【发布时间】:2012-07-26 01:23:25
【问题描述】:
我试图让用户平移/缩放静态图像,主图像上有一个选择矩形,“放大”图像有一个单独的 UIView。
“放大”的 UIView 实现 drawRect:
// rotate selectionRect if image isn't portrait internally
CGRect tmpRect = selectionRect;
if ((image.imageOrientation == UIImageOrientationLeft || image.imageOrientation == UIImageOrientationLeftMirrored || image.imageOrientation == UIImageOrientationRight || image.imageOrientation == UIImageOrientationRightMirrored)) {
tmpRect = CGRectMake(selectionRect.origin.y,image.size.width - selectionRect.origin.x - selectionRect.size.width,selectionRect.size.height,selectionRect.size.width);
}
// crop and draw
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], tmpRect);
[[UIImage imageWithCGImage:imageRef scale:image.scale orientation:image.imageOrientation] drawInRect:rect];
CGImageRelease(imageRef);
这方面的表现很糟糕。它在 [UIImage drawInRect] 中花费了 92% 的时间。
更深一点,在 ripc_AcquireImage 中为 84.5%,在 ripc_RenderImage 中为 7.5%。
ripc_AcquireImage 是 51% 的 jpg 解码,30% 的上采样。
所以...我想我的问题是避免这种情况的最佳方法是什么?一种选择是不以 jpg 开头,这对于某些事情来说是一个真正的解决方案 [ala captureStillImageAsynchronouslyFromConnection without JPG intermediary ]。但是,如果我从相机胶卷上得到一个 UIImage,比如说......有没有一种干净的方法来转换 UIImage-jpg?转换它甚至是正确的事情(本质上是否有一个“cacheAsBitmap”标志可以做到这一点?)
【问题讨论】:
-
所有 UIImage 都是位图。这是他们唯一可以使用的内部格式。
-
什么是设置源为jpg的UIImage重新解码每个drawInRect,然后呢?我的意思是,你的说法对我来说绝对有意义,在分析这个问题之前,这是我的假设……然后将静态图像捕获切换为使用原始 RGBA 而不是 JPEG 会使这种特定的减速消失……
-
我一直在使用视频中的
jpegStillImageNSDataRepresentation,并通过获取原始数据解决了这个问题;但仍然遇到相机胶卷中 jpg 的问题(imagePickerController: didFinishPickingMediaWithInfo:,UIImage image* = [info objectForKey:UIImagePickerControllerOriginalImage]]