如何将NSImage转换为JPEG数据,同时保持NSImage的宽度和高度?

时间:2018-11-29 13:13:00

标签: swift appkit nsimage

以下代码将NSImage转换为JPEG数据,但转换后图像将丢失其原始宽度和高度。如何执行转换,同时保持图像的原始尺寸。

let resizedImage = resizeImage(imageData: imageData, maxSize: maxSize) // return type is NSImage
let cgImage = resizedImage.cgImage(forProposedRect: nil, context: nil, hints: nil)!
let bitmapRep = NSBitmapImageRep(cgImage: cgImage)
let jpegData = bitmapRep.representation(using: NSBitmapImageRep.FileType.jpeg, properties: [:])

0 个答案:

没有答案