This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
coranos's profile picture

How do I read in images.

Started by coranos, 25 September 2012 - 03:38 AM
coranos #1
Posted 25 September 2012 - 05:38 AM
Hi,
So I'm trying to make a computer program that reads in an image, and makes a statue out of woll based on that image. So far, I can get it working outside of computercraft but not inside computercraft.

Is this possible to do? Or will I have to write java code rather than LUA to do it?

The following LUA reads in an image and prints width and height when run in eclipse:

java_awt_image_BufferedImage = luajava.bindClass( "java.awt.image.BufferedImage" );
java_net_URL = luajava.bindClass( "java.net.URL" );
javax_imageio_ImageIO = luajava.bindClass( "javax.imageio.ImageIO" );
java_awt_Color = luajava.bindClass( "java.awt.Color" );
url = luajava.newInstance("java.net.URL", "http://www.minecraft.net/images/char.png" );
image = javax_imageio_ImageIO:read(url);
print("image = " .. image:getWidth() .. "," .. image:getHeight());

but when I run it on a computer, it says in line #1 "attempt to index a null value"
D3matt #2
Posted 25 September 2012 - 06:27 AM
CCLua doesn't allow direct interactions with luajava, AFAIK.
coranos #3
Posted 26 September 2012 - 01:53 PM
Does this mean I have to write my own plugin?
Cranium #4
Posted 26 September 2012 - 04:45 PM
Yep. In this case, you would.
coranos #5
Posted 27 September 2012 - 03:11 AM
Looking at the periperal API, do I really have to create a new 'turtle upgrade ID' just to convert PNGs into RGB or HSV values?
There's no way to expose additional classes (already present in java) withount also adding a peripheral?
That seems kind of excessive.

It'd be literally simpler to do the image conversion in the cloud, and use the http api to do the conversion.