【发布时间】:2018-08-04 10:05:21
【问题描述】:
我正在使用 Android 上的 Kotlin 将应用程序数据文件夹中的图像加载到 ImageView 中。使用 Picasso 加载图像,但加载过程不起作用。
路径是:
file:///data/user/0/at.guger.speiseplan/files/KW9.jpg
我试过了:
Picasso.with(this).load(file.absolutePath).fit().into(imvMenu)
Picasso.with(this).load("file://" + file.absolutePath).fit().into(imvMenu)
而file是通过以下方法生成的:
private val sMenuFileName: String = "KW%d.jpg"
fun getMenuFile(): File {
return mContext.getFileStreamPath(String.format(sMenuFileName, Utils.getWeekOfYear()))
}
该文件确实存在,因为加载到 WebView 中有效:
String sHTML = "<html><head><meta charset=\"utf-8\"><style type=\"text/css\">body{padding: 0; margin: 0;}</style></head><body><img src=\"" + "file://" + file.toString() + "\" width=\"100%\"></body></html>";
mWebView.loadDataWithBaseURL("http://schuelerwohnheim-steyr.com", sHTML, "text/html", "utf-8", "");
而且使用BitmapFactory加载图片也可以,为什么毕加索不加载图片呢?
imvMenu.setImageBitmap(BitmapFactory.decodeFile(file.absolutePath))
【问题讨论】: