如何在Mac App中从粘贴板复制图像并将图像写入粘贴板

时间:2019-03-30 11:20:36

标签: swift macos nspasteboard

我正在尝试从粘贴板复制图像并将图像写入粘贴板,但是将数据设置为粘贴板后,我无法将图像粘贴到系统中的任何位置。 我正在使用的代码块下面。

// Copying image data from paste board
let pasteboard = NSPasteboard.general
let imageData = pasteboard.data(forType: NSPasteboard.PasteboardType.tiff)


//Writing image data to paste board

  let pb = NSPasteboard.general

      pb.declareTypes([NSPasteboard.PasteboardType.tiff], owner: nil)

    if let imageData = imageData.tiffRepresentation{
        print("imagedata \(imageData)")
         pb.clearContents()
       pb.setData(imageData, forType: NSPasteboard.PasteboardType(rawValue: "NSTIFFPboardType"))
   }

有什么建议吗?

预先感谢!

0 个答案:

没有答案