如何压缩iPhone SDK中相机拍摄的图像? [英] How to compress an Image taken by the camera in iphone sdk?

查看:107
本文介绍了如何压缩iPhone SDK中相机拍摄的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从通讯录中获取联系人列表,因为某些联系人的图像是用相机拍摄的,它们的尺寸非常大.我将联系人及其图像以3x3的行和列格式显示.问题是由于图像的大小太大,需要花费一些时间来加载图像.谁能建议我如何压缩它们. 我尝试以某种方式压缩它们:

I am getting the list of contacts from the Address book in that some contacts have images which are taken with camera they are very huge in size.I am displaying the contacts along with their images in a 3x3 rows and columns format.The problem is due to huge size of the images its taking time to load the images.Can anyone suggest me how to Compress them. I tried to compress them in a way:

if ([imageData length] > 0)
{
    int len = [imageData length];
    if(len > 9000)
    {
        UIImage *theImage =  [UIImage imageWithData:imageData];
        imageData = UIImageJPEGRepresentation(theImage,0.5);
        printf("\n image data length in condition...%d",[imageData length]);
        imageViewL.image = [UIImage imageWithData:imageData];
    }
    else
    {
        imageViewL.image = [UIImage imageWithData:imageData];   
    }
}

尽管需要花费一些时间来加载.

Eventhough its taking time to load.

任何人的帮助将不胜感激.

Anyone's help will be much appreciated.

感谢所有人, 结束.

推荐答案

您可以使用以下代码行调整iphone相机拍摄的图像的大小

You can resize the image captured by the iphone camera by using the following lines of code

-(UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)newSize
{  
    UIGraphicsBeginImageContext(newSize);  
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];  
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();    
    return newImage;  
}

然后像这样调用此方法

UIImage *image = [self scaleImage:your image toSize:CGSizeMake(320.0,480.0)];

这篇关于如何压缩iPhone SDK中相机拍摄的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆