Results 1 to 3 of 3
  1. #1
    arieltal is offline Member
    Join Date
    Sep 2012
    Posts
    34
    Rep Power
    0

    Default Transparency issues..

    hello, i'm trying to eliminate the background of a sprite, i have found several forum talks about it, the problem is that
    i manage to set the alpha of the color i want to make transparent to zero, but when i draw the image, it has a gray background instead of what color it used to be. please help.
    code:
    Java Code:
    public void cleanImage(BufferedImage target,int r,int g,int b,int a)
      {
    	  int col = ((a << 24) | (r << 16) | (g << 8) | b);
    	  int trans = ((0 << 24) | (r << 16) | (g << 8) | b);
    	  int [] pixels = ((DataBufferInt)target.getRaster().getDataBuffer()).getData();
    	  ColorModel cm = target.getColorModel();
    	  SampleModel sm = target.getRaster().getSampleModel();
    	  for (int i = 0;i<pixels.length;i++)
    			if (pixels[i] == col) pixels[i] = trans;//-1118482;
    	  DataBuffer db = new DataBufferInt(pixels,target.getHeight()*target.getWidth());
    		WritableRaster wr = Raster.createWritableRaster(sm,db,null);
    		target = new BufferedImage(cm, wr, false, null);
      }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    arieltal is offline Member
    Join Date
    Sep 2012
    Posts
    34
    Rep Power
    0

    Default Re: Transparency issues..

    not in that perticular procedure, but i have copy-pasted that code and it did not work.. :(

Similar Threads

  1. JTable Transparency
    By Redefine12 in forum Java 2D
    Replies: 4
    Last Post: 04-17-2012, 09:24 AM
  2. Transparency
    By zirbinator in forum Java 2D
    Replies: 7
    Last Post: 03-28-2012, 05:51 AM
  3. DrawImage with transparency ?
    By mrhid6 in forum AWT / Swing
    Replies: 2
    Last Post: 10-01-2011, 11:58 PM
  4. Transparency problem
    By Lacrim in forum Java Applets
    Replies: 1
    Last Post: 07-27-2011, 01:34 PM
  5. ImageIcon Transparency
    By Lingerz in forum New To Java
    Replies: 2
    Last Post: 06-04-2010, 02:53 PM

Posting Permissions

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