通常在開發(fā)中view轉(zhuǎn)UIIimage的方法為:
+(UIImage *)imageWithUIView:(UIView *)view{
? ? UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
? ? CGContextRef ctx = UIGraphicsGetCurrentContext();
? ? [view.layer renderInContext:ctx];
? ? UIImage* tImage = UIGraphicsGetImageFromCurrentImageContext();
? ? UIGraphicsEndImageContext();
? ? returntImage;
}
但是生成后的圖片清晰度直線下降,尤其是在圖片上有文字的情況下态鳖,糊的更為明顯。
變糊是因?yàn)閕OS的編程像素和實(shí)際顯示像素不同唾糯,在X2和X3的retina屏幕設(shè)備上,使用此方法生成的圖片大小將會被還原成1倍像素涡上,?
從而導(dǎo)致再次顯示到UIImageView上顯示時(shí)趾断,清晰度下降。所以使用此方法前吩愧,先將要轉(zhuǎn)換的UIview及它的所有SubView 的frame里的坐標(biāo)和大小都根據(jù)需要X2或X3芋酌。