Results 1 to 4 of 4
  1. #1
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    97
    Rep Power
    0

    Default IndexColorModel 255 Colors to BufferedImage

    I need to write an image to a .png with a 255-color indexed color model. I know usually do it like this:
    Java Code:
    BufferedImage img=new BufferedImage(width,height,BufferedImage.TYPE_BYTE_INDEXED,model);
    but that doesn't work with models with 255 colors (as opposed to 256 colors). I'm fairly sure it is the BufferedImage creation that is the problem, as when I call model.getMapSize(), it returns the correct size.

    The extra color added to the image's index is 15,15,15.

    Should I be something other than a BufferedImage to write the image, or should I be using a different constructor for BufferedImage, or am I doing something else wrong?

  2. #2
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    97
    Rep Power
    0

    Default Re: IndexColorModel 255 Colors to BufferedImage

    Additional Information: I am drawing the BufferedImage by drawing a regular (BufferedImage.TYPE_INT_RGB) BufferedImage, pixel by pixel, then transposing it onto the indexed BufferedImage by drawing on it with a Graphics2D object.

  3. #3
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    97
    Rep Power
    0

    Default Re: IndexColorModel 255 Colors to BufferedImage

    I apologize for the thread necromancy, however, I have found somewhat of a solution to my problem so I wanted to post it just in case anyone could get any use out of it.

    I needed the image with a specific color index so it could be read correctly by a game (CKII). Using the method described above, the game couldn't read it. Additionally, Ubuntu and its Image Viewer could not display its contents either. Adding one more color to the index in Java before creating the image makes the image readable and work for my purposes. It doesn't seem to matter what the extra color is.

  4. #4
    Ewe Loon's Avatar
    Ewe Loon is offline Member
    Join Date
    Jun 2016
    Posts
    3
    Rep Power
    0

    Default Re: IndexColorModel 255 Colors to BufferedImage

    PNG does not have a 255 color model, in fact i have never seen an image format that does
    I have however seen software that uses either color 0 or 255 as transparent, leaving 255 useable colors
    The PNG file format stores its alpha in a separate section of the file, keeping it inderpendent of the color format

    the reason nothing would read the file with only 255 colors saves it that it no-longer fits the specs of the file format , and other apps expect 256 colors to be present

Similar Threads

  1. Changing colors
    By leeroijenkiins in forum New To Java
    Replies: 2
    Last Post: 04-26-2013, 06:30 PM
  2. How do i add colors
    By ytrewqc in forum New To Java
    Replies: 1
    Last Post: 11-01-2011, 03:15 PM
  3. Animation with colors
    By musico in forum New To Java
    Replies: 2
    Last Post: 05-28-2011, 08:07 PM
  4. In Case You Want Colors!
    By angryboy in forum Forum Lobby
    Replies: 0
    Last Post: 08-29-2009, 10:06 PM
  5. Rectangle and Colors
    By urbim in forum Java Applets
    Replies: 0
    Last Post: 07-11-2009, 03:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •