由于位图 Uri 错误,解决 Uri 失败

发布于 2024-12-21 04:46:56 字数 1743 浏览 1 评论 0原文

我是 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;

}

请帮助我解决此问题。!!!!! :(

I am new to Android development.

Please help me regarding the following issue. I'm getting the error "system.out - resolveuri failed on bad bitmap uri" on Logcat when I tried to update the widget using the function,

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

I am attaching my code:-

    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;

}

Please help me regarding this.!!!!! :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入怼 2024-12-28 04:46:56

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

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

As you are reading a file from sd card the path can be given as " file:/// (absolute path.)"

I feel this will solve the URI parsing issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文