【问题标题】:How to compress an Image taken by the camera in iphone sdk?如何在iphone sdk中压缩相机拍摄的图像?
【发布时间】:2010-10-08 10:33:17
【问题描述】:

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

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];   
    }
}

尽管加载需要时间。

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

谢谢大家, 莫尼什。

【问题讨论】:

    标签: objective-c


    【解决方案1】:

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

    -(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)];
    

    【讨论】:

      猜你喜欢
      • 2018-01-03
      • 1970-01-01
      • 2017-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-10
      • 1970-01-01
      相关资源
      最近更新 更多