เช่นเดียวกับที่คุณเห็นในโค้ดของฉัน ฉันจะจับภาพหน้าจอและบันทึกลงในอัลบั้มรูป
//for retina displays
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
UIGraphicsBeginImageContext(self.view.bounds.size);
}
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
ในตอนแรกฉันใช้ webview.size
แทน self.view.bounds.size
และมันทำงานได้อย่างถูกต้องเนื่องจากมุมมองอยู่ที่ 0/0
แต่ตอนนี้ฉันจัด WebView ไว้ตรงกลาง แต่รูปภาพเริ่มต้นที่ 0/0
สำหรับขนาดที่กำหนด
ฉันจะกำหนดค่าให้ภาพหน้าจอเริ่มต้นที่ location
อื่น (เช่น 300/150
) สำหรับขนาดที่กำหนดได้อย่างไร
หรือมีวิธีอื่นในการถ่ายภาพ UIWebView
?