2011-10-20 24 views
14

我在sqlite數據庫中存儲圖像的完整路徑,該圖像存儲在設備中,並且需要使用該圖像設置UIImage。使用圖像的路徑初始化UIImage

實施例:

NSLog(@"Path %@", imagePath); 

輸出:

/Users/Sk*****/Library/Application Support/iPhone Simulator/4.3.2/Applications/15977219-DEFE-407A-BB80-72E188E18DD2/Documents/20-10-20111746.png 

回答

32

使用+ (UIImage *)imageWithContentsOfFile:(NSString *)path

UIImage *image = [UIImage imageWithContentsOfFile:imagePath]; 
+4

好的......我做到了。它不工作的主要原因是... UIImageView被隱藏。我是個白癡!不管怎麼說,還是要謝謝你。 – Oiproks

1

夫特3.0代碼在這裏..

使用contentsOfFile

imageView.image = UIImage.init(contentsOfFile: imagePath) 
+0

建議使用UIImage(contentsOfFile:imagePath)。 – user5685969

+0

@ user5685969如果你想在你的設備上顯示圖像路徑,那麼你應該使用這個,但是你的代碼在版本swift 3.0之前 –