我想要存储图片,但我不知道我应该在android studio中放置“b.jpg”,它应该在“Drawable”或其他 PS:“b.jpg”是PC文件
这是我的代码
String externalDir = Environment.getExternalStorageDirectory().toString();
imgFile = externalDir + "/b.jpg";
iv_file = findViewById(R.id.image);
iv_file.setDrawingCacheEnabled(true);
Button btn_img_save = findViewById(R.id.btn_img_save);
Button btn_img_open = findViewById(R.id.btn_image_read);
btn_img_save.setOnClickListener(this);
btn_img_open.setOnClickListener(this);
}
private void saveBitmap(String path, Bitmap bitmap) {
try {
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(path));
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
bos.flush();
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
}