こんにちは、私はConverting bitmap to byteArray androidを実装しようとしています。バイト[]を圧縮せずにビットマップに変換する必要があります。しかし、いつも、私は完全に黒いイメージを得ていますか?どのようにそれを行うにはどのようなアイデア? 何イム私はそれがバイト配列からビットマップへの変換の問題
BitmapFactory.Options options = new
BitmapFactory.Options();
options.inScaled = false;
Bitmap bmp = BitmapFactory.decodeByteArray(barray,0, barray.length,options);
ImageView imageView = (ImageView) findViewById(R.id.resdetayimage);
imageView.setImageBitmap(bmp);`
EDIT ビットマップの工場デコードのみ圧縮されたものをビットマップに取得する方法
int bytes = bmp.getByteCount();
ByteBuffer buffer = ByteBuffer.allocate(bytes);
bmp.copyPixelsToBuffer(buffer);
byte[] resarray = buffer.array();
そして、ここをやって。それは私のコードが動作しない理由です。だから私は何かのようなものが必要です。
Bitmap.Config configBmp = Bitmap.Config.valueOf(bitmap.getConfig().name());
Bitmap bitmap_tmp = Bitmap.createBitmap(width, height, configBmp);
ByteBuffer buffer = ByteBuffer.wrap(byteArray);
bitmap_tmp.copyPixelsFromBuffer(buffer);
しかし、コードはまだ機能しません。だから私はこれをどのように実装できますか?私は意図からバイト[]を得ました。 BYTEARRAY
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, bStream);
byte[] mByteArray = bStream.toByteArray();
それはcopyPixelsToBuffer()
の逆であるとして使用copyPixelsFromBuffer()
Bitmap bitmap = BitmapFactory.decodeByteArray(mByteArray , 0, mByteArray.length);
Bitmap = Bitmap.createBitmap(resarray、bmp.getWidth()、bmp.getHeight()、bmpgetConfig())というビットマップを作成できますか? – dex
copyPixelsToBuffer()の逆を行う必要があります。バッファからの読み込みピクセルなどがありますか? DecodeByteArrayはその配列内のjpgファイルを必要とします。ピクセルではありません。今はnullを返すと思います。チェックしてください。そうではなく、「黒い画像」。 – greenapps
nullが返されていないことを確認済み –