Accname
2D-Graphics enthusiast
- Reaction score
- 1,462
Hi, i am currently trying to use OpenGL with lwjgl in java.
My current problem is to set the icon used by the display (that one in the upper left corner on windows).
The function takes a ByteBuffer array, but i want to use png-files i have on the harddrive as images.
So, after a little bit of google search i came up with the following code:
ICON_PATHS is a String array containing 3 strings for 3 different png-files with sizes 16x16, 32x32 and 128x128 as the java.doc for Display.setIcon(...) specifies i need at least these 3.
The problem is, it doesnt quite work correctly.
Fact is, i get something to be displayed, but definitely not the icon i wanted to have. It seems to be like random colors.
If i try to use different png-files (with the same dimensions) it doesnt work at all.
Can somebody help me?
Edit: No exceptions or errors are thrown, it just doesnt display the images correctly or (if i use other files) does not take them at all.
My current problem is to set the icon used by the display (that one in the upper left corner on windows).
The function takes a ByteBuffer array, but i want to use png-files i have on the harddrive as images.
So, after a little bit of google search i came up with the following code:
Code:
ByteBuffer[] icon_array = new ByteBuffer[ICON_PATHS.length];
try {
for (int i = 0; i < ICON_PATHS.length; i++){
icon_array[i] = ByteBuffer.allocateDirect(1);
String path = ICON_PATHS[i];
File icon_file = new File(path);
BufferedImage bufferedImage = ImageIO.read(icon_file);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", byteArrayOutputStream);
byte[] imageData = byteArrayOutputStream.toByteArray();
icon_array[i] = ByteBuffer.wrap(imageData);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Display.setIcon(icon_array);
The problem is, it doesnt quite work correctly.
Fact is, i get something to be displayed, but definitely not the icon i wanted to have. It seems to be like random colors.
If i try to use different png-files (with the same dimensions) it doesnt work at all.
Can somebody help me?
Edit: No exceptions or errors are thrown, it just doesnt display the images correctly or (if i use other files) does not take them at all.