makeAwtImage() returns null

why?

as far as i understood, this happens all the time, because it's set to always return null :expressionless:



EDIT:

and if i actually use the source inside jme:

Image image //loaded elsewhere

int type = BufferedImage.TYPE_4BYTE_ABGR; // i tried all types with the same result

BufferedImage img = new BufferedImage(image.getWidth(), image.getHeight(), type);
img.getRaster().setDataElements(0, 0, image.getData());



May 3, 2009 8:39:54 PM com.jmex.game.DefaultUncaughtExceptionHandler uncaughtException
SEVERE: Main game loop broken by uncaught exception
java.lang.ClassCastException: java.util.ArrayList cannot be cast to [B
   at sun.awt.image.ByteInterleavedRaster.setDataElements(Unknown Source)
   at gen.gui.GImage.applyFilter(GImage.java:45)
   at gen.GameMenu.update(GameMenu.java:41)
   at com.jmex.game.state.GameStateNode.update(GameStateNode.java:71)
   at com.jmex.game.StandardGame.update(StandardGame.java:381)
   at com.jmex.game.StandardGame.run(StandardGame.java:250)
   at java.lang.Thread.run(Unknown Source)




hi,



this class needs a byte array intead of an arraylist, see

sun.awt.image: ByteInterleavedRaster.java



(or the cryptic [B in java.lang.ClassCastException: java.util.ArrayList cannot be cast to [B)



why image.getData() is a arraylist, i don't know.



greetz

snare

snareoj2 said:

hi,

this class needs a byte array intead of an arraylist, see
http://www.docjar.com/html/api/sun/awt/image/ByteInterleavedRaster.java.html

(or the cryptic [B in java.lang.ClassCastException: java.util.ArrayList cannot be cast to [B)

why image.getData() is a arraylist, i don't know.

greetz
snare


i already tried using a bytearray but failed ://
really, can anyone manage to get an awt image out of a jme image?
i'm in a great need of this.

doing this:

Format format = Format.RGB8;

ByteBuffer buffer = BufferUtil.newByteBuffer(width * height * 3);
renderer.grabScreenContents(buffer, format, 0, 0, width, height);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
img.getRaster().setDataElements(0, 0, buffer);



results in almost the same thing:


java.lang.ClassCastException: java.nio.DirectByteBuffer cannot be cast to [I
   at sun.awt.image.IntegerInterleavedRaster.setDataElements(Unknown Source)
   at gen.GameMenu.update(GameMenu.java:46)
   at com.jmex.game.state.GameStateNode.update(GameStateNode.java:71)
   at com.jmex.game.StandardGame.update(StandardGame.java:381)
   at com.jmex.game.StandardGame.run(StandardGame.java:250)
   at java.lang.Thread.run(Unknown Source)