UIViewの外観を画像として取得する
MonoTouchのView再構築時間が結構かかりストレスなので,終了直前の画像を表示して置こうと考えました.Viewの画像取得は次のコードでできます._targetViewおよび_copyViewはそれぞれUIView,UIImageViewクラスです.
{
/*
* http://www.iphonedevsdk.com/forum/iphone-sdk-development/2592-how-copy-image-uiview-another-uiview.html
*
* UIGraphicsBeginImageContext(self.bounds.size);
* [self.layer renderInContext:UIGraphicsGetCurrentContext()];
* UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
* UIGraphicsEndImageContext();
* I'm loading in an image into an UIImageView
* "[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];".
* The UIImageView takes care of scaling and cropping the image. Then I get viewImage from that UIImageView.
* */
UIGraphics.BeginImageContext(_targetView.Bounds.Size);
_targetView.Layer.RenderInContext(UIGraphics.GetCurrentContext());
var img = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
_copyView.Image = img;
}