我在目標C的代碼從swift中給定路徑初始化圖像?
selectedImage = [[NSImage alloc] initWithContentsOfFile:[_thePath path]];
if (selectedImage.size.width < selectedImage.size.height) {
imageProportion =selectedImage.size.height /selectedImage.size.width ;
[selectedImage setSize:NSMakeSize(690.0, 690.0* imageProportion)];
} else{
imageProportion =selectedImage.size.width /selectedImage.size.height ;
[selectedImage setSize:NSMakeSize(690.0* imageProportion, 690.0)];
}
[_imageEditorWindow orderFront:nil];
[_imageViewEditor setFrameSize:NSMakeSize(selectedImage.size.width, selectedImage.size.height)];
initialImageSizeH = selectedImage.size.height ;
initialImageSizeW = selectedImage.size.width ;
[_imageViewEditor setImage:selectedImage];
[_imageViewEditor setFrameOrigin:NSMakePoint(45, 35)];
如果我寫在夫特這個代碼,用操場但我收到錯誤:
var selectedImage = NSImage(byReferencingURL: NSURL (string: "/Users/admin/Desktop/10658771_575156615924178_8253607361793017933_o.jpg")!)
2014年11月4日15:32:37.582 MyPlayground [2327:701632] CFURLCopyResourcePropertyForKey失敗,因爲它傳遞了這個沒有方案的URL:/ Users/admin/CGImageDestinationFinalize圖片的目的地必須至少有一個圖片 2014年11月4日15:32:37.592 MyPlayground [2327:701632] CGImageDestinationFinalize失敗輸出類型 'public.tiff'
,如果我使用以下代碼:
var selectedImage = NSImage(byReferencingFile: "/Users/admin/Desktop/10658771_575156615924178_8253607361793017933_o.jpg")
OV 4 15點34分:56 imac.inf.ucv.local MyPlayground [2331]:ImageIO:CGImageDestinationFinalize圖像目標必須至少有一個圖像 2014-11-04 15:34:56.014 MyPlayground [2331:701825] CGImageDestinationFinalize失敗,輸出類型爲public。 tiff'
那麼,什麼是錯的?這個錯誤說我的文件不是圖像?
謝謝,對不起我的英語!
你能舉一個你提出的答案的客觀例子嗎? – Tiago 2017-04-09 14:51:30