Tuesday, August 5, 2014

android using images store to sdcard

Android using image store to sdcard
============================

image convert to bitmap

private void SaveImage(Bitmap finalBitmap) {


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

    } catch (Exception e) {
           e.printStackTrace();
           Toast.makeText(Mycoupon_detail.this, "SAVE IMAGE FAIL", Toast.LENGTH_LONG).show();
    }
}

No comments:

Post a Comment