毕加索不会从File加载图片

问题描述 投票:0回答:1

我正在使用Android上的Kotlin将apps数据文件夹中的图像加载到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))
android kotlin picasso
1个回答
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

然后它会工作,但因为你有那种花哨的“。”在那里需要“$ {}”

© www.soinside.com 2019 - 2024. All rights reserved.