1

When I'm trying to convert the Mat image to Bitmap the image doesn't displayed in my device, on the contrary when I use Bitmap.Config.RGB_565 the displayed image is black. Here is my code:

Mat src = new Mat(bmp.getHeight(), bmp.getWidth(), CvType.CV_8UC1);
        imgToProcess = Utils.bitmapToMat(bmp, src);

        Bitmap bmpOut = Bitmap.createBitmap(imgToProcess.cols(), imgToProcess.rows(), Bitmap.Config.ARGB_8888);
        Utils.matToBitmap(imgToProcess, bmpOut);
        imv.setImageBitmap(bmpOut);
        rotateImage(bmpOut);

1 Answers1

0

matToBitmap is known to be buggy. As a workaround, try to convert your image to different colorspace before converting to bitmap:

Imgproc.cvtColor(imgToProcess, result, Imgproc. COLOR_GRAY2BGRA);
bmp = Bitmap.createBitmap(result.cols(), result.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(result, bmp);

See related issue Correct way to convert between Bitmap and Mat in OpenCV on Android?

Community
  • 1
  • 1
taarraas
  • 1,483
  • 9
  • 18