当我使用此功能保存位图时,我得到一个不可读的文件,比原始图像大(使用手机上的Root explorer)有什么问题? 位图由用户使用库存图像选择器设置。
这是电话:
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
saveToInternalSorage(bitmap);
这里是saveToInternalSorage方法(从这里Saving and Reading Bitmaps/Images from Internal memory in Android)
private String saveToInternalSorage(Bitmap bitmapImage){
ContextWrapper cw = new ContextWrapper(getApplicationContext());
// path to /data/data/yourapp/app_data/imageDir
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
// Create imageDir
String filename = randomString();
System.out.println(filename);
File mypath=new File(directory,filename);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
return directory.getAbsolutePath();
}