diff --git a/AFNetworking/AFImageRequestOperation.h b/AFNetworking/AFImageRequestOperation.h index d18b6be..45f85cf 100644 --- a/AFNetworking/AFImageRequestOperation.h +++ b/AFNetworking/AFImageRequestOperation.h @@ -53,14 +53,27 @@ @private #if __IPHONE_OS_VERSION_MIN_REQUIRED UIImage *_responseImage; + CGFloat _imageScale; #elif __MAC_OS_X_VERSION_MIN_REQUIRED NSImage *_responseImage; #endif } #if __IPHONE_OS_VERSION_MIN_REQUIRED +/** + An image constructed from the response data. If an error occurs during the request, `nil` will be returned, and the `error` property will be set to the error. + */ @property (readonly, nonatomic, retain) UIImage *responseImage; + +/** + The scale factor used when interpreting the image data to construct `responseImage`. Specifying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property. This is set to the value of `[[UIScreen mainScreen] scale]` by default, which automatically scales images for retina displays, for instance. + */ +@property (nonatomic, assign) CGFloat imageScale; #elif __MAC_OS_X_VERSION_MIN_REQUIRED + +/** + An image constructed from the response data. If an error occurs during the request, `nil` will be returned, and the `error` property will be set to the error. + */ @property (readonly, nonatomic, retain) NSImage *responseImage; #endif diff --git a/AFNetworking/AFImageRequestOperation.m b/AFNetworking/AFImageRequestOperation.m index 4fdb6e5..e0d0ce5 100644 --- a/AFNetworking/AFImageRequestOperation.m +++ b/AFNetworking/AFImageRequestOperation.m @@ -45,6 +45,9 @@ static dispatch_queue_t image_request_operation_processing_queue() { @implementation AFImageRequestOperation @synthesize responseImage = _responseImage; +#if __IPHONE_OS_VERSION_MIN_REQUIRED +@synthesize imageScale = _imageScale; +#endif #if __IPHONE_OS_VERSION_MIN_REQUIRED + (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest @@ -173,6 +176,10 @@ static dispatch_queue_t image_request_operation_processing_queue() { self.acceptableContentTypes = [[self class] defaultAcceptableContentTypes]; +#if __IPHONE_OS_VERSION_MIN_REQUIRED + self.imageScale = [[UIScreen mainScreen] scale]; +#endif + return self; } @@ -184,16 +191,24 @@ static dispatch_queue_t image_request_operation_processing_queue() { #if __IPHONE_OS_VERSION_MIN_REQUIRED - (UIImage *)responseImage { if (!_responseImage && [self isFinished]) { - if ([[UIScreen mainScreen] scale] == 2.0) { - CGImageRef imageRef = [[UIImage imageWithData:self.responseData] CGImage]; - self.responseImage = [UIImage imageWithCGImage:imageRef scale:2.0 orientation:UIImageOrientationUp]; - } else { - self.responseImage = [UIImage imageWithData:self.responseData]; - } + CGImageRef imageRef = [[UIImage imageWithData:self.responseData] CGImage]; + self.responseImage = [UIImage imageWithCGImage:imageRef scale:self.imageScale orientation:UIImageOrientationUp]; } return _responseImage; } + +- (void)setImageScale:(CGFloat)imageScale { + if (imageScale == _imageScale) { + return; + } + + [self willChangeValueForKey:@"imageScale"]; + _imageScale = imageScale; + [self didChangeValueForKey:@"imageScale"]; + + self.responseImage = nil; +} #elif __MAC_OS_X_VERSION_MIN_REQUIRED - (NSImage *)responseImage { if (!_responseImage && [self isFinished]) {