Tôi đang làm việc trên iphone và tôi lấy phân lớp của UIView và trong phương pháp vẽ trực tiếp Tôi đang thực hiện một số thiết kế. Tôi muốn chuyển đổi chế độ xem này ở định dạng .png.chuyển đổi uiview thành hình ảnh .png
Xin cảm ơn trước.
Tôi đang làm việc trên iphone và tôi lấy phân lớp của UIView và trong phương pháp vẽ trực tiếp Tôi đang thực hiện một số thiết kế. Tôi muốn chuyển đổi chế độ xem này ở định dạng .png.chuyển đổi uiview thành hình ảnh .png
Xin cảm ơn trước.
UIGraphicsBeginImageContext(myView.frame.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data=UIImagePNGRepresentation(viewImage);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *strPath = [documentsDirectory stringByAppendingPathComponent:@"myimage.png"];
[data writeToFile:strPath atomically:YES];
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(YourView.frame.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(keyWindow.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[keyWindow.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
UIGraphicsEndImageContext();
u muốn nhận được ảnh chụp màn hình của UIView điều đó không ?? –
u muốn hình ảnh chuyển đổi thành định dạng .png hoặc ảnh chụp màn hình –