如何在内部存储中保存图像并在imageView中以另一个活动显示图像,请告诉我如何将该图像保存在内部存储中,因为许多手机只有内部存储而不是SD卡
//camera
camera = (ImageView) findViewById(R.id.takePic);
camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File pictureDirectory=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String pictureName=getPictureName();
File imageFile=new File(pictureDirectory,pictureName);
pictureUri=Uri.fromFile(imageFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT,pictureUri);
startActivityForResult(intent,CAMERA_REQUEST_CODE);
}
});
private String getPictureName() {
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd_HHmmss");
String timestamp=sdf.format(new Date());
return "Plane place image"+timestamp+".jpg";
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==RESULT_OK){
if (resultCode==CAMERA_REQUEST_CODE)
{
pictureUri = data.getData();
if (pictureUri!=null) {
Intent intent = new Intent(this, PictureActivity.class);
intent.setData(pictureUri);
intent.putExtra("imgUrl", pictureUri.toString());
startActivity(intent);
}
}
}
}
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
Log.e("ashish", bundle.getString("imgUrl") + "");
path = Uri.parse(bundle.getString("imgUrl"));
}
ImageView selfiiii = (ImageView) findViewById(R.id.mySelfie);
selfiiii.setImageURI(path);
答案 0 :(得分:0)
我将图像存储在代码下面的模拟器内部存储中...
created_at
答案 1 :(得分:0)
在opencamera方法中进行更改,例如在代码下面使用...
private void OpenCamera(){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap thumbnail = null;
if (resultCode==RESULT_OK){
if (requestCode==CAMERA_REQUEST_CODE)
{
thumbnail = (Bitmap) data.getExtras().get("data");
Intent intent = new Intent(this, DbInsert.class);
intent.putExtra("name", thumbnail);
startActivity(intent);
}
}
}
第二项活动......
Bitmap bitmap = getIntent().getExtras().getParcelable("name");
imageView.setImageBitmap(bitmap);