Skip to content

Commit

Permalink
[Issue #1181] Using UIImage calculated image orientation
Browse files Browse the repository at this point in the history
Minor refactoring
  • Loading branch information
mattt committed Aug 11, 2013
1 parent 9174f5f commit 748260a
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions AFNetworking/AFImageRequestOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ static dispatch_queue_t image_request_operation_processing_queue() {
return nil;
}

UIImage *image = AFImageWithDataAtScale(data, scale);
if (image.images) {
return image;
}

CGImageRef imageRef = nil;
CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);

Expand All @@ -59,22 +64,15 @@ static dispatch_queue_t image_request_operation_processing_queue() {
}

if (!imageRef) {
UIImage *image = AFImageWithDataAtScale(data, scale);
if (image.images) {
CGDataProviderRelease(dataProvider);

imageRef = CGImageCreateCopy([image CGImage]);

if (!imageRef) {
return image;
}

imageRef = CGImageCreateCopy([image CGImage]);
}

CGDataProviderRelease(dataProvider);

if (!imageRef) {
return nil;
}

size_t width = CGImageGetWidth(imageRef);
size_t height = CGImageGetHeight(imageRef);
size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
Expand All @@ -100,15 +98,15 @@ static dispatch_queue_t image_request_operation_processing_queue() {
if (!context) {
CGImageRelease(imageRef);

return [[UIImage alloc] initWithData:data];
return image;
}

CGRect rect = CGRectMake(0.0f, 0.0f, width, height);
CGContextDrawImage(context, rect, imageRef);
CGImageRef inflatedImageRef = CGBitmapContextCreateImage(context);
CGContextRelease(context);

UIImage *inflatedImage = [[UIImage alloc] initWithCGImage:inflatedImageRef scale:scale orientation:UIImageOrientationUp];
UIImage *inflatedImage = [[UIImage alloc] initWithCGImage:inflatedImageRef scale:scale orientation:image.imageOrientation];
CGImageRelease(inflatedImageRef);
CGImageRelease(imageRef);

Expand Down

0 comments on commit 748260a

Please sign in to comment.