Results 1 to 2 of 2
  1. #1
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    6

    Default 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:
    Java 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 :
    Java 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

  2. #2
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    6

    Default

    Solved : by setting int type = BufferedImage.TYPE_INT_ARGB;

Similar Threads

  1. KeyListener Graphics Problem
    By Makesfolkslose in forum New To Java
    Replies: 2
    Last Post: 05-26-2011, 05:07 AM
  2. Problem in Graphics
    By justbeller in forum Java 2D
    Replies: 1
    Last Post: 04-03-2011, 01:39 PM
  3. Graphics problem
    By luke24 in forum New To Java
    Replies: 7
    Last Post: 02-19-2011, 09:19 PM
  4. problem with jframe&jmenu&graphics
    By beni.vd in forum AWT / Swing
    Replies: 1
    Last Post: 12-31-2010, 08:07 PM
  5. i am having a problem with creating graphics
    By umpire43055 in forum AWT / Swing
    Replies: 3
    Last Post: 08-07-2009, 06:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •