gpt4 book ai didi

Swift OSX - 在 IKImageView 上设置 NSImage

转载 作者:行者123 更新时间:2023-11-28 15:20:36 26 4
gpt4 key购买 nike

我正在尝试在 IKImageView 上设置来自 NSImage 的图像。我已经使用 NSImage.cgImage 从 NSImage 获取了 CGImage,但是要在 IKImageView 上设置它,我需要图像的属性。我怎样才能获得这些属性?

import Cocoa
import Quartz

class AjustarImagemViewController: NSViewController {

@IBOutlet weak var imagemIKImageView: IKImageView!

var imagem: NSImage? //Receive an image from another view

override func viewDidLoad() {
super.viewDidLoad()

print(imagem)

if let imagemRecebida = imagem {


let cgImagem = imagemRecebida.cgImage(forProposedRect: nil, context: nil, hints: nil)

imagemIKImageView.setImage(cgImagem, imageProperties: [AnyHashable : Any])
}
}

@IBAction func voltarButtonClicked(_ sender: NSButton) {

dismiss(self)
}
}

最佳答案

像这样的东西应该可以解决问题:

CGImageSourceRef source;

source = CGImageSourceCreateWithData((CFDataRef)[cgImagem TIFFRepresentation], NULL);

NSDictionary* props = (NSDictionary*)CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);

imagemIKImageView.setImage(cgImagem, imageProperties: props)

关于Swift OSX - 在 IKImageView 上设置 NSImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46073419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com