setImageViewUri不显示图片,但显示imageview的背景

时间:2016-02-29 08:25:19

标签: android uri android-imageview android-appwidget

var wt:uint;
var ht:uint ;
var webview:StageWebView ;
var rect:Rectangle;
var url:String;

url = "https://www.youtube.com/watch?v=hFupHx5G44s";

trace(url);

wt = this.stage.stageWidth;
ht = this.stage.stageHeight;

webview = new StageWebView();
rect = new Rectangle(0,300,wt,ht/2);

webview.stage = this.stage;
webview.viewPort = rect;
webview.loadURL(url);

我检查了路径和uri,它是正确的。File file = new File("/storage/emulated/0/BabyCareData/photo/20160229_161413.jpg"); if (file.exists()) { views.setImageViewUri(R.id.imageAvatar, Uri.parse(file.getPath())); } 不显示图片但显示白色屏幕(背景为白色)。

2 个答案:

答案 0 :(得分:1)

试试这个:

File file = new File("/storage/emulated/0/BabyCareData/photo/20160229_161413.jpg");
        if (file.exists()) {
            Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
            views.setImageViewBitmap(R.id.imageAvatar, bitmap);              
        }

答案 1 :(得分:0)

试试这个:

File file = new File(/storage/emulated/0/BabyCareData/photo/20160229_161413.jpg);

if(file.exists())
{

    Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
    setBitmap(views,R.id.imageAvatar,myBitmap);

}

    private void setBitmap(RemoteViews views, int resId, Bitmap bitmap){
        Bitmap proxy = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(proxy);
        c.drawBitmap(bitmap, new Matrix(), null);
        views.setImageViewBitmap(resId, proxy);
    }