我想讓用戶通過主圖像上的選擇矩形和單獨的UIView「放大」圖像來平移/縮放靜態圖像。將jpg UIImage轉換爲位圖UIImage?
的 「放大」 的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,這對於某些事情是真正的解決方案[ala captureStillImageAsynchronouslyFromConnection without JPG intermediary]。但是,如果我從相機膠捲上取下UIImage,請說...有沒有一種乾淨的方式來轉換UIImage-jpg?轉換它甚至是正確的事情(是否有一個「cacheAsBitmap」標誌某處會做到這一點,本質上?)
所有UIImage都是位圖。這是他們可以使用的唯一內部格式。 – borrrden 2012-07-26 01:32:50
什麼是UIImage的設置,其源是一個JPG重新解碼每個drawInRect,然後?我的意思是,你的陳述對我來說絕對有意義,這是我的假設,直到分析這個問題...然後切換靜止圖像捕獲使用原始RGBA而不是JPEG使特定的放緩消失... – 2012-07-26 04:26:28
你變得「形象」? – borrrden 2012-07-26 04:31:23