# RGB Colors in TikZ and conversion with ghost script to PNG

Since a few days I am trying to find a solution for the folowing problem: I am creating a Tikz picture with a simple rectangele and fill the rectange with a special RGB color. The code looks like this:

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\fill[color={rgb:red,50;green,5;blue,5}](0.0,0.0)--(0.0,20.0)--(15.0,20.0)--(15.0,0.0)--(0.0,0.0);
\end{tikzpicture}
\end{document}


Then I create a PNG from this Pdf file with a Shell Skript:

gs -r200x200 -sDEVICE=png16 -sOutputFile=test.png -dBATCH -dNOPAUSE test.pdf

At last I read the output image with Java and read the RGB Color of a pixel inside the rectangle. The resulting color values have alwys a big difference to the value I have set in TikZ. I think the problem is somewhere in ghost script. I would be happy of any ideas to solve this.

-
Welcome to TeX.SX. A tip: If you indent lines by 4 spaces or enclose words in backticks , they'll be marked as code, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). –  Harish Kumar May 22 '12 at 23:34

You have to define the color something like this

\definecolor{mycolor}{rgb}{.5,.05,.05}


One more possibility is to use RGB where you have to give numbers from 0 to 255.

\definecolor{mycolor}{RGB}{128,15,15}


This needs the package xcolor (which is loaded by tikz in this case).

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\definecolor{mycolor}{rgb}{.5,.05,.05}
%\definecolor{mycolor}{RGB}{128,15,15}
\begin{document}
\begin{tikzpicture}
\fill[color=mycolor](0.0,0.0)--(0.0,20.0)--(15.0,20.0)--(15.0,0.0)--(0.0,0.0);
\end{tikzpicture}
\end{document}
`

-
Great, now it works. Cant believe that this was the problem. –  Rua_de_Janeiro May 22 '12 at 23:49
@Rua_de_Janeiro: In that case you may upvote theanswer (with the upward pointing arrow to the left of it; you need 15 reputation points before you can upvote) and accept it (by clicking on the checkmark). This will add some reputation points to those who answered and to you. This the tradition followed here in TeX.SX. –  Harish Kumar May 22 '12 at 23:53