繁体   English   中英

将jpg UIImage转换为位图UIImage?

[英]convert jpg UIImage to bitmap UIImage?

我试图让用户平移/缩放在主图像上带有选择矩形的静态图像,并为“放大”图像提供单独的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);

在这方面的表现是残酷的。 它将其92%的时间花费在[UIImage drawInRect]中。

更深一点,在ripc_AcquireImage中为84.5%,在ripc_RenderImage中为7.5%。

ripc_AcquireImage是51%的JPG,30%上采样进行解码。

所以...我想我的问题是避免这种情况的最佳方法是什么? 一种选择是不接受jpg开始,这是对某些事情的真正解决方案[ 无JPG中介的 ala captureStillImageAsynchronouslyFromConnection ]。 但是,如果我要从相机胶卷上取下UIImage,请说...是否有一种干净的方法来转换UIImage-jpg? 正在转换它甚至是正确的事情(本质上是否有“ cacheAsBitmap”标志可以做到这一点?)

显然,这不仅仅是一个JPG问题,我认为这还没有“理想的本地表示”的支持。

我在以下方面取得了成功(显着的性能改进):

UIGraphicsBeginImageContext(image.size);
[image drawAtPoint:CGPointZero];
image = [UIGraphicsGetImageFromCurrentImageContext() retain];
UIGraphicsEndImageContext();

对于从相机胶卷和相机中取出的东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM