2012-07-21 32 views

回答

1

使用getResources()方法獲取繪圖。

Drawable drawable= getResources().getDrawable(R.drawable.image1); 

類型轉換爲BitmapDrawable,

Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap(); 

compress經由方法寫位圖指定的OutputStream的壓縮版本。

ByteArrayOutputStream out = new ByteArrayOutputStream(); 
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); 
byte[] buffer= out.toByteArray(); 
+0

謝謝你的回答。你節省了我的時間。感謝+1 – 2012-07-21 08:22:51

0

您可能想要使用Resources類中的openRawResource函數。它會給你一個InputStream。然後您可以使用該流來獲取原始字節數組(使用讀取函數)。

相關問題