【问题标题】:android Camera picture not being displayedandroid相机图片不显示
【发布时间】:2014-09-07 16:08:40
【问题描述】:

以下是我的相机代码

 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);            
     }}}

当调用它时,相机应用程序会拍摄一张照片并将其存储在带有预定义文件名的图片文件夹中

问题是它应该在 imageview 调用 mImageView 中显示图像,但它没有

mImageView 中已经有一个位图。它应该更改为新图像,但保持原样

ouputFileURI 报告了正确的路径和文件名,但我无法让它工作

有什么想法吗?

标记

【问题讨论】:

标签: android bitmap camera


【解决方案1】:

由于您明确给出了存储图像的文件名,因此您应该从该文件中读取Bitmap,而不是从Intent 中加载它。听起来data.getExtras().get("data"); 正在返回null

【讨论】:

  • 感谢这个抱歉的新手,知道我会怎么做吗?
  • @user3422687 您是否阅读了我在评论中对您的问题提供的链接?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-25
  • 1970-01-01
相关资源
最近更新 更多