繁体   English   中英

如何在ImageView中显示捕获的图像?

[英]How to show a captured image in an ImageView?

我正在尝试从相机意图显示捕获的图像,但是当我调用showPhoto方法时,该图像未显示在ImageView中。 没有错误输出到堆栈跟踪,所以我不确定如何调试该问题。

没有人知道不显示捕获图像的方法有什么问题吗?

showPhoto方法如下:

private void showPhoto(Uri photoUri) {
          String filePath = photoUri.getEncodedPath();
          File imageFile = new File(filePath);
          //File imageFile = new File(photoUri.getPath());
          if (imageFile.exists()){
             Drawable oldDrawable = photoImage.getDrawable(); 
             if (oldDrawable != null) { 
                 ((BitmapDrawable)oldDrawable).getBitmap().recycle();
            }
             Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
             BitmapDrawable drawable = new BitmapDrawable(this.getResources(), bitmap);
             photoImage.setScaleType(ImageView.ScaleType.FIT_CENTER);
             photoImage.setImageDrawable(drawable);
          }       
        }

这是我遵循的教程: http : //www.linux.com/learn/tutorials/722038-android-calling-the-camera

我正在测试的设备是JellyBean 4.1 ,这是完整类的链接:

http://hastebin.com/oqokupulol.java

首先使用BitmapOptions.inJustDecodeBounds找出图像的尺寸

通常,Android不会加载大于4000px宽/高的图像

如果发现图像太大,可以使用BitmapOptions.inSampleSize缩小图像,以便Android加载它

实际上,您可以直接使用ImageView.setImageBitmap(Bitmap)代替setImageDrawable

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM