2011-10-21 35 views
-3

我对我在iPhone应用程序中使用的png图像有疑问。对于不同的视图,我有很多大图像,但它们是压缩的,但我想知道是否会降低应用程序的速度。像在初始加载时间和加载不同视图基本上我需要知道如何通过调整图像来缩小应用程序的尺寸和速度?或者,如果它甚至值得与之混淆?在iPhone应用程序中的大PNG图像Dev

我已经完成了关于这个主题的研究,但除了压缩图像之外我还没有找到任何可行的解决方案。

任何帮助非常感谢?

+0

建议:在分辨率方面千万不要使用较大的图像,而不是在大小方面。如果图像的分辨率高于iphone屏幕,尽管它被界面构建器压缩,它将在应用程序中产生大量混乱。 –

+0

@AnilKumarReddy感谢您的建议! – PetersCodeProblems

回答

1

当你使用你的应用程序时,你注意到加载速度慢吗?如果不是,那么不要打扰图像,收益将是最小的,如果有的话。

如果您在加载应用程序时遇到问题,请不要假设它是PNG。使用提供的工具和配置您的应用程序,以找出缓慢的部分是什么,并从那里开始。永远不要以为你知道慢代码的起因。

+0

这个我知道。我只是想知道什么样的解决方案可以用于大型图像。 – PetersCodeProblems

+0

感谢您回答我的问题。 – PetersCodeProblems

2

希望,这有助于!

http://www.iphonedevsdk.com/forum/iphone-sdk-development/7307-resizing-photo-new-uiimage.html

 -(UIImage *)resizeImage:(UIImage *)image { 

CGImageRef imageRef = [image CGImage]; 
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef); 
CGColorSpaceRef colorSpaceInfo = CGColorSpaceCreateDeviceRGB(); 

if (alphaInfo == kCGImageAlphaNone) 
    alphaInfo = kCGImageAlphaNoneSkipLast; 

int width, height; 

width = 640; 
height = 480; 

CGContextRef bitmap; 

if (image.imageOrientation == UIImageOrientationUp | image.imageOrientation == UIImageOrientationDown) { 
    bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo); 

} else { 
    bitmap = CGBitmapContextCreate(NULL, height, width, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo); 

} 

if (image.imageOrientation == UIImageOrientationLeft) { 
    NSLog(@"image orientation left"); 
    CGContextRotateCTM (bitmap, radians(90)); 
    CGContextTranslateCTM (bitmap, 0, -height); 

} else if (image.imageOrientation == UIImageOrientationRight) { 
    NSLog(@"image orientation right"); 
    CGContextRotateCTM (bitmap, radians(-90)); 
    CGContextTranslateCTM (bitmap, -width, 0); 

} else if (image.imageOrientation == UIImageOrientationUp) { 
    NSLog(@"image orientation up"); 

} else if (image.imageOrientation == UIImageOrientationDown) { 
    NSLog(@"image orientation down"); 
    CGContextTranslateCTM (bitmap, width,height); 
    CGContextRotateCTM (bitmap, radians(-180.)); 

} 

CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef); 
CGImageRef ref = CGBitmapContextCreateImage(bitmap); 
UIImage *result = [UIImage imageWithCGImage:ref]; 

CGContextRelease(bitmap); 
CGImageRelease(ref); 

return result; 

}

相关问题