如何使用Picasso从本地计算机获取图像,然后用Java将其显示在Android应用中。

huangapple go评论58阅读模式
英文:

How to fetch image from local computer with Picasso then display it to android app with Java

问题

这行代码可以正常工作

Picasso.with(context).load("https://www.simplifiedcoding.net/wp-content/uploads/2015/10/advertise.png").into(holder.imageView);

这行代码无法正常工作

Picasso.with(context).load("/Users/jz/Desktop/Pictures/kigali.png").into(holder.imageView);

我该如何解决这个问题?
是文件权限问题吗?

英文:

This line of code works

Picasso.with(context).load("https://www.simplifiedcoding.net/wp-content/uploads/2015/10/advertise.png").into(holder.imageView);

This line of code doesn't work

Picasso.with(context).load("/Users/jz/Desktop/Pictures/kigali.png").into(holder.imageView);

How can is solve the issue ?
is it my file permission ?

答案1

得分: 3

这样做不起作用。您的计算机对于您的Android设备来说不是本地的 - 即使在模拟器上运行您的应用程序,该模拟器在计算机上运行的虚拟机,因此在此上下文中需要被视为独立设备。要使计算机上的任何文件可用,您需要使用任何服务器(如apach、nginx),并使计算机能够从网络访问(可能仅为本地)。然后,您可以使用网络访问这些文件,例如通过与您已有的相同类型的 http:// 请求。

英文:

This won't work. Your computer is NOT local for your Android - even if you run your app on emulator running on that computer as it runs virtual machine thus needs to be considered separate device in this context. To make any file from your machine available you need any server (like apach, nginx) and make your computer reachable from the network (can be local only). Then you can reach these files using network i. e. via same type of http:// request you already have.

答案2

得分: 0

如果您想在应用程序中使用图像或图标,您可以将其放入资产文件夹并按以下方式使用:

Picasso.with(context).load(R.drawable.icon_main_page).into(holder.imageView)
英文:

if you want to use image or icon inside app you can put it into assets folder and use like this

Picasso.with(context).load(R.drowable.icon_main_page).into(holder.imageView)

huangapple
  • 本文由 发表于 2020年9月25日 15:10:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/64059449.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定