objective c - Initialize an image from a given path in swift? -
I object> This code
selectedImage = [[NSImage alloc] initWithContentsOfFile: [_the path path]]; If (selectedImage.size.width & lt; selectedImage.size.height) {imageProportion = selectedImage.size.height /selectedImage.size.width; [Selected image set size: nsmcases (690.0, 690.0 * imagepropation)]; } Other {imageProportion = selectedImage.size.width /selectedImage.size.height; [Selected image set size: nsmcases (690.0 * imageproportion, 690.0)]; } [_imageEditorWindow orderFront: nil]; [_imageViewEditor setFrameSize: NSMakeSize (selected image size.width, selectedImage.size.height)]; InitialImageSizeH = Selected Image.size.height; InitialImageSizeW = Selected Image.size.width; [_imageViewEditor setImage: selectedImage]; [_imageViewEditor setFrameOrigin: NSMakePoint (45, 35)];
If I write this code in Swift using the playground, but I get an error:
var selectedImage = NSImage (byReferencingURL: NSURL (string: "/ users / admin / desktop / 10658771_575156615924178_8253607361793017933_o.jpg"))
2014-11-04 15: 32: 37.582 MyPlayground [2327: 701,632] CFURLCopyResourcePropertyForKey failed because it was the URL a plan which was passed: /Users/admin/Desktop/10658771_575156615924178_8253607361793017933_o.jpg November 4 15:32:37 imac.inf.ucv.local MyPlayground [2327]: ImageIO: need to be CGImageDestinationFinalize image destination Yk at least one image 2014-11-04 15: 32: 37.592 MyPlayground [2327 is: 701,632] CGImageDestinationFinalize production of 'public.tiff'
and fail if I use this code:
var selectedImage = NSImage (byReferencingFile: "/Users/admin/Desktop/10658771_575156615924178_8253607361793017933_o.jpg")
ov 4 15:34:56 imac. Inf.ucv.local MyPlayground [2331]: ImageIO: Fix Image on CGImageDestinati Image should have at least one image 2014-11-04 15: 34: 56.014 MyPlayground [2331: 701825] CGImageDestinationFinalize Output Type 'public.tiff 'Failed for'
So, what is wrong? Do these errors say that my file is not an image?
Thank you, and sorry for my English!
It is looking for a TIFF image representing NSBitmapImageRep
to NSImage
. I recently got this issue and found that it is making a NSBitmapImageRep
and approved it for the NSImage
presentation.
assuming that the image is a NSImage
example
let's go = image =. CGImageForProposedRect (zero, reference: zero, signal: zero)! Give rep = NSBitmapImageRep (CGImage: cg) image.addRepresentation (self.bitmapRep)
Give it a try and see if it works better Now your methods get TIFF representation from the image Should be able to
Comments
Post a Comment