2

我对处理图像有点陌生,有很多我不知道的事情,所以请多多包涵。基本上我是用相机拍照,然后把它呈现在里面UIImageView,这是 60:80 的小视图。图像会自动调整大小以适应UIImageView,一切看起来都很好。

我的问题是 - 我需要做更多的图像操作(为了最大限度地提高效率),还是仅此而已?

4

3 回答 3

6

请使用以下代码,这将为您提供更好的缩略图

  -(UIImage *)generatePhotoThumbnail:(UIImage *)image 
  {
    CGSize size = image.size;
    CGSize croppedSize;
    CGFloat ratio = 120.0;
    CGFloat offsetX = 0.0;
    CGFloat offsetY = 0.0;

     if (size.width > size.height) {
        offsetX = (size.height - size.width) / 2;
        croppedSize = CGSizeMake(size.height, size.height);
     } else 
         {
        offsetY = (size.width - size.height) / 2;
        croppedSize = CGSizeMake(size.width, size.width);
     }

     CGRect clippedRect = CGRectMake(offsetX * -1, offsetY * -1, croppedSize.width, croppedSize.height);
     CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], clippedRect);

     CGRect rect = CGRectMake(0.0, 0.0, ratio, ratio);

     UIGraphicsBeginImageContext(rect.size);
     [[UIImage imageWithCGImage:imageRef] drawInRect:rect];
     UIImage *thumbnail = UIGraphicsGetImageFromCurrentImageContext();
     UIGraphicsEndImageContext();
         CGImageRelease(imageRef);

     return thumbnail;
   }
于 2012-10-30T11:17:51.950 回答
2

Resize image function将会:

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

Savedocument directory用调整大小的图像unique names。后来access thumbnail imagedocument directory

如果图像计数more比使用lazy loading图像显示图像。

于 2012-10-30T10:59:25.263 回答
0

If you are happy with the way the picture is displayed, then you don't need any additional code. Image views have no problems rescaling images for you and they are quite efficient at that, so don't worry about it.

于 2012-10-30T11:24:50.850 回答