i have an little problem with my painting. I'm load images with following method:
public Image getImage(String name) {
Image image = (Image) this.storage_images.get(name);
if((image == null) && (!name.endsWith("-"))) {
try {
InputStream stream = this.getClass().getResourceAsStream(name);
if(stream != null) {
byte[] image_bytes = new byte[stream.available()];
stream.read(image_bytes);
image = Toolkit.getDefaultToolkit().createImage(image_bytes);
}
} catch (Exception exception) {
System.err.println("Unable to read image from JAR.");
}
if(image == null) {
try {
image = this.client.getImage(this.client.getCodeBase(), name);
} catch (Exception exception) {
System.out.println("ERROR: while receiving image(" + name + "): " + exception);
}
}
if(image != null) {
this.client.prepareImage(image, null);
this.storage_images.put(name, image);
}
}
return image;
}
When i will draw the image, it will be cutted - curiously. Im only change the with & height proportional. The original image has a dimension from 256x256.
Here is the Problem: on the appletviewer (eclipse) it seems correct. But when i compile it and open that over my webbrowser, the image will be cutted (see the screenshots at the bottom).
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
new int[] {
40, // position left
10, // position top
65, // width (Original is 256)
65 // height (Original is 256)
};
g2.drawImage(getImage("warning.png"), insets.right + data[0], insets.bottom + data[1], data[2], data[3], null);
}
i hope you can tell me, what i do wrong.
Result on Webbrowser
Result on AppletViewer in eclipse IDE*
Aw, problem solved.
Located on the picture itself!