Creating transparent PNG with exact RGBA values

Posted by rrowland on Stack Overflow See other posts from Stack Overflow or by rrowland
Published on 2012-10-31T21:15:17Z Indexed on 2012/10/31 23:00 UTC
Read the original article Hit count: 143

I'm color-coding a transparent image to be read programatically. However, the image seems to be getting compressed and my code is reading color values other than the ones I mean to pass it.

Concept

Output

This is the output I get, exporting as PNG-24. I programatically check each pixel for one of the six colors I use in creating the image:

  • 0x00000F
  • 0x0000F0
  • 0x000F00
  • 0x00F000
  • 0x0F0000
  • 0xF00000

Each color represents a different texture to apply. Top right (0x00000F) will pull texture from the tile to its top right and blend it at a ratio equal to the opacity of the pixel. The end goal is to create a hex tiled grid with differing textures that blend smoothly.

What's happening

It seems that when converting to PNG, Photoshop will change the RGBA to make it smoother, or just to help compression size. Parts that should be 250 red range anywhere from 150 to 255.

Question

Whether using PNG or another web-compatible format, I need to be able to save these pixel values, essentially instructions, loss-less and still maintain transparency. Is this possible in any format or will I need to re-think my approach?

© Stack Overflow or respective owner

Related posts about compression

Related posts about png