0

UIView (およびそのサブビュー) の内容を UIImage に保存しようとしています。

私が使用しているコードは次のとおりです。

+(UIImage *)imageWithView:(UIView *)view {
    UIGraphicsBeginImageContextWithOptions([view bounds].size, YES, 0);
    [[view layer] renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

それはうまく機能します...初めて。ただし、ビューのサブビューを変更してこのメ​​ソッドを再度呼び出すと、毎回古い UIImage が取得されます。

UIGraphicsEndImageContext()実際にスタックからビットマップ画像をポップするのは私の理解です。

ビューのサブビューの現在の状態を考慮して、この imageWithView: メソッドを機能させるにはどうすればよいですか?

4

1 に答える 1

-2

これが役立つことを願っています:

UIGraphicsBeginImageContext(self.view.frame.size);
[testView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
于 2013-01-02T05:28:50.947 に答える