I'm receiving a Bitmap in byte array through socket and I read it and then I want to set it os.toByteArray
as ImageView
in my application. The code I use is:
try { //bmp = BitmapFactory.decodeByteArray(result, 0, result.length); bitmap_tmp = Bitmap.createBitmap(540, 719, Bitmap.Config.ARGB_8888); ByteBuffer buffer = ByteBuffer.wrap(os.toByteArray()); bitmap_tmp.copyPixelsFromBuffer(buffer); Log.d("Server",result+"Length:"+result.length); runOnUiThread(new Runnable() { @Override public void run() { imageView.setImageBitmap(bitmap_tmp); } }); return bmp; } finally { }
When I run my application and start receiving Byte[]
and expect that ImageView
is changed, it's not.
LogCat says:
java.lang.RuntimeException: Buffer not large enough for pixels at android.graphics.Bitmap.copyPixelsFromBuffer
I searched in similar questions but couldn't find a solution to my problem.