以下是我的相机代码
public void takepic(View view) {
Spinner spinner1 = (Spinner)findViewById(R.id.spinner1);
String schname = spinner1.getSelectedItem().toString();
String[] tokens = schname.split(" ");
String timeStamp = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss").format(new Date());
String imageFileName = tokens[0] + "-" + timeStamp + ".jpg";
TextView detail = (TextView)findViewById(R.id.textView1);
detail.setText(imageFileName);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String name = imageFileName;
File file = new File(path, name );
ImageView mImage = (ImageView) findViewById(R.id.mImageView);
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
new SingleMediaScanner(this, file);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
mImage.setImageBitmap(thumbnail);
}}}
当调用它运行时,相机应用程序拍摄照片并将其存储在带有预定义文件名的Pictures文件夹中
问题是它应该在imageview调用mImageView中显示图像,但它不是
mImageView已经有了一个位图。它应该更改为新图像,而是保持原样
ouputFileURI报告正确的路径和文件名,但我无法使其工作
有什么想法吗?
标记
答案 0 :(得分:0)
由于您明确指定文件名存储图像的位置,因此您应该从该文件中读取Bitmap
而不是从Intent
加载它。听起来data.getExtras().get("data");
正在返回null
。