4

我想从我的 res/drawable 文件中的 jpeg 图像中获取一个字节数组?

请问有谁知道该怎么做?

4

3 回答 3

11
    Drawable drawable;

    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] bitmapdata = stream.toByteArray();
于 2012-03-01T11:22:02.413 回答
7

Get a bitmap decodeResource(android.content.res.Resources, int) Then either compress it to ByteArrayOutputStream() or copyPixelsToBuffer and get your array from the buffer. http://developer.android.com/reference/android/graphics/Bitmap.html

于 2010-05-13T19:33:53.500 回答
2
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mPhoto.compress(Bitmap.CompressFormat.JPEG /* FileType */,
                        100 /* Ratio */, stream);

于 2010-05-14T03:15:18.530 回答