Re: Parsing module resource image to Java Awt Image

45 views
Skip to first unread message
Message has been deleted

Colin Bartolome

unread,
Feb 3, 2017, 3:13:42 PM2/3/17
to ceylon-users
I had a similar issue in an earlier discussion, "What's the best way to handle embedding an image as a resource in a module?" I was able to work around the issue by skipping Ceylon's resource code for now and relying on Java's resource code:

value resource = javaClassFromInstance(game.board).getResourceAsStream(name);

if (exists resource) {
   
return ImageIO.read(resource);
}

Ceylon's resource code doesn't currently let you get at the raw bytes or stream, I think, and the URI when running on the JVM starts with "classpath:/", which needs some special handling.

On Friday, February 3, 2017 at 9:09:14 AM UTC-8, Wojciech Potiopa wrote:


Hello, i am trying to do the thing as in title. I put image resource image in resource resource/com/module/name/image.png. It is on class path.
i do the:
 assert (exists image = `module`.resourceByPath("image.png"));

I convert it to ceylon.URI

and then im stuck
I have tried using ImageIO to convert java.File into Image but it fils
value imageUri = URI(image.uri);
value file
= File(imageUri.path);
file
.setReadable(true);
value read
= ImageIO.read(file);
It fails with
java.lang.RuntimeException: javax.imageio.IIOException: Can't read input file

Then i tried to use  it as a ceylon.File readBytes and so on
but it fails on assertation

assert(is File file=parsePath(imageUri.path).resource.linkedResource);
It is Nill instance and not the ceylon.File.

i made a simple test if text file will be parsed from this location and it is.

assert (exists text= `module`.resourceByPath("test.txt"));
String textContent = text.textContent();
assert(textContent=="asdasdasdasdad");

How should i handle this ?

Tako Schotanus

unread,
Feb 3, 2017, 3:27:34 PM2/3/17
to ceylon-users
Colin's suggestion is indeed the best way for now.

We need and want a way to support access to raw binary data natively from Ceylon of course but we haven't decided yet what that API would look like exactly.


-Tako

--
You received this message because you are subscribed to the Google Groups "ceylon-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-users+unsubscribe@googlegroups.com.
To post to this group, send email to ceylon...@googlegroups.com.
Visit this group at https://groups.google.com/group/ceylon-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceylon-users/5be32ec1-88f0-49d9-913f-2c17fd1e3e33%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages