Commit 2f00ea56 authored by Tobias's avatar Tobias

Use screen scale as image scale for thumbnailing

preferred thumbnail size is in points @1x not in pixels
parent 7d10a819
......@@ -107,8 +107,9 @@
MLThumbnailerQueue *thumbnailerQueue = [MLThumbnailerQueue sharedThumbnailerQueue];
CGSize thumbSize = [UIImage preferredThumbnailSizeForDevice];
thumbnailer.thumbnailWidth = thumbSize.width;
thumbnailer.thumbnailHeight = thumbSize.height;
CGFloat scale = [UIScreen mainScreen].scale;
thumbnailer.thumbnailWidth = thumbSize.width*scale;
thumbnailer.thumbnailHeight = thumbSize.height*scale;
[thumbnailer fetchThumbnail];
[thumbnailerQueue.queue setSuspended:YES]; // Balanced in -mediaThumbnailer:didFinishThumbnail
// Balanced in -mediaThumbnailer:didFinishThumbnail:
......@@ -131,7 +132,7 @@
MLFile *file = self.file;
APLog(@"Finished thumbnail for %@", file.title);
if (thumbnail) {
UIImage *thumbnailImage = [UIImage imageWithCGImage:thumbnail];
UIImage *thumbnailImage = [UIImage imageWithCGImage:thumbnail scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];
if (thumbnailImage) {
file.computedThumbnail = [UIImage imageWithCGImage:thumbnail];
#if TARGET_OS_IOS
......
......@@ -11,6 +11,9 @@
@interface UIImage (MLKit)
+ (CGSize)preferredThumbnailSizeForDevice;
// uses current screen scale as scale
+ (UIImage *)scaleImage:(UIImage *)image toFitRect:(CGRect)rect;
+ (UIImage *)scaleImage:(UIImage *)image toFitRect:(CGRect)rect scale:(CGFloat) scale;
@end
......@@ -16,36 +16,20 @@
CGFloat thumbnailWidth, thumbnailHeight;
/* optimize thumbnails for the device */
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if ([UIScreen mainScreen].scale==2.0) {
thumbnailWidth = 540.;
thumbnailHeight = 405.;
} else {
thumbnailWidth = 272.;
thumbnailHeight = 204.;
}
thumbnailWidth = 272.;
thumbnailHeight = 204.;
} else {
if (SYSTEM_RUNS_IOS7) {
if ([UIScreen mainScreen].scale==2.0) {
thumbnailWidth = 480.;
thumbnailHeight = 270.;
} else {
thumbnailWidth = 720.;
thumbnailHeight = 405.;
}
} else {
if ([UIScreen mainScreen].scale==2.0) {
thumbnailWidth = 480.;
thumbnailHeight = 270.;
} else {
thumbnailWidth = 240.;
thumbnailHeight = 135.;
}
}
thumbnailWidth = 240.;
thumbnailHeight = 135.;
}
return CGSizeMake(thumbnailWidth, thumbnailHeight);
}
+ (UIImage *)scaleImage:(UIImage *)image toFitRect:(CGRect)rect
+ (UIImage *)scaleImage:(UIImage *)image toFitRect:(CGRect)rect {
return [self scaleImage:image toFitRect:rect scale:[UIScreen mainScreen].scale];
}
+ (UIImage *)scaleImage:(UIImage *)image toFitRect:(CGRect)rect scale:(CGFloat)scale
{
CGRect destinationRect = AVMakeRectWithAspectRatioInsideRect(image.size, rect);
......@@ -56,8 +40,8 @@
CGBitmapInfo bitmapInfoRef = CGImageGetBitmapInfo(cgImage);
CGContextRef contextRef = CGBitmapContextCreate(NULL,
destinationRect.size.width,
destinationRect.size.height,
destinationRect.size.width*scale,
destinationRect.size.height*scale,
bitsPerComponent,
bytesPerRow,
colorSpaceRef,
......@@ -67,7 +51,7 @@
CGContextDrawImage(contextRef, (CGRect){CGPointZero, destinationRect.size}, cgImage);
CGImageRef imageRef = CGBitmapContextCreateImage(contextRef);
UIImage *scaledImage = [UIImage imageWithCGImage:imageRef];
UIImage *scaledImage = [UIImage imageWithCGImage:imageRef scale:scale orientation:UIImageOrientationUp];
CGImageRelease(imageRef);
CGContextRelease(contextRef);
return scaledImage;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment