public class SaveImageToRaw {
private Context context;
private Bitmap bitmap;
public SaveImageToRaw(Context context){
this.context = context;
}
public void savaImage(String filename,Bitmap bitmap){
try {
FileOutputStream fos = context.openFileOutput(filename,context.MODE_PRIVATE);
//bitmap转文件对象
bitmap.compress(Bitmap.CompressFormat.PNG,100,fos);
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public Bitmap getImage(String filename){
try {
FileInputStream fis = context.openFileInput(filename);
bitmap = BitmapFactory.decodeStream(fis);
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
}
android中保存图片到/data/data/<package name>/files/目录中
最新推荐文章于 2021-10-14 17:29:25 发布