如何将由 CGContextRef 表示的位图图像保存到 iPhone 的硬盘上?
我有一个小草图程序,我已经使用 Quartz2D 设法将其组合在一起,但我对 iOS 平台非常陌生,并且无法弄清楚如何允许用户保存他们的草图。我有一个包含草图的 CGContextRef,如何保存它以便以后可以检索它?保存后如何找回?
预先非常感谢您的帮助!我现在要继续阅读……
I have a little sketch program that I've managed to throw together using Quartz2D, but I'm very new to the iOS platform and I'm having trouble figuring out how to allow the user to save their sketch. I have a CGContextRef that contains the sketch, how can I save it so that it can later be retrieved? Once it's saved, how can I retrieve it?
Thanks so much in advance for your help! I'm going to continue reading up on this now...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CGContext 有不同类型。您很可能拥有基于屏幕的上下文,但您需要 bitmapContext 或 pdfContext 来创建位图或 pdf 文件。
请参阅 UIKit 函数参考。应该感兴趣的函数是:
UIGraphicsBeginImageContext()
UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageJPEGRepresentation()
UIImageWriteToSavedPhotosAlbum()
UIGraphicsBeginPDFContextToFile()
UIGraphicsEndPDFContext()
There are different types of CGContexts. You are most likely having a screen based context, but you would need either a bitmapContext or a pdfContext, to create a bitmap or a pdf file.
See the UIKit Functions Reference. Functions that should be of interest are:
UIGraphicsBeginImageContext()
UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageJPEGRepresentation()
UIImageWriteToSavedPhotosAlbum()
UIGraphicsBeginPDFContextToFile()
UIGraphicsEndPDFContext()
这是我的做法...
保存
检索
Here's how I did it...
Saving
Retrieving