難道你只是在所需的大小創建一個新的圖形上下文,使用CGAffineTransform縮小它,呈現根UIView的根層,恢復上下文到原始大小和渲染圖像?有沒有試過這種視網膜內容,但這似乎也爲已在UIImageViews的被縮小大圖像工作...
類似:
CGSize originalSize = myOriginalImage.size; //or whatever
//create context
UIGraphicsBeginImageContext(originalSize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context); //1 original context
// translate/flip the graphics context (for transforming from CG* coords to UI* coords
CGContextTranslateCTM(context, 0, originalSize.height);
CGContextScaleCTM(context, 1.0, -1.0);
//original image
CGContextDrawImage(context, CGRectMake(0,0,originalSize.width,originalSize.height), myOriginalImage.CGImage);
CGContextRestoreGState(context);//1 restore to original for UIView render;
//scaling
CGFloat wratio = originalSize.width/self.view.frame.size.width;
CGFloat hratio = originalSize.height/self.view.frame.size.height;
//scale context to match view size
CGContextSaveGState(context); //1 pre-scaled size
CGContextScaleCTM(context, wratio, hratio);
//render
[self.view.layer renderInContext:context];
CGContextRestoreGState(context);//1 restore to pre-scaled size;
UIImage *exportImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
檢查是否可以使用'UIGraphicsBeginImageContextWithOptions'有什麼意義?它是否向後兼容? – pixelfreak 2012-01-11 19:27:08
該解決方案還需要QuartzCore框架,用於renderInContext方法。 – arlomedia 2012-04-16 19:51:19
@pixelfreak這是因爲UIGraphicsBeginImageContextWithOptions僅適用於iOS 4 +。 – shannoga 2012-07-02 19:37:27