I'm trying to setup up a NSCollectionView which is binded to an entity and I'm trying to load an image into an NSImageView out of this entity. I stored the image as a NSData object.
I did a little research and found out that I'm supposed to set a ValueTransformer but I couldn't get this work.
Here is my Code for the save process of my image attribute pdfImage:
pdf = NSData(contentsOfFile: path)
// pdf to image
let pdfImageRep = NSPDFImageRep(data: pdf)
let factor: CGFloat = 300/72
pdfImageRep?.currentPage = 1
let image = NSImage(size: self.frame.size, flipped: false,
drawingHandler: {
dstRect in
(pdfImageRep?.drawInRect(dstRect))!
return true
})
let scaledImageRep = image.representations.first
scaledImageRep?.pixelsWide = Int((pdfImageRep?.size.width)! * factor)
scaledImageRep?.pixelsHigh = Int((pdfImageRep?.size.height)! * factor)
let pngImageRep = NSBitmapImageRep(data: image.TIFFRepresentation!)
let imageData = pngImageRep?.representationUsingType(NSBitmapImageFileType.NSJPEGFileType, properties: [:])
pdfImage = imageData
I save the pdfImage later in the code.
As I said I tried to use NSKeyedUnarchiveFromData as ValueTransformer but it didn't work.
Am I doing it wrong or is there an easier way? And can somebody help me with this problem?
Thank you very much!