如何在pdf中提高图像质量?

时间:2016-06-08 22:37:23

标签: swift image pdf

使用pdf照片报告应用程序,并在生成的pdf中处理低图像质量。

func drawImage(index: Int, rectPos: Int) {
    let image = getImage(index)
    let xPosition = CGFloat(rectArray[rectPos][0])
    let yPosition = CGFloat(rectArray[rectPos][1])
    image.drawInRectAspectFill(CGRectMake(xPosition, yPosition, 325, 244))
}

func getImage(index: Int) -> UIImage {
    var thumbnail = UIImage()
    if self.photoAsset.count != 0 {
        let initialRequestOptions = PHImageRequestOptions()
        initialRequestOptions.resizeMode = .Exact
        initialRequestOptions.deliveryMode = .HighQualityFormat
        initialRequestOptions.synchronous = true
        PHImageManager.defaultManager().requestImageForAsset(self.photoAsset[index], targetSize: CGSizeMake(325, 244), contentMode: PHImageContentMode.Default, options: initialRequestOptions, resultHandler: { (result, info) -> Void in
            thumbnail = result!
        })
    }
    return thumbnail
}

然后我使用这些函数抓取图像,并在UIGraphicsBeginPDFPageWithInfo(page,nil)之后将其放置在页面上的某个位置......

我使用BSImagePicker pod来获取图片。

最后,我的photoAsset只是一组PHAsset照片,是在用户从pod的CollectionView中选择图像后生成的......

到目前为止,我尝试了initialRequestOptions.deliveryMode的所有设置......高质量似乎并没有让图像更好。

我在这里做错了什么?谢谢!

1 个答案:

答案 0 :(得分:0)

请求图像时更改目标分辨率可设置您要使用的图像的最小分辨率。

而不是:

PHImageManager.defaultManager().requestImageForAsset(self.photoAsset[index], targetSize: CGSizeMake(325, 244)...

我简单地将图像的大小加倍,并且绘制到pdf的图像质量更好。

PHImageManager.defaultManager().requestImageForAsset(self.photoAsset[index], targetSize: CGSizeMake(650, 488)...