public File mCurrentPhotoFile = null;
public String path = "/storage/emulated/0/DCIM/Camera/";
public static SharedPreferences sharedPreferences = null;
public SharedPreferences.Editor editor = null;
public void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
sharedPreferences = this.getSharedPreferences("Storage",0);
editor = sharedPreferences.edit();
String path = sharedPreferences.getString("ReadPhotoPath",null);
if(path!=null){
Bitmap bitmap = ReadPreviewBitmap(path);
headerImage.setImageBitmap(bitmap) /*** 设置图片***/
}
}
/****保存图片本地***/
public void savePreviewBitmap(Bitmap bitmap){
FileOutputStream fos = null;
try{
mCurrentPhotoFile.createNewFile();
fos = new FileOutputStream(mCurrentPhotoFile);
bitmap.compress(Bitmap.CompressFormat.JPEG,100,fos);
fos.flush();
fos.close();
}catch(Exception e){
}
}
/****读取本地图片****/
public Bitmap ReadPreviewBitmap(String paths){
FileInputStrean fis = null;
if(paths!=null){
try{
fis = new FileInputStrean(paths);
Bitmap bitmap = BitmapFactory.decodeStram(fis);
if(bitmap!=null) return bitmap;
}catch( Exception e){
}
}
return null;
}
/****打开相机*****/
public void doPickPhoto(){
mCurrentPhotoFile = new File(path,System.currentTimeMillis()+".jpg");
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,0);
}
/***函数回调***/
pretected void onActivityResult(int reqcode,int respcode,Intent data){
super.onActivityResult(reqcode,respcode,data);
Bundle bundle = data.getExtras();
Bitmap bitmap = (Bitmap)bundle.get("data");
if(bitmap!=null){
savePreviewBitmap(bitmap);
editor.clear().commit();
editor.putString("ReadPhotoPath",mCurrentPhotoFile.getPath());
editor.commit();
}
}
浙公网安备 33010602011771号