# ImageData returns slightly different RGB values than specified when creating a graphic

Why does the following not return precisely {0.99,0.5,0.49}?
Is there a way to avoid the discrepancy?

In[2089]:=
ImageData[
Show[Graphics[{FaceForm[RGBColor[0.99, 1/2, 0.490000]],
Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}], ImageSize -> 20,

Out[2089]= {0.988235, 0.501961, 0.490196}

• Use c/255 where c is in interval [0,255] for values of colors to be exact. Or use hexadecimal RGBColor["#ff0000"]. Commented Mar 15 at 15:59
• Do you want a 20 by 20 image filled with RGBColor[0.99, 1/2, 0.490000]? Try img = Image[ConstantArray[RGBColor[0.99, 1/2, 0.490000], {20, 20}]] . Verify with Flatten[ImageData[img], 1] // DeleteDuplicates is {{0.99, 0.5, 0.49}}. Commented Mar 15 at 20:12

The real numbers (RGB) spanning [0,1] have to be put into bytes (Range 0..255 permissible levels).

Don't know the actual algorithm, but assuming that the algorithm Rescales:

Rescale[{0.99, 0.5, 0.49}, {0, 1}, {0, 255}] // Round


{252, 128, 125}

which after conversion for display gives:

{252, 128, 125}/255 // N


{0.988235, 0.501961, 0.490196}

• Thank you! This was helpful. It is somewhat annoying that Mathematica won't accept rgb values in the form of integers in [0,255], but I guess it is easy enough to write a function to do that myself. Commented Mar 16 at 16:27