|
Author |
Topic: Read files outside the sketch/data folder (Read 463 times) |
|
mkn
|
Read files outside the sketch/data folder
« on: Dec 11th, 2004, 6:48pm » |
|
Hi all, How do I access files outside the data folder? I'm aware that applets needs signing, but it should work when running the programs inside Processing, right? I've managed to access subfolders within the data folder, but finding the way out to for example the root of disk d: seems problematic. Thanks in advance! Mkn.
|
Bork bork bork
|
|
|
mkn
|
Re: Read files outside the sketch/data folder
« Reply #1 on: Dec 12th, 2004, 7:08pm » |
|
One reason that I want to get out of the sketch folder is that I've got some amount of media stored elsewhere on disk that I want to access when trying out stuff in Processing, without necessarily having to make a multitude of copies in every sketches data folder. Yours all! Mkn.
|
Bork bork bork
|
|
|
mkn
|
Re: Read files outside the sketch/data folder
« Reply #3 on: Dec 13th, 2004, 11:03am » |
|
Thanks, I've read the posts, but I still cant get reading images on hard disk outside the processing environment to work. For example: Code: BImage testImg; testImg = loadImage("d:/test.jpg"); |
| So I figured that maybe loadImage has to have relative paths finding their way out of the sketch/data folder, but no matter what combinations of "..":s, "/":s or "\":s, still no go.
|
Bork bork bork
|
|
|
st33d
|
Re: Read files outside the sketch/data folder
« Reply #4 on: Dec 13th, 2004, 7:32pm » |
|
Whoops, you're right. That's bloody annoying really. It works fine with loadStrings, I can even download a html off of the web into a string but I can't even go through a shortcut folder to a different drive to load an image (which I thought should work seeing as in Linux, folder location on a drive is shown to be an abstraction). Tried the Java method of importing an image but it's not compatible with BImage and BImage overides any reference to Java's Image. Makes life a bit poo really.
|
I could murder a pint.
|
|
|
fjen
|
Re: Read files outside the sketch/data folder
« Reply #5 on: Dec 14th, 2004, 12:03am » |
|
Code: // -- file ImageLoader.java -- goes into sketch's code-folder // fjenett, 2004, www.florianjenett.de import java.awt.*; import java.net.*; public class ImageLoader { BApplet parent; ImageLoader ( BApplet _ba ) { this.parent = _ba; } Image loadImage ( String image_file ) { try{ MediaTracker tracker = new MediaTracker(this.parent); URL imgURL = new URL(image_file); Image img = null; if ( !this.parent.online() ) img = Toolkit.getDefaultToolkit().getImage( imgURL ); else this.parent.getImage( imgURL ); tracker.addImage(img, 0); tracker.waitForAll(); return img; } catch (Exception e) { System.out.println("Error: "+e.toString()); } return null; } } |
| Code: // testsketch ... BImage urlImage; ImageLoader il; void setup() { size(200,200); il = new ImageLoader( this ); } void loop() { if (urlImage == null) { //urlImage = new BImage( il.loadImage("file:/Users/fjenett/Desktop/amazonHTML.gif") ); urlImage = new BImage( il.loadImage("http://processing.org/images/processing.gif") ); if (urlImage != null) image(urlImage, 0,0); } } |
| it's not as direct as BImage() but it works outside the sketchfolder ... i know there are better ways to do this, but i had this already sitting in my sketchbook ... make sure to check the BImage agains null (your_bimage != null) before using it! /F
|
|
|
|
|