Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Saving Mat Image in Android Gallery

$
0
0
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......

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>