Skip to main content

Create transparent image using JAI

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
3 replies [Last post]
newmanw10
Offline
Joined: 2009-08-17
Points: 0

Anyone know of an easy way to create a transparent image using jai?

I tried using the ConstantDescriptor to do this. I am creating four bands (RGBA), but my image is not really transparent. I am thinking becuase I don't have a ColorModel.

public RenderedOp createTranparentImage(float width, float height) {
   ParameterBlockJAI pb = new ParameterBlockJAI("constant");
   pb.setParameter("width", width);
   pb.setParameter("height", height);
   Byte red = (byte) 0;
   Byte green = (byte) 0;
   Byte blue = (byte) 0;
   Byte alpha = (byte) 0; //set alpha to 0 so that image is completly transparent
   pb.setParameter("bandValues", new Byte[] {red,green,blue,alpha});
   return JAI.create("constant", pb);
}

If I ask for the bufferedImage and try and get that BufferedImages alpha raster I get null;

Is there a way to create a transparent image using jai?

Thanks!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
erunquist
Offline
Joined: 2009-05-01
Points: 0

I use code just like this to make transparent images using JAI. Perhaps the problem is with the mechanism you're using to extract the raster. You could try getting the full raster (with all bands), then manipulate only the alpha sample of each pixel.

forklabs
Offline
Joined: 2006-01-19
Points: 0

Hello,

I tried reproducing your problem using JAI 1.1.3 (see the code below
my sig) and the alpha raster from the BufferedImage is present. If you
could forward us more information it would be helpful.

Regards,

Daniel Léonard

P.S. Class ParameterBlockUtil is part of my jai-operators library at
http://code.google.com/p/forklabs-jai-operators/

Rafael Santos Guest
Offline
Joined: 2010-11-18
Points: 0

Does it need to use JAI?

http://www.lac.inpe.br/JIPCookbook/1300-create-rgb.jsp

Rafael
> Anyone know of an easy way to create a transparent image using jai?
>
> I tried using the ConstantDescriptor to do this. I am creating four
> bands
> (RGBA), but I my image is not really transparent. I am thinking
> becuase I
> don't have a ColorModel.
>
> public RenderedOp createTranparentImage(float width, float height) {
> ParameterBlockJAI pb = new ParameterBlockJAI("constant");
> pb.setParameter("width", width); pb.setParameter("height", height);
> Byte red
> = (byte) 0; Byte green = (byte) 0; Byte blue = (byte) 0; Byte alpha =
> (byte)
> 0; //set alpha to 0 so that image is completly transparent
> pb.setParameter("bandValues", new Byte[] {red,green,blue,alpha}); return
> JAI.create("constant", pb); }
> If I ask for the bufferedImage and try and get that BufferedImages alpha
> raster I get null;
>
> Is there a way to create a transparent image using jai?
>
> Thanks!
>
>