I want to save the Mat Images in android gallery automatically. When I run my code in an Emulator the resultant Mat Image is not saving in Gallery.
The code for saving Images is below
String Folder = Environment.getExternalStorageDirectory().getPath()+"/Gallery";
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").Format(new Date());
Highgui.imwrite(Folder + "/" + "Name_" + timestamp + ".png", outputImage);
--It didn't worked and so I searched for an answer in this Forum and tried the answer from the below post
http://answers.opencv.org/question/68206/saving-an-image-using-opencv-android/
> //subimg -> your frame
Bitmap bmp = null;
try {
bmp = Bitmap.createBitmap(subimg.cols(), subimg.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(subimg, bmp);
} catch (CvException e) {
Log.d(TAG, e.getMessage());
}
subimg.release();
FileOutputStream out = null;
String filename = "frame.png";
File sd = new File(Environment.getExternalStorageDirectory() + "/frames");
boolean success = true;
if (!sd.exists()) {
success = sd.mkdir();
}
if (success) {
File dest = new File(sd, filename);
try {
out = new FileOutputStream(dest);
bmp.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap instance
// PNG is a lossless format, the compression factor (100) is ignored
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, e.getMessage());
} finally {
try {
if (out != null) {
out.close();
Log.d(TAG, "OK!!");
}
} catch (IOException e) {
Log.d(TAG, e.getMessage() + "Error");
e.printStackTrace();
}
}
}
It too didn't worked out for me.
I searched for the permissions in AndroidManifest file and it is fine.
Any words from you......
↧