android - 当图像保存为位图时,OpenCV 矩形是黑色的
问题描述
以下是保存前在手机屏幕上看到的图像:
将图像保存到外部存储后:
请指导如何修复opencv绘制的矩形的颜色。
下面是我的代码:
Bitmap new_bitmap = takeScreenShot(findViewById(R.id.img));
Bitmap workingBitmap = Bitmap.createBitmap(new_bitmap);
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
File outFile = new File("External directory", "My folder name");
FileOutputStream outStream = new FileOutputStream(outFile);
mutableBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
public Bitmap takeScreenShot(View view) {
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_AUTO);
view.buildDrawingCache(true);
Bitmap image = view.getDrawingCache();
if (image != null) {
return Bitmap.createBitmap(image, 0, 0, image.getWidth(), image.getHeight());
}
return null;
}
以下代码设置图像:
Bitmap resultBitmap=BitmapFactory.decodeFile("Path for image");
Mat m_ogr = new Mat(resultBitmap.getWidth(), resultBitmap.getHeight(), CvType.CV_8UC3);
List<Rect> rectList = "Some list with Rect elements";
for (int fi = 0; fi < rectList.size(); fi++) {
Imgproc.rectangle(m_ogr, new Point(rectList.get(fi).x, rectList.get(fi).y),
new Point(rectList.get(fi).x + rectList.get(fi).width, rectList.get(fi).y + rectList.get(fi).height),
new Scalar(50, 205, 50), 2);
}
Utils.matToBitmap(m_ogr, resultBitmap);
img.setImageBitmap(resultBitmap);
解决方案
保存前如何显示图像?OpenCV 不使用 alpha 通道,在矩形位置可能为 0(例如,如果您绘制的矩形只有 3 个颜色值而不是 4 个)?
推荐阅读
- reactjs - 我们可以在一个部分列表中添加两个平面列表吗?
- python - 如何导入进一步导入其他文件的python文件。没有得到 ImportError?
- javascript - 使用 axios 向服务器发出请求会冻结 React Native 应用程序
- regex - 如何修复此正则表达式以匹配我想要的字符串?
- python - Python:如何遍历树的所有未知深度?
- java - 编译报错包 com.fasterxml.jackson.annotation 不存在
- html - VBA IE 如何使用 MouseEvetns 'mouseover' 和 'mouseleave' 单击按钮
- arrays - R中按列进行的复杂元素比较
- c# - 当.Result()使方法挂起时如何在构造函数中使用异步方法?
- c# - 使用 Blazor 的默认 SignalR 连接发送“Hello World”