2010-05-13 42 views
4

我想從位於我的res/drawable文件中的jpeg圖像獲取一個字節數組?如何從可繪製資源中獲取字節數組?

有誰知道該怎麼做?

+0

我相信你可以在http://stackoverflow.com/questions/6602417/get-the-uri-of-an-image-stored-in-drawable/36062748#36062748使用的解決方案 – 2016-08-20 20:29:27

回答

2
ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
mPhoto.compress(Bitmap.CompressFormat.JPEG /* FileType */, 
         100 /* Ratio */, stream);

HTH!

9
Drawable drawable; 

    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); 
    ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); 
    byte[] bitmapdata = stream.toByteArray();