From fbf9186d10b3aebb3fd95769c8542dface6e9029 Mon Sep 17 00:00:00 2001 From: David Keegan Date: Thu, 17 Nov 2011 23:07:40 -0800 Subject: [PATCH 1/2] Adding code to set the responceImage to the correct size. --- AFNetworking/AFImageRequestOperation.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/AFNetworking/AFImageRequestOperation.m b/AFNetworking/AFImageRequestOperation.m index e0d0ce5..1742706 100644 --- a/AFNetworking/AFImageRequestOperation.m +++ b/AFNetworking/AFImageRequestOperation.m @@ -213,6 +213,12 @@ static dispatch_queue_t image_request_operation_processing_queue() { - (NSImage *)responseImage { if (!_responseImage && [self isFinished]) { self.responseImage = [[[NSImage alloc] initWithData:self.responseData] autorelease]; + + // The size of an NSImage can sometimes be incorrect, so make a CGImage which is more + // like a single pixel-based representation so it is the correct size, and then + // set the size based on what the CGImage says it is. + CGImageRef cgimage = [[NSBitmapImageRep imageRepWithData:self.responseData] CGImage]; + [self.responseImage setSize:NSMakeSize(CGImageGetWidth(cgimage), CGImageGetHeight(cgimage))]; } return _responseImage; From bfb6b35a3e867225b06a965ac5f99657d4711a4c Mon Sep 17 00:00:00 2001 From: David Keegan Date: Fri, 18 Nov 2011 09:59:29 -0800 Subject: [PATCH 2/2] Update the NSImage code to just use an NSBitmapImageRep for determining the correct pixel width and height Thanks to @indragiek for the tip. --- AFNetworking/AFImageRequestOperation.m | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/AFNetworking/AFImageRequestOperation.m b/AFNetworking/AFImageRequestOperation.m index 1742706..03b456e 100644 --- a/AFNetworking/AFImageRequestOperation.m +++ b/AFNetworking/AFImageRequestOperation.m @@ -212,13 +212,11 @@ static dispatch_queue_t image_request_operation_processing_queue() { #elif __MAC_OS_X_VERSION_MIN_REQUIRED - (NSImage *)responseImage { if (!_responseImage && [self isFinished]) { - self.responseImage = [[[NSImage alloc] initWithData:self.responseData] autorelease]; - - // The size of an NSImage can sometimes be incorrect, so make a CGImage which is more - // like a single pixel-based representation so it is the correct size, and then - // set the size based on what the CGImage says it is. - CGImageRef cgimage = [[NSBitmapImageRep imageRepWithData:self.responseData] CGImage]; - [self.responseImage setSize:NSMakeSize(CGImageGetWidth(cgimage), CGImageGetHeight(cgimage))]; + // Ensure that the image is set to it's correct pixel width and height + NSBitmapImageRep *bitimage = [[NSBitmapImageRep alloc] initWithData:self.responseData]; + self.responseImage = [[[NSImage alloc] initWithSize:NSMakeSize([bitimage pixelsWide], [bitimage pixelsHigh])] autorelease]; + [self.responseImage addRepresentation:bitimage]; + [bitimage release]; } return _responseImage;