John John - 1 year ago 142
Android Question

convert Bitmap to Mat after capture image using android camera

Mat b = new Mat();
Bitmap bmp = getIntent().getExtras().getParcelable("image_send");

protected void onCreate(Bundle savedInstanceState) {
Mat tmp = new Mat (bmp.getWidth(), bmp.getHeight(), CvType.CV_8UC1);
Utils.bitmapToMat(bmp, tmp);
Imgproc.cvtColor(tmp, tmp, Imgproc.COLOR_RGB2GRAY);
//Imgproc.cvtColor(tmp, tmp, Imgproc.COLOR_GRAY2RGB, 4);
Utils.matToBitmap(tmp, bmp);

iv = (ImageView) findViewById(;

Can't display the bmp. My app has stopped after taking a picture.

Answer Source

Bitmap bmp32 = bmpGallery.copy(Bitmap.Config.ARGB_8888, true);
Utils.bitmapToMat(bmp32, imgMAT);

I hope that will help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download