From Buffered image to JME picture?

I have some custom graphics that are created dynamically at run time with buffered images. I used the awtloader to load them into a texture.image file

AWTLoader imgLoader = new AWTLoader();
Image load = imgLoader.load(off_Image, true)

I’m stuck at this point. When you create a new JME picture it ask to load the image from a file. However I have the image stored in memory. What would be the best way of converting this over to a JME Picture. I need a Picture type not a texture type. I want to load the image into the guiNode. Thanks for any help.

Look at the ImageToAwt class
I think the convert method is what you are looking for. It converts a ByteBuffer in a JME3 image

What is off_image?

…if it’s a BufferImage then your code should work. Not sure why you are stuck.,%20boolean)

Then take the image and put it into a texture if you want it in a texture.

Completely ignore Picture. It’s a totally useless class that only hides the stuff you actually need to know and exposes everything else you don’t. Just create a quad and put the texture on it.

I’m using an array of the Picture class to store images. However I have a few images that need to be drawn at run time using custom graphics. I can’t get the image to show in the Picture.

BufferedImage off_Image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB);

Graphics2D g2 = off_Image.createGraphics();
g2.setFont(new Font("TimesRoman", Font.PLAIN, 18));
g2.drawString("testing", 500, 500);
AWTLoader imgLoader = new AWTLoader();
imgLoader.load(off_Image, false);
Image load = imgLoader.load(off_Image, true);
Picture test = new Picture("test");
Texture2D testpic;
testpic = new Texture2D();
test.setTexture(assetManager, testpic, true);
test.setPosition(50, 50);

Nothing is rendered. Basically I’m trying to get the image that was drawn into the Picture object. Everything I have is currently based off Picture so I need to either figure this out or rewrite my entire code. I’d rather figure this out.

From memory…

Geometry test = new Geometry("myPic", new Quad(500, 500));
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", new Texture2D(load));
test.setLocalTranslation(50, 50, 0);

‘Picture’ is a total waste of space to me.

Note: your string isn’t even in the image as it’s drawn off the edge.

That’s just pseudo code. The real code looks nothing like that but even if I use 0,0 it still doesn’t work.

If picture is so bad it should be taken out of the JME tutorials. That is where I learned to use it from :stuck_out_tongue:

Ok, I’m not sure how we can debug code we can’t see when we are presented an entirely different kind of buggy code. Seems kind of like a waste of time.

If it were up to me it would be removed completely… but that would probably break quite a few folks.

I do think tutorials shouldn’t use it. As I said, it hides the parts a user should know and exposes a bunch of useless crap that hides what it’s really doing. Personally, I think the Geometry approach is simpler, less code, and teaches you something you can use again and again.