By supporting transparency you catch an interesting problem.

Suppose you draw an image like a PNG file that has an alpha channel 
incorporated.
You have trasparent pixels and half transparent pixels.

I suppose computing the tightest box would consider half trasparent pixels as 
opaque and put them inside the box instead perfectly transparent pixels would 
be outside the box, right.

Anyway what method would make this calculation, can you give me any insight ?

And just another question what if you don't want to get rid of those completely 
transparent pixels, suppose you use them for centering pursposes.

Anyway I reply to the to question about which BufferedImage.

Should it be a BufferedImage.TYPE_INT_RGB or TYPE_INT_ARGB ?

I suppose the latest.

But I had strange behaviours with the last type...

Example I was working with photoshop layers and Blending Modes

I used an implementation of Composite for Screen Blending mode from a previous 
version of SwingX.

I got an Image from an ImageIcon from a JLabel.
And using composites I had uncorrect behaviour from using it directly.
I lost all the trasparency from the original PNG file used in the JLabel, when
applying the composite.

The same has happened when I tried to create a bufferedImage TYPE_INT_ARGB
and draw the image over it and then use this for the composite.

Instead redrawing the original image on a bufferedImage TYPE_INT_RGB and then 
using this for the composite works perfectly.

Here's the sample code:

/// CODE SNIPPET START

Graphics2D g2D = (Graphics2D) g;

Composite myComposite = BlendComposite.Screen;
Composite originalComposite = g2D.getComposite();

// Using this Image directly would give loss of all transparency and uncorrect 
result on Composite.
Image glowImage = group.getArrowGlowImageIcon().getImage();

// Procedure to make Images with alpha work with Blending Composites

// Declaring the image type as BufferedImage.TYPE_INT_ARGB would give same 
results as not using any buffered Image at all

BufferedImage bufferedGlowImage = new 
BufferedImage(glowImage.getWidth(null),glowImage.getHeight(null),BufferedImage.TYPE_INT_RGB);

Graphics2D imgG2D = bufferedGlowImage.createGraphics();
imgG2D.drawImage(glowImage, 0, 0, null);
imgG2D.dispose();

g2D.setComposite(myComposite);

g2D.drawImage(bufferedGlowImage, x, y, null);

// Restore of the old Composite to paint other stuff correctly

g2D.setComposite(originalComposite);

/// CODE SNIPPET END

As a proof of that problem I tracked the object and the image returned from the 
imageIcon contains a BufferedImage imageType == 2 in his imagerep.
[Message sent by forum member 'estades' (estades)]

http://forums.java.net/jive/thread.jspa?messageID=216564

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to