在 Android 应用程序中从计算机显示真实设备中的图像
我想将图像从系统的外部文件夹加载到我的 Android 应用程序中。我使用以下代码,但图像未显示。当我调试它时,位图对象“bitmap”显示为空。我该如何解决这个问题?
ImageView img=(ImageView)findViewById(R.id.myImage);
String fname="C:/Users/Public/Pictures/Garden.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(fname);
img.setImageBitmap(bitmap);
我的实际需求是我的 andorid 应用程序(在真实设备上)应该显示一些存储在一台计算机中的图像。该应用程序的管理员会将一些图像上传到该计算机中的特定文件夹。 Android应用程序将使用IP地址访问这些图像,并显示这些图像。如果这些图像应该被推送到SD卡路径,那么我该如何在运行时做到这一点?
请帮助我。
谢谢大家。
I want to load an image from an external folder of my system to my android application. I use the following code, but the image is not displaying. When I debugged it, the Bitmap object 'bitmap' is shown as null. How can I solve this problem?
ImageView img=(ImageView)findViewById(R.id.myImage);
String fname="C:/Users/Public/Pictures/Garden.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(fname);
img.setImageBitmap(bitmap);
My actual need is my andorid application (on real device) should display some images which is stored into one computer. The admin of this application will upload some images to a specific folder in that computer. And the android application will access these images using IP address, and will display these images. If these images should be pushed to sdcard path, then how can i do it at runtime?
Please help me..
Thank you to all..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“外部文件夹”?那是什么? Android 只能访问其内部文件系统(即内部存储、SD 卡以及您可能通过 Linux 操作系统安装的任何其他内容)。使用 Windows 路径绝对行不通。这些数据应该来自哪里?
您需要使用正确的 UNIX 样式路径,该路径要么指向手机的内部存储,要么指向 SD 卡,并且该路径需要可由您的应用程序访问。
An "external folder"? What is that? Android only has access to its internal file system (i.e. the internal storage, and the SD card, and whatever else you may have mounted via the Linux operating system). Using a Windows path is definitely never going to work. Where is that data supposed to be coming from?
You need to use a proper UNIX-style path that either points to the phone's internal storage, or the SD card, and the path needs to be accessible by your application.
您无法访问您的系统文件。检查此链接
如果您尝试访问 SD 卡,可以使用以下命令
You cannot access you system file. Check this link
If you are trying to access SDcard you can use the following
您无法从 Android(模拟器或手机)访问计算机上的文件。您必须将您的应用程序视为独立于其他应用程序运行。
如果您确实不想将图像放在android的drawable文件夹中(并使用R.drawable.imagename访问它,那么您需要将图像推送到手机/模拟器的sdcard上,并使用sdcard路径打开它
You can't access files that are on your computer from android (emulator or phone). you have to consider your application as running independently from the rest.
if you really don't want to place your image inside the drawable folder of android (and access it using R.drawable.imagename then you need to push your image onto the sdcard of your phone/emulator and open it using the sdcard path