writing a "png" file with imageio

T

tiewknvc9

Hi!

i wrote some code that takes a rendered image and successfully converts
it into a JPEG image. Unfortunately I need it to be in a "PNG" format,
luckily a PNG imagewriter is built into java!

The only thing is that when I try to write a png file, it always comes
out as 100% white, but if I write the same rendered image to a jpeg it
looks right. What a pain. Here is the code I am working with

the buffered image is an image that has a black background

Code:
RenderedImage renImage = (RenderedImage)bufferedImage;

//Write generated image to a file
try {
// Save as PNG
if (renImage != null){
File filImg = new File("jb" + lImageCount + ".png");
ImageIO.write(renImage, "png", filImg);
}}

by changing all png's to jpg's, I get a wildly successful jpeg image of
a black background! but as a png its just white.
 
O

Oliver Wong

tiewknvc9 said:
Hi!

i wrote some code that takes a rendered image and successfully converts
it into a JPEG image. Unfortunately I need it to be in a "PNG" format,
luckily a PNG imagewriter is built into java!

The only thing is that when I try to write a png file, it always comes
out as 100% white, but if I write the same rendered image to a jpeg it
looks right. What a pain. Here is the code I am working with

the buffered image is an image that has a black background

Code:
RenderedImage renImage = (RenderedImage)bufferedImage;

//Write generated image to a file
try {
// Save as PNG
if (renImage != null){
File filImg = new File("jb" + lImageCount + ".png");
ImageIO.write(renImage, "png", filImg);
}}

by changing all png's to jpg's, I get a wildly successful jpeg image of
a black background! but as a png its just white.

When you say the PNG is all white, could it be that the PNG is actually
all transparent (but perhaps being displayed over a white background)? Could
it be that you are incorrectly setting the alpha channel for your image?

- Oliver
 
T

tiewknvc9

Im actually not setting the alpha channel... should I be?

everything appears white, I have a foreground layer of text, if I
change the text to say blue, the whole image still appears white...

the background is a filled rectange with the color black..
 
O

Oliver Wong

tiewknvc9 said:
Im actually not setting the alpha channel... should I be?

everything appears white, I have a foreground layer of text, if I
change the text to say blue, the whole image still appears white...

the background is a filled rectange with the color black..

When you say "I have a foreground layer", I don't know what you mean.
Neither the Java class "Image" nor the PNG file format supports layers.

I also don't know what software you are using to view your PNG.

What I'm getting at is maybe whatever image you were rendering is all
there, except it's completely transparent, and your viewing-software is
rendering it by first drawing a completely white background, and then
drawing your image on top of that background. Except your image is
completely transparent, which is why you see a white rectangle regardless of
what contents you put in the PNG file.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top