import android.graphics.Bitmap; import android.text.format.DateFormat; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Calendar; import java.util.Locale; /** * Created by 牛皮 */ public class SavePhoto { private static String filename; public static String getFilename() { return filename; } public static void getPhoto(Bitmap bitmap){ new DateFormat(); String name= DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA))+".jpg"; FileOutputStream fout = null; File file = new File("/sdcard/pintu/"); file.mkdirs(); filename = file.getPath() + name; try { fout = new FileOutputStream(filename); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fout); } catch (FileNotFoundException e) { e.printStackTrace(); }finally{ try { fout.flush(); fout.close(); } catch (IOException e) { e.printStackTrace(); } } } }
时间: 2024-10-28 02:08:11