문제

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 ?

도움이 되었습니까?

해결책

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

다른 팁

    Drawable drawable;

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

HTH !

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top