File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Support for PNG in Browsers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Support for PNG in Browsers" Watch "Support for PNG in Browsers" New topic
Author

Support for PNG in Browsers

David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Does anyone know about how well PNG images are supported?
I have a web app that creates dynamic images. At the moment it outputs them as JPEGs but they would be better as GIFs. I'm avoiding GIF because of the patent problem.
The JPEG dithering is beginning to get me down, but I'd prefer to have some idea on the percentage of viewers that will be able to see the images.
Anyone?


[ JavaRanch FAQ ][ Book Promotions ][ DbTamer ][ BumperStickers ][ JavaRanch Badges ]
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 411
look at:
http://www.libpng.org/pub/png/pngapbr.html
http://www.w3.org/Graphics/PNG/
and
http://www.libpng.org/pub/png/pngstatus.html#browsers
By the way, I tried just couple days ago to create a servlet, that will generate an image.
That image suppose to be 2 pixel height and 1 pixel width (I wanted it as a background color for table cells). Url for a servlet suppose to contain 2 parameters - colors for both pixels.
I just gave up - it messes colors even if I set quality to 100%.
I mean, if I provide 0000ff and ffffff they both get changed - blue is not exactly 0000ff and white is kind of lightblue. If first color is green, than white is kind of lightgreen.
If anybody knows, is it how it suppose to be, or I made some stupid mistake, please respond.
This is the code:
String strCL1 = request.getParameter("color1");
String strCL2 = request.getParameter("color2");
int color1 = 0;
try{
color1 = Integer.parseInt(strCL1,16);
}
catch(Exception e){}
int color2 = 0;
try{
color2 = Integer.parseInt(strCL2,16);
}
catch(Exception e){}
BufferedImage img = new BufferedImage(1,2,BufferedImage.TYPE_INT_RGB);
img.setRGB(0,0,color1);
img.setRGB(0,1,color2);
ServletOutputStream out = response.getOutputStream();
JPEGImageEncoder enc = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(img);
param.setQuality(1.0f,true);
enc.setJPEGEncodeParam(param);
enc.encode(img);
out.flush();
out.close();
[ April 06, 2003: Message edited by: Yuriy Fuksenko ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Your code is like mine, and I'm getting the JPEG dithering too. Interesting that it dithers when there are only two pixels...
Thanks for the links, I'll check them out.
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 411
Well, I had the same effect, when I tryed to create 30x30 pixel image, but only with 2 colors, alternate for each pixel line.
 
IntelliJ Java IDE
 
subject: Support for PNG in Browsers
 
Threads others viewed
Printing images in Java
Recognizing Blank Images
Retrieving all images from phone memory
AppleTV like GUI?
Counting number of files in each folder
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com