【问题标题】:Retrieving images into HTML with Swift使用 Swift 将图像检索为 HTML
【发布时间】:2021-05-26 02:48:06
【问题描述】:

我真的很难将快速保存的图像转换为 HTML。 我正在拍照,将其保存到默认文档文件夹中,然后我想将它们取出并放入 HTML 字符串中,该字符串稍后会转换为 PDF。我需要做的最后一件事是将保存的图像转换为 HTML。有人知道该怎么做吗?

这是我的图像保存功能:

private func saveImage(imageData: Data, named: String, completion: @escaping (URL) -> Void) {
        guard let directory = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) as NSURL else {
            return
        }
        do {
            try imageData.write(to: directory.appendingPathComponent(named)!)
            completion(directory.appendingPathComponent(named)! as URL)
        } catch {
            print(error.localizedDescription)
            return
        }
    }

之后我将其放入 HTML 中:

"<td class='unit'>" + "/(url.absoluteString).png" + "</td></tr>"

它实际上是图像的完整路径,但我猜它不是那样工作的,不幸的是这样结束:

Image with the resulting PDF after html rendering/

【问题讨论】:

标签: html swift image pdf


【解决方案1】:

您必须将路径放入图像(img)标签中。

"<td class='unit'><img src='/(url.absoluteString).png' /></td></tr>"

【讨论】:

  • ` 仍然没有人:/也许我应该去掉“文件:”?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-28
  • 2017-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-09
  • 2015-03-07
相关资源
最近更新 更多