iPhone : How to save a view as image ??? (ex.save what you draw )

前端 未结 3 1696
暗喜
暗喜 2020-12-23 23:33

I found some sample is teach you how to draw on iphone

but it does not say how to save a view as image ?

Does anyone got idea ???

Or any sample will

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-24 00:15

    In MonoTouch/C# as an extension method:

    public static UIImage ToImage(this UIView view) {
        try {
            UIGraphics.BeginImageContext(view.ViewForBaselineLayout.Bounds.Size);
            view.Layer.RenderInContext(UIGraphics.GetCurrentContext());
            return UIGraphics.GetImageFromCurrentImageContext();
        } finally {
            UIGraphics.EndImageContext();
        }
    }
    

提交回复
热议问题