Skip to main content

Image with transparent background

4 replies [Last post]
scubed
Offline
Joined: 2006-09-20
Points: 0

I want to display a curve in J3D without having to draw a zillion line segments and I'm not too concerned about display quality (fineness), so I'm using a J2D shape to create a texture in J3D. I've been able to display the shape successfully by drawing it to a BufferedImage, creating a texture from that and applying the texture to a quad.

The background of the image becomes part of the texture and obscures objects behind it. I'd like the background to be transparent so that only the shape itself appears to be in the scene. I assume I will need to make the quad transparent, too. It seems that a GIF will support a transparent background and might be the solution I need. (Or perhaps there's another way...)

If the solution is a GIF, can I create the GIF from the BufferedImage without writing to disk and just use it directly? I'm new to image processing so I'd appreciate any code snippets that will take the BufferedImage to a GIF.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Dmitri Trembovetski

Why don't you use a translucent BufferedImage?
You can use BufferedImage.TYPE_INT_ARGB as the bi type
when creating it.

Thanks,
Dmitri

java2d@JAVADESKTOP.ORG wrote:
> I want to display a curve in J3D without having to draw a zillion line segments and I'm not too concerned about display quality (fineness), so I'm using a J2D shape to create a texture in J3D. I've been able to display the shape successfully by drawing it to a BufferedImage, creating a texture from that and applying the texture to a quad.
>
> The background of the image becomes part of the texture and obscures objects behind it. I'd like the background to be transparent so that only the shape itself appears to be in the scene. I assume I will need to make the quad transparent, too. It seems that a GIF will support a transparent background and might be the solution I need. (Or perhaps there's another way...)
>
> If the solution is a GIF, can I create the GIF from the BufferedImage without writing to disk and just use it directly? I'm new to image processing so I'd appreciate any code snippets that will take the BufferedImage to a GIF.
> [Message sent by forum member 'scubed' (scubed)]
>
> http://forums.java.net/jive/thread.jspa?messageID=260277
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

scubed
Offline
Joined: 2006-09-20
Points: 0

OK, but...when I make the host quad transparent, the texture disappears too. I'm using Mode DECAL.

I think I still need some more hints. What specifies the transparent color of the image?

Dmitri Trembovetski

java2d@JAVADESKTOP.ORG wrote:
> OK, but...when I make the host quad transparent, the texture disappears too. I'm using Mode DECAL.
>
> I think I still need some more hints. What specifies the transparent color of the image?

Note that I'm talking about using a TRANSLUCENT image,
not BITMASK (see java.awt.Transparency).

Thanks,
Dmitri

> [Message sent by forum member 'scubed' (scubed)]
>
> http://forums.java.net/jive/thread.jspa?messageID=260291
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

scubed
Offline
Joined: 2006-09-20
Points: 0

Eureka! I set the mode(s) to RGBA where ever possible and set quad transparency to 0.0 and used

ta.setTextureMode(TextureAttributes.REPLACE);

and I get the desired result.

Thanks for your help.