2017년 3월 27일 월요일

How to to display an image referring to a file name on the SD card?


AI2 supports displaying an image, but the image's file name has to be in the appinventor's "asset" folder of the phone. It seems not possible to specify an image file name from i.e. the sd card of the phone (I tried specifying a folder path in the "Image's Picture" property without success).

I have hundreds of picture files to upload to my app, which is really cumbersome with AI2 since one must do it one by one, not mentioning the limit in size of the "Asset" folder   :(

Could we had the feature of specifying an image file name like "/externalsd/image1.jpg" in the "Image's Picture" property directly?

--
yes you can, see Accessing Images and Sounds
file:///mnt/sdcard/image1.jpg should do it

-- 
Thanks for the prompt reply  :)


And thanks for the link; I did not know that nice piece of documentation and the URL approach ... that should be added to the documentation offered directly from AI2's Designer for the "file" component (see "Storage - App Inventor for Android" at http://ai2.appinventor.mit.edu/reference/components/storage.html#File).

Having said that, I have tried it without success. I have attached a screen shot with little explanation for your review, please.

Note: just to make sure, we both speak of the same thing, I mean, the "Image" component, right?

Let me know.


--
you should use file:///mnt/sdcard/Eric/PicDVDlist/301.jpg instead

--
None of the folders "/mnt/sdcard/" exist on my Galaxy S2 (from Samsung / T-Mobile). When I connect my phone to my computer, I can see the folder "external_sd", but no "mnt" or "sdcard" is visible.

Nevertheless, I tried to rename "external_sd" into i.e. "sdcard", but Android (4.0.4) will not let me change it. So, I tried exactly "file:///mnt/sdcard/Eric/PicDVDlist/301.jpg" ... and got nothing  :(

Any other idea?

Note: my testing is performed with AI companion under WIFI.

--
are there 2 sdcards on your device?
file:///mnt/sdcard is a generic path to your sdcard which is also valid for emulated sdcards


you can test with the file component to store a text file in the root directory of the accessible sdcard, just use the File.SaveFile block together with /myFile.txt to find it out
you only an read from/write to that sdcard using App Inventor... (EDIT: this is not correct, see SteveJG's test below)

--
There's only one SD slot.

I have performed the test you suggested (thanks) and found the file ... directly at the top of the phone's RAM instead of the SD card. Just to make sure, I have removed the SD card and have verified on my computer that the new file I had created with AI2 was not there in any way.

Note: I have attached 2 screen shots to show you what I see on my phone screen when launching Android's standard Files app.




--
.. and here is the AI command:


--
so if you store image 301.jpg in directory Eric/PicDVDlist there, you can access images from that directory like this file:///mnt/sdcard/Eric/PicDVDlist/301.jpg

-- 
This works on my Samsung Tab II external sd card:

file:///storage/extSdCard/DCIM/Camera/20120905_090759.jpg       while  file:///mnt/sdcard/DCIM/Camera/20120905_090759.jpg  gets nothing     and  file:///mnt/extSdCard/DCIM/Camera/20120905_090759.jpg
also provides the correct image.

--
ok, I didn't know that this is possible... thank you SteveJG...


which means, if you use your app only for you, you should be able to read an image from your external sd card, as SteveJG demonstrated...
however if you like also other people to use your app, you should use the generic path file:///mnt/sdcard and your default sdcard to store the images
because that generic path file:///mnt/sdcard also works for emulated sdcards (as in my Nexus 5)

@SteveJG: can the file component read from / write to your external sdcard?

-- 
@Taifun    It seems it is possible to read an image into an image control when you have an external SDcard... either of these two work:


file:///storage/extSdCard/DCIM/Camera/20120905_090759.jpg 

file:///mnt/extSdCard/DCIM/Camera/20120905_090759.jpg  retrieve an image on my Samsung Tab II.

and something like this would retrieve from my emulated sdCard within the Tab II file:///mnt/sdcard/DCIM/Camera/20120905_090759.jpg  would work if the rest of the directory existed.

However,  I can not access extSdCard to create any files with   call Canvas.SaveAs filename  with similar code.  I can save on the emulated SDcard but cannot SAVE an image on the external SD  .  I tried to use both existing and created directories.  Nothing.

I can not access the external card with the File control at all .  When I use similar code to what allows me to retrieve a jpg to the image control, I get error messages that the File contoul could not read the EMULATED SD card... so File seems to work only with an internal or emulated internal SD card.

There are a lot of inconsistencies among the various AI controls that write (or read) files; among those is the Camera control .

Is this what you are seeing too?

@ Eric ... can you now read an image from your external SD card?

--
Is this what you are seeing too?
yes, I think this is correct
all components, which expect a full path (starting with file:///), can read/write to both
all other components can't

-- 
To answer Taifun's question about storing 301.jpg and accessing it with the "Image" component:
(as opposed to what the "File" component can do)


- I could not read 301.jpg from the SD card using "file:///mnt/sdcard/Eric/PicDVDlist/301.jpg".
- I could not read it from the sd card using my phone's folder path "file:///mnt/external_sd/Eric/PicDVDlist/301.jpg".
- I could not read it from the sd card using directly "/external_sd/Eric/PicDVDlist/301.jpg"  (the "File" component can do it!).
- I could not read it directly from the "/" root folder of the phone's memory using "/301.jpg"  (the "File" component can do it!). 
- Of course, no issue reading it from AI's "Asset" folder using "//301.jpg".

In short, no mean to retrieve an image from elsewhere than the "Asset" folder when using the "Image" component  :(

To answer Steve's question about if I can read an image from my external SD card:
- Yes, I can using the "File" component.
- No, I cannot using the "Image" component.

Quick questions to Steve:
- In your two examples "file:///storage/extSdCard/" and "file:///mnt/extSdCard/, are the "storage", "extSdCard" and "mnt" folders visible in your phone using the Android standard "Files" app?
- What is an "emulated" SD card?
- Is an "emulated" SD card visible in the Android standard "Files" the same way the actual SD card is?
- BTW, Is the "File" component what you refer to as "File control"?

--
In short, no mean to retrieve an image from elsewhere than the "Asset" folder when using the "Image" component  :(
it seems to be, you still didn''t get it
if you store an image with the name 301.jpg in the root directory here
you can access it with the image component like this
file:///mnt/sdcard/301.jpg
also you can use subfolders there...


-- 
@Eric   you should be able to    set image1.Picture to file:///mnt/external_sd/Eric/PicDVDlist/301.jpg
if that does not work try set image1.Picture to file:///storage/external_sd/Eric/PicDVDlist/301.jpg

what address depends on where your File app (not the AI2 control) indicates in the path to 301.jpg


In my example with my Samsung Tab II, both of these work  set Image1.Picture to  file:///storage/extSdCard/   and the appropriate directories 
                                                          set Image1.Picture to  file:///mnt/extSdCard/   and the appropriate directories.
 "extSdCard" is the actual name of my external SDcard.  It appears you exeternal   is called   external_sd  ???   be careful, Android is very strict about cas and make sure your director is not perhaps  exernal_Sd or something else.

Only the /storage/extSdCard/ folder is visible using a File app (this is NOT the control in AI).  The "mnt" folder is NOT  visible in your phonebecause it is a generic addressing method that is supposed to find the sdCard 

Taifun answered the other questions.   Yes, an "emulated" is found the same way using the File app. On my Tablet, what is emulated is the SdCard ...not the external one. :)

To avoid confusion, the Fle component is the AI2 control used to read/write text files (it does not work with images).     AI does not have a control that allows a user to examine the contents of an Android folder.  You can do that with an external program on your phone that might be called   File ...that lets you examine the contents of folders on you phone and shows the full path to all files on your phone.  No control on AI can do that.   What Taifun and I were talking about is the AI2 File control;  we decided that AI2's File can not read or write to an EXTERNAL sd card.

To make sure we are talking about the same thing, my Tablet has a slot on the side for a micro Sd card..most users do not use one;  I do and that is what I mean by external sd card.

Hope this helps.

--
New input, new testing, new POSITIVE answers :)

Steve, I already had tried unsuccessfully your "file:///mnt/external_sd/Eric/PicDVDlist/301.jpg".
I now have tried your new suggestion (thanks), but still unsuccessfully "file:///storage/external_sd/Eric/PicDVDlist/301.jpg".

I also had tried unsuccessfully Taifun's previous suggestion "file:///mnt/sdcard/Eric/PicDVDlist/301.jpg".
I also had tried unsuccessfully "file:///mnt/external_sd/Eric/PicDVDlist/301.jpg".

Taifun, I have tried SUCCESSFULLY your new suggestion "file:///mnt/sdcard/301.jpg" (image in the root directory of the phone's RAM).
I also have successfully tried "file:///mnt/sdcard/external_sd/Eric/PicDVDlist/301.jpg" (image in the SD card).

In short: the "Image" component has access to the whole phone and SD card memory using "file:///mnt/sdcard/".

What was misleading, or at least confusing, was that the path "///mnt/sdcard/" does not lead to the SD card but to the root directory of the phone!!

Is there anything to change in AI2 with regards to this phone behavior? Meaning, "///mnt/sdcard/" seems not doing what it is expected to, which is to access the SD card,right? And the "File" component does not access the SD card either but the root of the phone memory when using "/"...

Thanks Steve for your long explanation, and thanks Taifun for your last tips. BTW,

--

댓글 없음:

댓글 쓰기