Hi everyone
I am currently trying to render an icon ; here is my code :
ByteBuffer[] buffArray = new ByteBuffer[3];
buffArray[0] = LoaderUtils.toByteBuffer("icon32PNG");
buffArray[1] = LoaderUtils.loadIcon("icon64PNG");
buffArray[2] = LoaderUtils.loadIcon("icon256PNG");
Display.setIcon(buffArray);
// LoaderUtils
public static ByteBuffer toByteBuffer(String fileName) throws IOException {
File file = new File("res/"+fileName+".png");
FileDataSource fsource = new FileDataSource(file);
InputStream stream = fsource.getInputStream();
BufferedImage img = ImageIO.read(stream);
final int w = img.getWidth();
final int h = img.getHeight();
byte rgbData[] = new byte[w * h];
for (int i = 0; i < rgbData.length; i++) {
int x = i % w;
int y = h - 1 - i / w;
rgbData = (byte) img.getRGB(x, y);
}
ByteBuffer buffer = BufferUtils.createByteBuffer(w * h);
buffer.put(rgbData);
buffer.flip();
stream.close();
return buffer;
}
The icon changed, but looks very awful. I checked other forums, and I think the problem is that the image need to be in a .rgba format. The problem is that my method toByteBuffer do not recognize the rgba file as an image, so it does not work. Do you have any idea how I can fix that ? Maybe it is simple but I don't master the out/in object a lot, so please be gentle
Kind regards,
Askigh