We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi. I am trying to load an image with the code below, but this will give the error:
The method loadImage(String) in the type PApplet is not applicable for the arguments (File) >
How to do this? Thanks.
import android.os.Environment;
PImage img;
File f;
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/imgFolder";
String fileName = "noel_28_5_2018_9_9.png";
f = new File(baseDir + "/" + fileName);
img = loadImage(f);
Answers
f.getAbsolutePath(); //Untested
but it should work. Don't forget to enable the relevant permission.Consider moving to the new forum.
@akenaton I hope to see ya in the "nouveau" forum as well.
Kf
@kfrajer Thanks for the hint. My next question wll be on the new forum. As for this topic, I do not understand what you mean. If I use a println(f); It gives the exact location: /storage/emulated/0/imgFolder/noel_28_5_2018_9_9.png. The sketch does not give any errors when out-commented the loadImage(f);.
When you use print, it is very likely the print function is invoking the
toString()
method associated to the Objec class. In turned, this function overriden by the File class. I am not totally sureloadImage()
can handle objects of type File. Generating the proper string path should work.Kf
@noel===
with P5 loadimage() waits for a String and with your code you give it a File object: that is the problem...Where is your imgFolder???? in your app??? on the sdCard???
@kfrajer === i am on the new forum where i put a post for a weird problem i got with standard processing (no android)...Still unsolved; must be a processing bug : if you get some idea, it s in the "uncategorized" category!
EDIT: no it migrates here https://discourse.processing.org/t/strange-results-when-exporting/288
@akenaton. Yes of course you are wright. It was just a hopeless try. Because using a String like
gives the error:
On the other hand saving a file to the internal storage, not specifically the sketch folder, works pretty well. I have tried a lot of other things but they are to foolish to be posted. I hope you have some idea, because I already have a headache.
@noel===
i ll post some snippet tomorrow here.
Thanks!
Thanks!
Check these:
https://forum.processing.org/two/discussion/comment/118947/#Comment_118947
https://forum.processing.org/two/discussion/comment/120203/#Comment_120203
Also
https://github.com/processing/processing-android/issues/450
Kf
@kfrajer @akenaton
Afterall so simple. Thanks!
Great, thxs for sharing your solution. To clarify on your approach, do you create the
imgFolder
ahead of time? Sorry, I would test it myself but I don't have resources setup atm.Kf
@kfrajer Yes with this code I verify and create a new directory.if necessary
@noel Thxs for sharing your full solution.
@akenaton: For that bug, it seems one needs to dig into the source code. I give it a try tomorrow or Thursday.
Kf