Hello all,
I have a new problem with my Paint app, I have a TYPE_INT_RGB buffered image, and I'm drawing a "preview" of it, but I want to be able to see through the "preview." Is there a way to make it appear transparent without modifying the actual image?

Well, as an update, I'm using this as a temporary solution,

BufferedImage im = new BufferedImage(b,b,TYPE_INT_ARGB);
            im.getGraphics().drawImage( this, 0, 0, b,b,0,0,this.getWidth(),this.getHeight(),null);
            Color c;
            for(int xx = 0;xx<b;xx++) {
                for(int yy = 0;yy<b;yy++) {
                    c = new Color(im.getRGB( xx, yy ));
                    c = new Color(c.getRed(),c.getGreen(),c.getBlue(),alpha);
                    im.setRGB( xx, yy, c.getRGB() );
                }
            }
            g.drawImage(im,x+5,y+5,null);

::NOTE b is the width and height of the square preview.

I know it's horribly inefficient, and I would like it if someone could point out a simpler more efficient way of doing this.

In my personal opinion, I would say there is no quick way of doing this, since the image is made from solid colours, appling a transparent rectangle behind or above will not make it see through.

I think I would have coded it differently, perhaps get the pixel data for the image by using a PixelGrabber.

Then you could loop thru this int[] like...

int len = pixels.length;
for(int lp=0;lp<len;lp++))
{
     pixels[lp] = (pixels[lp] & 16777215) | (127<<24);
}

Then use createImage(MemoryImageSource(...)) to rebuild the image.

That should hopefully work, can't remember all the details though.

Thanks for the reply, I will look into that, it probably would be more efficient that way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.