下面的代码保存的图片在平板上浏览是全黑色的图,但是在电脑上打开就是正常的,代码看上去是没问题的,难道真的是我的平板有问题嘛
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.abc1);
try {
String filePath = null;
//如果手机已插入sd卡,且app具有读写sd卡的权限
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
if (Build.VERSION.SDK_INT < 29) {
//安卓10以下保存在SD卡根目录
filePath = Environment.getExternalStorageDirectory().getCanonicalPath() + "/" + System.currentTimeMillis() + ".jpg";
} else {
//安卓10以上保存在Android/data/com.example.filetorw/files目录下
filePath = MainActivity.this.getExternalFilesDir(null).getAbsolutePath() + "/" + System.currentTimeMillis() + ".jpg";
}
}
FileOutputStream outStream = new FileOutputStream(filePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}