【问题标题】:Picasso doesn't load image from File毕加索不从文件加载图像
【发布时间】: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))

【问题讨论】:

    标签: android kotlin picasso


    【解决方案1】:

    我自己也犯过很多次这个错误

    改变

    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
    

    那么它会起作用,但既然你有那个花哨的“。”在那里它需要“${}”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-02
      相关资源
      最近更新 更多