我有一個滾動視圖,框架大小爲480x265,內容大小爲1800x600。如何將UIScrollView轉換爲圖像?
我有很多UIView作爲子視圖添加到此滾動視圖。
我可以知道我應該如何將此滾動視圖轉換爲圖像?
非常感謝任何意見/幫助提前!
我有一個滾動視圖,框架大小爲480x265,內容大小爲1800x600。如何將UIScrollView轉換爲圖像?
我有很多UIView作爲子視圖添加到此滾動視圖。
我可以知道我應該如何將此滾動視圖轉換爲圖像?
非常感謝任何意見/幫助提前!
- (void)submitClicked
{
UIGraphicsBeginImageContext(scrollView.contentSize);
CGPoint savedContentOffset = scrollView.contentOffset;
CGRect savedFrame = scrollView.frame;
scrollView.contentOffset = CGPointZero;
scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
[scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
scrollView.contentOffset = savedContentOffset;
scrollView.frame = savedFrame;
UIGraphicsEndImageContext();
}
這對你很好,因爲我也會遇到這個問題TAUHEED AHMD – 2011-06-10 07:05:48
好像要將滾動視圖的內容保存爲圖像。
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
[data writeToFile:@"myImage.png" atomically:YES];
這將只捕獲scrollview的可見部分,它會剪切剩下的內容不可見 – iwasrobbed 2013-05-30 03:11:36
這是http://stackoverflow.com/questions/3539717/getting-a-screenshot的副本-of-a-uiscrollview-including-offscreen-parts – Rambatino 2015-05-19 15:20:48