#996 Image Scaling

jerlin Mon 1 Mar 2010

Hi, I am trying fan coding and have a rather simple doubt. I have an instance of "Image". I've called resize on it to resize it.. Now how do I write it back to a file?

Also, Whenever I try to use ImageIO.read(File), using java FFI, it seems to hang, any clues on why this could happen?

thanks, Jerlin

brian Mon 1 Mar 2010

Now how do I write it back to a file?

There are currently no encoders to write an image from memory back to a PNG or JPEG file.

Also, Whenever I try to use ImageIO.read(File), using java FFI, it seems to hang, any clues on why this could happen?

You can post a stack trace which might show what is going on. But I don't think Java's ImageIO can work with SWT anyhow.

jerlin Tue 2 Mar 2010

Thanks brian. The bug I've is strange. I've code like this using java FFI to get an instance of BufferedImage

f := File(`/Users/jerlin/Documents/photoshop-images/creative.png`)
BufferedImage image := (BufferedImage) ImageIO.read(Interop.toJava(f.in)); 
echo("done")

Now if the same code is put in main and execute as a fan script, it works fine. However if the same code goes in doGet of wisp servlet, ImageIO.read() hangs indefenitely.. Do you know why this could happen?

Jerlin

brian Tue 2 Mar 2010

Jerlin,

I tried your code in a weblet and didn't see any hang-up. If you can get a thread dump you can post that (or just email me). One thing you might want to make sure is that you don't have any code which might be kicking off the AWT event loop which would cause that thread to hang.

jerlin Tue 2 Mar 2010

Here is trace of the thread that hangs.. Thanks for helping!

Name: ThreadPool-Worker-5 State: RUNNABLE Total blocked: 0 Total waited: 2

Stack trace:

java.lang.ClassLoader$NativeLibrary.load(Native Method)
java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1822)
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1723)
java.lang.Runtime.loadLibrary0(Runtime.java:822)
java.lang.System.loadLibrary(System.java:993)
sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
java.security.AccessController.doPrivileged(Native Method)
java.awt.Toolkit.loadLibraries(Toolkit.java:1509)
java.awt.Toolkit.<clinit>(Toolkit.java:1530)
java.awt.Rectangle.<clinit>(Rectangle.java:93)
javax.imageio.ImageReader.getSourceRegion(ImageReader.java:2544)
com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1315)
com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1579)
javax.imageio.ImageIO.read(ImageIO.java:1400)
javax.imageio.ImageIO.read(ImageIO.java:1322)

jerlin Tue 2 Mar 2010

Ok, I got this fixed by commenting the following lines in fanlaunch

if $darwin; then
  osFlags="-XstartOnFirstThread"
fi

Hope this helps someone facing the same problem in future.

Login or Signup to reply.