如何在iPhone中保存大于设备分辨率的图像?
My question is related to this link
I would like to know how we can save images larger than device resolution using CGBitmapContextCreate
.
Any sample code for guidance will be much appreciated.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用CGBitmapContextCreate,使用UIGraphicsBeginImageContextWithOptions,它更容易。像这样使用它:
UIGraphicsBeginImageContext 的三个参数是:
图像的大小 - 这可以是你想要的任何内容
图像是否有透明度与否
图像中像素的比例。 0.0 是默认值,因此在 iPhone 3GS 上它将为 1.0,在配备视网膜显示屏的 iPhone 4 上它将为 2.0。不过,您可以传入任何您想要的比例,因此如果您传入 5.0,则图像中的每个像素单位实际上是位图中的 5x5 像素,就像 Retina 显示屏上的 1 像素实际上是屏幕上的 2x2 像素一样。
编辑:事实证明 UIGraphicsBeginImageContext() 是否线程安全的问题似乎有点争议。如果您确实需要在后台线程上同时执行此操作,则可以使用 CGBitMapContextCreate() 进行替代(相当复杂的方法):UIGraphicsBeginImageContext 与 CGBitmapContextCreate
Don't use CGBitmapContextCreate, use UIGraphicsBeginImageContextWithOptions, it's much easier. Use it like this:
The three parameters to UIGraphicsBeginImageContext are:
The size of the image - this can be anything you want
Whether the image has transparency or not
The scale of pixels in the image. 0.0 is the default, so on an iPhone 3GS it will be 1.0 and on an iPhone 4 with a retina display it will be 2.0. You can pass in any scale you want though, so if you pass in 5.0, each pixel unit in your image will actually be 5x5 pixels in the bitmap, just like 1 pixel on a Retina display is really 2x2 pixels on screen.
Edit: it turns out that the question of whether UIGraphicsBeginImageContext() is thread-safe seems to be a bit controversial. If you do need to do this concurrently on a background thread, there is an alternative (rather more complex approach) using CGBitMapContextCreate() here: UIGraphicsBeginImageContext vs CGBitmapContextCreate