Domanda

mi piacerebbe ottenere un array di byte da un'immagine jpeg situato nei miei res / file di drawable?

Qualcuno sa come fare per favore?

È stato utile?

Soluzione

Ottenere una bitmap decodeResource(android.content.res.Resources, int) Allora o comprimerlo a ByteArrayOutputStream () o copyPixelsToBuffer e ottenere l'array dal buffer. http://developer.android.com/reference/android/graphics/Bitmap.html

Altri suggerimenti

    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!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top