【发布时间】:2019-07-26 14:29:05
【问题描述】:
我想知道如何将图像保存在我的存储中,因为在我的应用程序中我可以拍照并查看它,但是当我关闭我的应用程序并重新打开它时,图像消失了我使用了位图。
我的代码:
public static final int REQUEST_CODE = 01;
private ImageView imgs1;
private File outputMediaFile;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.semana1);
imgs1 = (ImageView) findViewById(R.id.imgs1);
}
public void btnTakePhotoClicked1(View v){
Intent intent1= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent1, REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK){
Bitmap bm1= (Bitmap) data.getExtras().get("data");
imgs1.setImageBitmap(bm1);
}
}
【问题讨论】:
-
您只想将它们保存在图库或应用中?
-
我只希望图像不要消失。
-
@spain 请不要玷污你自己的问题。
-
将该位图路径保存在 SharedPreference 中,并在再次打开应用程序时检查它并使用该路径再次加载