【发布时间】:2015-10-22 17:58:32
【问题描述】:
我有一个生成各种图像/绘图的 iOS 应用程序,然后我使用 UIImage 类将其保存到设备中。图像最终分辨率相当低 - 有没有办法强制更高的分辨率,甚至生成要从 iOS 应用程序保存的矢量?
编辑:这里是代码运行方式的一些细节
为了创建图像,我使用 UIBezierPath() 创建了多个片段 - CAShapeLayer()。我将它们作为子层添加到其中创建了图像的 UIView 中,简写如下:
for i in 0...segmentCounter-1
{
let path = UIBezierPath() // this is generated in a function with some funky logic for points, colors, etc - UIBezierPath() is a placeholder
let shapeLayer = CAShapeLayer()
shapeLayer.opacity = 0.8;
shapeLayer.path = path.CGPath
self.layer.addSublayer(layer)
}
运行几次后,创建了一个包含多个图层的图像,我使用以下代码保存图像:
UIGraphicsBeginImageContextWithOptions(self.drawingView.layer.bounds.size, false, 0)
self.drawingView.drawViewHierarchyInRect(self.drawingView.layer.bounds, afterScreenUpdates: true)
let img:UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIImageWriteToSavedPhotosAlbum(img, self, "image:didFinishSavingWithError:contextInfo:", nil)
【问题讨论】:
-
能否请您发布一些示例代码?如果您创建自己的 CGContext,您应该能够以点和比例指定尺寸。
-
我在上面的编辑部分发布了一些代码 - 我没有明确使用 CGContext (我不认为,我对此还是很陌生) - 从我上面的代码中,你会建议我改变?
标签: ios image-processing uiimage