将图像转换为位图后,图像不显示
问题描述:
当我试图将Mat图像转换为位图时,图像不会显示在我的设备中,相反,当我使用Bitmap.Config.RGB_565
时,显示的图像为黑色。 这里是我的代码:将图像转换为位图后,图像不显示
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);
答
matToBitmap被称为是马车。作为一种变通方法,尝试转换为位图之前,你的图像转换成不同的色彩空间:
Imgproc.cvtColor(imgToProcess, result, Imgproc. COLOR_GRAY2BGRA);
bmp = Bitmap.createBitmap(result.cols(), result.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(result, bmp);
参阅相关的问题Correct way to convert between Bitmap and Mat in OpenCV on Android?
我试着将它转换成不同的色彩空间,但应用程序停止工作。 –