OpenCV Rectangle are black when image is saved as bitmap
Following is the image seen on mobile screen before saving :
After saving the image to external storage :
Please guide how to fix the color of the rectangles drawn by the opencv.
Below is my code :
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;
}
Following code to set the image:
Bitmap resultBitmap=BitmapFactory.decodeFile("Path for image");
Mat m_ogr = new Mat(resultBitmap.getWidth(), resultBitmap.getHeight(), CvType.CV_8UC3);
List 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);

