我有代码从SD卡加载图像,并将其发布到ImageView。
Mat mRgba = Highgui.imread(dir);
Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mRgba, bmp);
mImage.setImageBitmap(bmp, true, null, 5.0f);图像已加载,但颜色错误。颜色似乎是反转的(但不是反转的)。这是image comparison
我尝试通过以下方式加载图像
Bitmap bmp = BitmapFactory.decodeFile(dir);它工作正常。但我必须使用Highgui.imread。
我的代码有什么问题?
发布于 2013-05-05 23:35:30
你将不得不使用类似这样的东西:
Mat inputImage = Highgui.imread(pathToFile);
Mat tmp = new Mat();
Imgproc.cvtColor(inputImage, tmp, Imgproc.COLOR_BGR2RGB);
Bitmap imageToShow = Bitmap.createBitmap(tmp.cols(), tmp.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(tmp, imageToShow);发布于 2012-12-06 00:59:25
你正在尝试加载一个位图,假设图像是8位/彩色RGBA:你确定吗?
发布于 2012-12-06 01:10:00
另请注意,ARGB不是RGBA。您可能需要重新排列每个像素的字节。就像这样
int pixel = get_the_pixel();
int alpha = 0xff & pixel;
pixel = pixel<<8 | alpha;
set_the_pixel(pixel);您可能想要做一些比这里所示的访问器方法更有效的事情,但是您得到了这个想法。
https://stackoverflow.com/questions/13727899
复制相似问题