ios - Swift - 以 PDF 格式加载时质量不佳的图像 - 使用 TPPDF
问题描述
使用TPPDF library
时,当在 pdf 中加载高质量图像时,图像会变得模糊。
我尝试了所有可能的方法。
这是我的代码:
let coverImage = PDFImage(image: UIImage(named: "Banner")!, quality: 1, options: [.resize])
//To find proportional width and height
let imageWidth: CGFloat = coverImage.image.size.width
let imageHeight: CGFloat = coverImage.image.size.height
let targetHeight: CGFloat = imageHeight/imageWidth
print("PdfWidth", pdf.layout.width)
print("PdfHeight", pdf.layout.height)
print("TargetHeight", pdf.layout.width*targetHeight)
print("ImageWidth", coverImage.image.size.width)
print("ImageHeight", coverImage.image.size.height)
coverImage.size = CGSize(width: pdf.layout.width, height: pdf.layout.width*targetHeight)
print("size", coverImage.size)
pdf.addImage(.contentCenter, image: coverImage)
日志,我得到的是:
PdfWidth 595.0
PdfHeight 842.0
TargetHeight 44.5
ImageWidth 595.0
ImageHeight 44.5
size (595.0, 44.5)
我还尝试添加 8000x600 的高分辨率图像,但图像仍然模糊。
解决方案
推荐阅读
- php - 无法通过 txt 文件中的新行来分解字符串
- javascript - 使用双重逻辑而不是“!!”有什么意义?javascript中的运算符
- python - python - 如何在许多带有python的文本文件中删除以“1”开头的行
- pandas - 通过迭代比较另一列的前一个元素来增加分组的熊猫数据框
- javascript - 仅在 React.Js 中更改主页滚动标题组件的样式
- google-apps-script - 为 Google Apps 脚本 Web 应用程序驱动 API 推送通知
- c# - 如何通过 google-news-api 获取数据
- html - 为什么 froala 从我的 html 中删除表单标签?
- mongodb - 如何针对特定场景设计 Azure Cosmos DB 结构以限制创建的集合数量?
- python - 将单个 Json 文件数据保存到同一 SQL DB 中的 2 个不同表中