由于位图 Uri 错误,解决 Uri 失败
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您从 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.