iPhone:如何将视图另存为图像???(例如保存你画的东西) [英] iPhone : How to save a view as image ??? (ex.save what you draw )

查看:24
本文介绍了iPhone:如何将视图另存为图像???(例如保存你画的东西)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些例子是教你如何在 iphone 上画画

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

但它没有说明如何将视图另存为图像?

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

有人知道吗???

或者任何示例都会有所帮助:)

Or any sample will be helpful : )

实际上,我正在尝试将用户的签名保存为图像并将其上传到服务器.

actually,I'm trying to save user's signature as a image and upload it to server.

谢谢

韦伯

推荐答案

UIView *view = // your view    
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

这给出了您可以使用的图像 –

This gives the image which you can store using –

NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
[imageData writeToFile:path atomically:YES];

其中 path 是您要保存到的位置.

where path is location you want to save to.

这篇关于iPhone:如何将视图另存为图像???(例如保存你画的东西)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆