0

我正在尝试使小部件显示保存在 sdcard 上的图像。到目前为止,我发现了这个:

String imageInSD = String.format("/sdcard/facepalm%d.jpeg", counter%10);    
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
remoteViews.setBitmap(R.id.imageview1, "setImageBitmap", bitmap);
ImageView myImageView = (ImageView)findViewById(R.id.imageview1);
myImageView.setImageBitmap(bitmap);

注释行导致小部件由于某种原因崩溃。我只是想找到一种方法来完成这项工作。

4

2 回答 2

0

尝试无需将图像解码为位图,只需从图像路径获取图像的 URI:

File tempFile = new File(Environment.getExternalStorageDirectory()+"/XX/facepalm%d.jpeg");
Uri  imgUri=Uri.fromFile(tempFile);
ImageView  imageView=(ImageView)findViewById(R.id.imageuri);
imageView.setImageURI(imgUri);
于 2012-07-03T18:57:59.870 回答
0

检查以下代码:

Bitmap bitmap = null;
    Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    if(isSDPresent)
    {
       String pathOfImageInSD = Environment.getExternalStorageDirectory()+"/"+"facepalm.png";
       bitmap = BitmapFactory.decodeFile(pathOfImageInSD);
    }
ImageView myImageView = (ImageView)findViewById(R.id.imageview1);
myImageView.setImageBitmap(bitmap);
于 2012-07-03T18:59:44.100 回答