2012-07-21 53 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。然后您可以使用该流来获取原始字节数组(使用读取函数)。

相关问题