Skip to content

Commit

Permalink
Update the NSImage code to just use an NSBitmapImageRep for determini…
Browse files Browse the repository at this point in the history
…ng the correct pixel width and height

Thanks to @indragiek for the tip.
  • Loading branch information
kgn committed Nov 18, 2011
1 parent fbf9186 commit bfb6b35
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions AFNetworking/AFImageRequestOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,11 @@ - (void)setImageScale:(CGFloat)imageScale {
#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;
Expand Down

0 comments on commit bfb6b35

Please sign in to comment.