-
Graphics problem?
So ... im trying to split an image to different parts ... everything works well except when i draw the image its black where its supposed to be transperant and white where there is supposed to be colors =P Iv no idea of what has gone wrong ... here is how i do the splitting:
Code:
public static BufferedImage[][] splitImage(BufferedImage img, int cols, int rows) {
int w = img.getWidth()/cols;
GUI.getGUI().centerPanel.setSpiteWidth(w);
int h = img.getHeight()/rows;
GUI.getGUI().centerPanel.setSpiteHeight(h);
int num = 0;
BufferedImage imgs[][] = new BufferedImage[rows][cols];
for(int y = 0; y < rows; y++) {
for(int x = 0; x < cols; x++) {
imgs[y][x] = new BufferedImage(w, h, img.getType());
Graphics2D g2d = imgs[y][x].createGraphics();
g2d.drawImage(img, 0, 0, w, h, w*x, h*y, w*x+w, h*y+h, null);
g2d.dispose();
System.out.println(num++);
}
}
System.out.println("Done");
return imgs;
}
and then I use the images in the array by :
Code:
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.drawImage(pics[currentRow][currentCol], spiteX, spiteY, spiteW, spiteH, null);
}
any ideas? =P thanks alot
-
Solved : by setting int type = BufferedImage.TYPE_INT_ARGB;