【问题标题】:How can I improve image quality in the pdf?如何提高 pdf 中的图像质量?
【发布时间】:2016-06-08 22:37:23
【问题描述】:

正在开发一个 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 只是用户从 pod 的 CollectionView 中选择图像后生成的 PHAsset 照片数组...

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

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

【问题讨论】:

    标签: swift image pdf


    【解决方案1】:

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

    代替:

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

    我只是将图像的大小翻了一番,绘制到 pdf 的图像质量更好。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      • 2019-01-30
      • 2020-04-21
      • 1970-01-01
      相关资源
      最近更新 更多