samcarter
I am replicating a beamer theme whose title graphic should automatically adapt to the primary colour of the theme. Unfortunately I only have the graphic as pixelated image and the design is a bit too delicate to replicate it as a vector graphic.


samcarter
As first step I used gimp and adapted the colour curves so the image goes from transparent to black (this dramatically simplifies the involved math).

![test.png](/image?hash=4521659e0ed58996db3060b1db7114c1700771b20c5dce7ed069611ec8f604ac)

([image.png](/image?hash=4521659e0ed58996db3060b1db7114c1700771b20c5dce7ed069611ec8f604ac))

Then I found a hacky workaround using the decodearray key to mess with the colour palette of the included image:


\documentclass{beamer}

\setbeamercolor{palette primary}{fg=red}
\usebeamercolor{palette primary}
\extractcolorspecs{palette primary.fg}{\tmp}{\tempa}

\usepackage{listofitems}

\begin{document}

\begin{frame}

\includegraphics[width=4cm]{image.png}

\includegraphics[width=4cm,decodearray={\mylist[1] 0 \mylist[2] 0 \mylist[3] 0}]{image.png}

\end{frame}

\end{document}


![decorate.png](/image?hash=ed161e43371705b57afdc393a01ac15b9e46044648da5c2dc4ac8fecefe752d0)

### Caveat:

Depending on which colour you use, you might run into problems with colour models in certain pdf viewers. In my real use case I have some shade of blue instead of the red from the above example. This is how the result looks like in adobe reader (left) and mac preview (right):

![image.png](/image?hash=fbe18bae396bd325cb07158e5ab4b438a3a9ba39f348165a9ed6a06b25fff7e7)

(and if compiled with lualatex, the blue becomes entirely invisible)
Skillmon
# This answer is not meant seriously

First I translated the png to a pxpic image with an unpublished tool I wrote for fun a while ago. It outputs the pixel colours in HTML-codes.

Then I created my own pxpic mode that will interpolate between 00 and FF (taking only the first two tokens of the HTML code into consideration, as the original image is black and white). The result is ultra slow, suffers from the typical issues of many PDF viewers in introducing gaps between the "pixels", and all in all very unpleasant, but technically it works :)


\documentclass[]{standalone}

\usepackage{xcolor}
\usepackage{pxpic}
\ExplSyntaxOn
\cs_new:Npn \my_int_from_hex:w #1#2#3 \scan_stop: { \int_from_hex:n {#1#2} }
\pxpicnewmode{samcarter}
{
{
\exp_args:Ne \color
{
samcarter1 !
\fp_eval:n { \my_int_from_hex:w #1 \scan_stop: / 2.55 }
! samcarter2
}
\px
}
}
\NewDocumentCommand \samcarterbackground { O{} m m }
{
\group_begin:
\pxpicsetup {#1}
\colorlet {samcarter1} {#2}
\colorlet {samcarter2} {#3}
\input { samcartersbackground.tex }
\group_end:
}
\ExplSyntaxOff

\begin{document}
\samcarterbackground[size=.5pt]{red}{green}
\end{document}


Result:

(strange pattern is a result of aliasing of the gap issue)

The pxpic file samcartersbackground.tex is unfortunately too large to post it here. In fact, the list of pixels is too long to process it with pdfTeX (with the default memory limits), so I needed to use LuaTeX (this has dynamic memory allocation).
samcarter
Another way to adapt the image colour with a bit of Ti*k*Z magic:


\documentclass{beamer}

\usepackage{tikz}
\setbeamercolor{palette primary}{fg=red}

\begin{document}

\begin{frame}

\includegraphics[width=4cm]{image.png}

\begin{tikzpicture}[inner sep=0pt]
\usebeamercolor{palette primary}
\usebeamercolor{background canvas}
\begin{scope}[blend group=screen]
\begin{scope}[blend group=overlay]
\node (image) {\includegraphics[width=4cm]{image}};
\fill[white] (image.south west) rectangle (image.north east);
\end{scope}
\fill[palette primary.fg] (image.south west) rectangle (image.north east);
\end{scope}
\end{tikzpicture}

\end{frame}

\end{document}


Caveat: This will result in a solid background, the image won't be transparent any more. This should not be too big a problem with beamer, as beamer adds a white background to all slides by default, but might be inconvenient with other classes.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.