开发者

How to get a byte array from a drawable resource ?

开发者 https://www.devze.com 2022-12-30 09:07 出处:网络
I would like to get a byte array from an jpeg image located in my res/drawable file ? Does anyone know开发者_运维问答 how to do that please ?Drawable drawable;

I would like to get a byte array from an jpeg image located in my res/drawable file ?

Does anyone know开发者_运维问答 how to do that please ?


    Drawable drawable;

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


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


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

HTH !

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号