Save scanned image on SDcard?

16 views
Skip to first unread message

Sanawer Malik

unread,
Sep 30, 2013, 2:52:24 AM9/30/13
to zx...@googlegroups.com
I want to save the scanned image on my SDcard to keep the record of scanning.. Here is my code to save the image which is working perfectly in my camera app but not in zxing project.

public void SaveIamge(Bitmap finalBitmap) {

String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/scanned_Images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-" + n + ".jpg";
File file = new File(myDir, fname);
if (file.exists())
file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();

} catch (Exception e) {
e.printStackTrace();
}

getContext().sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));

}

So my question is that in which file and where I've to call this function so that my scanned image will save in my gallery. Thanx in advance.
Reply all
Reply to author
Forward
0 new messages