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 / November 2005

Tip: Looking for answers? Try searching our database.

create PNG images in palette mode in Java

Thread view: 
babz - 28 Oct 2005 05:22 GMT
Java does not allow us to use more than 16 entries in the color map of
the Index Color Model for palette mode PNG encoding.
This disrupts the quality of images drastically. Is there a way to
improve the image quality?

This is the code I used:

int cmap[] = {

        0x00000000,
           0xFF202020,
        0xFF0000FF,
        0xFF808080,
               0xFF00FF00,
           0xFF00FFFF,
        0xFFFF0000,
           0xFFFF00FF,
           0xFFFFFF00,
           0xFFFFFFFF,
       };

IndexColorModel colorModel = new IndexColorModel(8,
                    cmap.length, cmap, 0, true, -1,
DataBuffer.TYPE_BYTE);

bufImg = new BufferedImage(width, height,
               BufferedImage.TYPE_BYTE_INDEXED, colorModel);

Thanks,

Babz
Roedy Green - 28 Oct 2005 07:13 GMT
>Java does not allow us to use more than 16 entries in the color map of
>the Index Color Model for palette mode PNG encoding.

Where did you learn that?  Perhaps there is some related class without
the restriction.  The limit seems odd given that most indexed
colourmaps in the Windows universe are 8-bit.

I display  17..255-colour map gifs and pngs all the time in Java,
though I could not be certain all the colours are being rendered
properly.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

babz - 28 Oct 2005 10:06 GMT
so what do i do then? Can you think of a way that could prevent color
loss?
Roedy Green - 28 Oct 2005 10:26 GMT
>so what do i do then? Can you think of a way that could prevent color
>loss?

I don't know. I have not used those classes. My suggestion was to look
around for some alternate class that support 8 bit palettes. Perhaps
something in JAI.  See http://mindprod.com/jgloss/jai.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas Fritsch - 28 Oct 2005 15:16 GMT
> Java does not allow us to use more than 16 entries in the color map of
> the Index Color Model for palette mode PNG encoding.
What did actually happen, when you converted a BufferedImage like below
with a large IndexColorModel (say with cmap having 100 entries) to PNG?
Did you get any error, or did the PNG have too few colors, or was it
otherwise of bad quality? I got good results when converting a JPEG
photo to PNG (with a 125-color palette).

The BufferedImage bufImg in your example below is still empty. Hence:
Exactly how do you fill the pixels into that BufferedImage? There are
probably many ways to do this.
How did you convert that BufferedImage to PNG? I assume you did it with
ImageIO.write(bufImg, "PNG", ...).

> This disrupts the quality of images drastically. Is there a way to
> improve the image quality?
[quoted text clipped - 18 lines]
> bufImg = new BufferedImage(width, height,
>                 BufferedImage.TYPE_BYTE_INDEXED, colorModel);

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

babz - 08 Nov 2005 05:23 GMT
Thomas wrote:
>I got good results when converting a JPEG photo to PNG (with a 125-color palette)

can you plz give me the set of color map entries you used? Because now
using more than 16 entries does not give me the exception I was getting
before.

Thanks,

Babz
babz - 09 Nov 2005 08:12 GMT
Thomas wrote:
>I got good results when converting a JPEG photo to PNG (with a 125-color palette)

can you plz give me the set of color map entries you used? Because now
using more than 16 entries does not give me the exception I was getting

before.

Thanks,

Babz


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



©2009 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.