Creating a picture from BufferedImage flips my image

I needed to draw a BufferedImage into the GUI, so I implemented this code to convert the BufferedImage into a picture, maybe it is not the best way but this is the way I found, it works ok except that the image drawed is flipped, the top part of the image is at the bottom of the screen, in my code I saved the BufferedImage and it is correct, so I did something wrong while the conversion to a picture:

[java]public void drawTextureIntoGUINode(TextureInfoSubFile textureSubFile,IffFile iffFile) throws IOException{

	//the only way to create a picture froma BufferedImage that i found was this
	//BufferedImage->convertToAwt->with the ByteBuffer create an image->texture2d->picture
	
	BufferedImage bufImage=IffUtils.createBufferedImageForPreview(textureSubFile, iffFile);
	File imageFile= new File("c:\\users\\jorge\\desktop\\prueba.png");
	ImageIO.write(bufImage, "png",imageFile);
	ByteBuffer imageByteBuffer =ByteBuffer.allocateDirect(bufImage.getHeight()*bufImage.getWidth()*4);
	ImageToAwt.convert(bufImage,Format.ABGR8,imageByteBuffer);
	Image jme3Image= new Image();
	jme3Image.setData(imageByteBuffer);
	jme3Image.setFormat(Format.ABGR8);
	jme3Image.setHeight(bufImage.getHeight());
	jme3Image.setWidth(bufImage.getWidth());
	
	
	Texture2D texture2D= new Texture2D(jme3Image);
	
	Picture pic = new Picture("TexturePicture");
	pic.setTexture(assetManager, texture2D, true);
	pic.setWidth(settings.getWidth());
	pic.setHeight(settings.getHeight());
	pic.setPosition(0,0);
	guiNode.attachChild(pic);
}[/java]

JME3 textures have their Y-coordinates flipped by default, so it’s likely you haven’t done anything wrong.

1 Like

http://hub.jmonkeyengine.org/javadoc/com/jme3/texture/plugins/AWTLoader.html#load(java.awt.image.BufferedImage,%20boolean)

1 Like