I have an project that used Camera and Opencv. I take picture and crop image with OpenCv. After I have a Mat file to convert Jpeg for send byte[] data to Activity.
Mat to Bitmap
bmp2 = Bitmap.createBitmap(checkFrame.cols(),checkFrame.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(checkFrame, bmp2, true);
checkFrame.release();
Bitmap to byte[]
ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
bmp2.compress(Bitmap.CompressFormat.JPEG, 0,stream2);
bmp2.recycle();
bmp2 = null;
byte[] byteArray2 = stream2.toByteArray();
On Activity ,
((ImageView) findViewById(R.id.photoView))
.setImageBitmap(BitmapFactory
.decodeByteArray(photo2, 0,
photo2.length));
But this image is not same with I cropped. This is like 16bit color... If I direct send Bitmap to activity and set ImageBitmap, this is good. Why does the image break when it's converted to byte[]?