2012-12-07 71 views
1

我不知道,爲什麼我從BitmapFactory.decodeFile(String imagePath)方法中獲取null。 imagePath是完美的。代碼在這裏。BitmapFactory.decodeFile(String imagePath)返回null連圖像存在

public static byte[] imageToByteArray(String imagePath){ 
     Bitmap bitmap = BitmapFactory.decodeFile(imagePath); 
     ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 

     bitmap.compress(Bitmap.CompressFormat.JPEG , 100 , byteArrayOutputStream); 
     return byteArrayOutputStream.toByteArray(); 
    } 

imaagePath是。這裏我使用谷歌的地方API和ImagePath的是谷歌的網絡服務定圖像的位置的互聯網具體路徑。

+0

http://stackoverflow.com/questions/11372831/android-bitmapfactory-decodestream-doesnt-load-https-url-on-emulator –

回答

4

decodeFile用於從本地文件系統獲取Bitmap

Decode a file path into a bitmap. If the specified file name is null, or cannot be decoded into a bitmap, the function returns null. 

從Internet使用

Bitmap bitmap = BitmapFactory.decodeStream(imageUrl.openConnection().getInputStream()); 

不要忘了在上面後臺線程行運行得到Bitmap

+0

真棒。你再次幫助我 – ved

+0

1個更多的問題@Mohsin。 我在嘗試在Facebook牆上發佈圖片時遇到以下錯誤。 {「error」:{「message」:「Unsupported method,photos.upload」,「type」:「Exception」}} 請幫幫我。 – ved

相關問題