save Image To Local File - Android android.graphics

Android examples for android.graphics:Image Load Save

Description

save Image To Local File

Demo Code

import java.io.File;
import java.io.FileOutputStream;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {

  public static void saveImageToLocal(String originalPath, String destinationPath) {///
    Bitmap finalBitmap = BitmapFactory.decodeFile(originalPath);
    File myDir = new File(destinationPath);
    myDir.mkdirs();/*  w  w  w. j a v a  2 s .c  o m*/
    File file = new File(myDir, originalPath.substring(originalPath.lastIndexOf("/") + 1));
    if (file.exists())
      file.delete();
    try {
      FileOutputStream out = new FileOutputStream(file);
      if (finalBitmap != null) {
        finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
      }

      out.flush();
      out.close();

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

}

Related Tutorials