Skip to main content

SVG Image Element, file referencing issues??

3 replies [Last post]
mrtim
Offline
Joined: 2009-03-26
Points: 0

Hi Guys.

I am having a problem trying to reference a PNG/JPG file in an SVG file while using NetBeans/J2ME as an IDE.

Firstly i am unsure if i have to reference the file absolutly eg. root1/filename.png, if this is the case, what is the actual root of the phone (i am developing for an N95)

currently my SVG Image element looks like this

although each time i try to run the app i get this error

getExternalImage(), Image href = test.png
java.lang.IllegalArgumentException: no ':' in URL
at javax.microedition.io.Connector.openPrim(Connector.java:270)
at javax.microedition.io.Connector.open(Connector.java:222)
at javax.microedition.io.Connector.open(Connector.java:198)
at javax.microedition.io.Connector.open(Connector.java:180)
at com.sun.perseus.j2d.ImageLoaderUtil.getExternalImage(ImageLoaderUtil.java:111)
at com.sun.perseus.model.DefaultImageLoader$ImageLoadRunnable.run(DefaultImageLoader.java:325)
at com.sun.perseus.util.RunnableQueue.run(RunnableQueue.java:254)
returning broken image

i have placed the PNG at every level of my project file system, but with little success. Is there somthing i am doing wrong with the xlink:href, i have also tried to access the PNG in the following ways:

file:///root1/test.png
file:test.png
file///test.png
file:///C:/test.png

and varius other ways.

Plz Plz Plz help, this is a final year uni project and i am getting very close to the dead
line.

Mny thx

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
furius
Offline
Joined: 2009-06-16
Points: 0

Hi , it seems we have the same problem on our final uni project midlets ;-)

Did you manage to solve this issue?

If it's possible, I think it would be better not to use java code in order to embed an external image and leave the job to the SVG engine instead of make through java code; as you I've tried lots of possibilities to embed a png image (I'm using netbeans, but even in the image preview, I got only a sad grey rect ).
The only thing I found that it seems to be an improvement in solving that problem is that if
you make the xlink:href attribute like this:

xlink:href="file://////root1://image_path_of_png.yourImage.png"

at runtime gives you a"root not accessible " message.

I hope this may help you , as I hope you could give any hints about this issue, I will appreciate a lot .

Thanks, Vincent

eva_krejcirova
Offline
Joined: 2008-05-05
Points: 0

Hi,

You can write your own external resource handler and pass it to createImage method.

It will look something like this:
[code]
class ImageHandler implements ExternalResourceHandler {
public void requestResource(final ScalableImage scalableImage,
final String URI) {
System.out.println("request Resource " + URI);
final InputStream inputStream = ImageDemo.class.getResourceAsStream(URI);

if (inputStream == null) {
System.out.println("Failed to load " + URI + "!");
}

try {
scalableImage.requestCompleted(URI, inputStream);
} catch (final IOException e) {
e.printStackTrace();
}
}
}

SVGImage svgImage = (SVGImage)SVGImage.createImage(svgInputStream, new ImageHandler());

[/code]
(This particular code fragment loads images from jar file, so you would need to have the png file in the jar file to use it exactly like this.)

davjoh
Offline
Joined: 2007-07-18
Points: 0

The key problem highlighted is:

java.lang.IllegalArgumentException: no ':' in URL

I don't see why you should get the _every_ time because you say you tried...

file:///root1/test.png
file:test.png
file///test.png
file:///C:/test.png

Your 3rd case has no ':' character in the URL, so there's no reason that should throw up that exception. Looking at them, cases 1 and 4 should be valid.