iPhone:如何将视图保存为图像??? (ex.save你画的是什么) [英] iPhone : How to save a view as image ??? (ex.save what you draw )
本文介绍了iPhone:如何将视图保存为图像??? (ex.save你画的是什么)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现一些样本教会你如何在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 ?
有没有人有想法???
Does anyone got idea ???
或任何样品都会有所帮助:)
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:如何将视图保存为图像??? (ex.save你画的是什么)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文