【问题标题】:Resolve Uri failed on bad bitmap UriResolve Uri failed on bad bitmap Uri
【发布时间】:2011-12-12 05:05:20
【问题描述】:

我是 Android 开发新手。

请帮助我解决以下问题。当我尝试使用该函数更新小部件时,我在 Logcat 上收到错误“system.out - resolveuri failed on bad bitmap uri”,

 remoteViews.setImageViewUri(R.id.clockview, buildUpdate("CURRENTTIME", c));    
    awm.updateAppWidget(awID, remoteViews);

我附上我的代码:-

    public Uri buildUpdate(String time, Context context) {


        date = new Date();
        sec = (float) date.getSeconds();
        min = (float) date.getMinutes();
        hour = (float) date.getHours() + min / 60.0f;
        bitmap = Bitmap.createBitmap(200, 200, Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setColor(0xFFFF0000);
        p.setStrokeWidth(2);
        canvas.drawLine(
                x,
                y,
                (float) (x + (r - 15)
                        * Math.cos(Math
                                .toRadians((hour / 12.0f * 360.0f) - 90f))),
                (float) (y + (r - 10)
                        * Math.sin(Math
                                .toRadians((hour / 12.0f * 360.0f) - 90f))), p);
...
...
 OutputStream outStream = null;
        File file = new File("data/clockbitmap.PNG");
    try {
        outStream = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
        outStream.flush();
        outStream.close();
     }
     catch(Exception e)
       {}
       uri = Uri.parse(file.getAbsolutePath());

        Log.d("File","filename "+file);
        Log.d("here", "Does this exist? " + String.valueOf
                (file.exists()));
        Log.d("here",uri.getPath());
    return uri;

}

请帮我解决这个问题。!!!!!! :(

【问题讨论】:

  • 顺便说一句,buildUpdate() 方法名不是很好......

标签: android bitmap uri


【解决方案1】:

当您从 sd 卡读取文件时,路径可以指定为“file:///(绝对路径。)”

我觉得这会解决 URI 解析问题。

【讨论】:

  • 我使用了这个代码。 String extStorageDirectory = Environment.getExternalStorageDirectory().getAbsolutePath().toString();文件 file = new File(extStorageDirectory, "clockbitmap.PNG");
猜你喜欢
  • 1970-01-01
  • 2017-12-18
  • 2019-09-05
  • 2020-06-11
  • 1970-01-01
  • 1970-01-01
  • 2012-02-09
  • 1970-01-01
相关资源
最近更新 更多