[英]How to save image larger than device resolution in iPhone?
不要使用CGBitmapContextCreate,而要使用UIGraphicsBeginImageContextWithOptions,這要容易得多。 像這樣使用它:
UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), YES, 1.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
//do your drawing
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEdnImageContext();
//your resultant UIImage is now stored in image variable
UIGraphicsBeginImageContext的三個參數是:
圖片的大小-這可以是您想要的任何內容
圖像是否透明
圖像中像素的比例。 0.0是默認值,因此在iPhone 3GS上為1.0,在具有視網膜顯示屏的iPhone 4上為2.0。 不過,您可以按任意比例傳遞,因此,如果傳遞5.0,則圖像中的每個像素單位實際上將是位圖中的5x5像素,就像Retina顯示屏上的1像素實際上是屏幕上的2x2像素一樣。
編輯:事實證明,UIGraphicsBeginImageContext()是否是線程安全的問題似乎有點爭議。 如果確實需要在后台線程上同時執行此操作,則可以在此處使用CGBitMapContextCreate()作為替代方法(更復雜的方法): UIGraphicsBeginImageContext與CGBitmapContextCreate
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.