毕加索没有从File加载图片

时间:2018-02-24 13:15:04

标签: android kotlin picasso

我在Android上使用Kotlin将应用数据文件夹中的图像加载到ImageView中。要加载图像,请使用Picasso,但加载过程不起作用。

路径是:

  

文件:///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))

1 个答案:

答案 0 :(得分:0)

我自己多次犯了这个错误

更改

Picasso.with(this).load(file.absolutePath).fit().into(imvMenu)
Picasso.with(this).load("file://" + file.absolutePath).fit().into(imvMenu)

Picasso.with(this).load("file://" + “${file.absolutePath}”).fit().into(imvMenu)

如果只是Val或var

absolutePath

然后它会起作用但是因为你有那种想象力。“在那里它需要”$ {}“

相关问题