Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

writing a "png" file with imageio

Thread view: 
tiewknvc9 - 04 Apr 2006 17:04 GMT
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);
}}
[/code]

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.
Oliver Wong - 04 Apr 2006 17:33 GMT
> Hi!
>
[quoted text clipped - 22 lines]
> 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
tiewknvc9 - 04 Apr 2006 18:21 GMT
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..
Oliver Wong - 04 Apr 2006 22:13 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.