5

I'm using tikz library spy to zoom into an image. The image Im zooming into is a binary black and white image. But i want the circle with the magnified part to be filled with a color version of the same image. Is this possible?

\documentclass[12 pt,onecolumn]{article}
\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{xcolor}
\usetikzlibrary{spy}
\pgfplotsset{compat=1.5}
\begin{document}

\begin{figure}
\begin{tikzpicture}[spy using outlines={circle,yellow,magnification=5,size=5cm, connect spies}]
\node[anchor=south west,inner sep=0]  at (0,0) {\includegraphics[width=\textwidth]{images/film-stupid-duck}};
\spy on (12.2,5.2) in node [left] at (16,10);
\spy on (6,4) in node [left] at (10,10);
\path[fill=white] (5,0) rectangle (12,2);
\end{tikzpicture}
\caption{}
\label{}
\end{figure}
\end{document}

The picture below is my current result. I want the two magnified images to be from a second image that matches spatially

enter image description here

2
  • No it simply copies what is there in the original. It's pretty nontrivial to get a different version of the image unless you pull off some layering tricks
    – percusse
    Commented May 18, 2014 at 15:38
  • A full compilable example would be welcome.
    – Manuel
    Commented May 18, 2014 at 15:38

1 Answer 1

4

Don't know if this is quite right but it seems to work (although not in any way fully tested).

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{spy}
\begin{document}

\makeatletter
\tikzset{spy on other/.code={%
  \pgfutil@g@addto@macro\tikz@lib@spy@collection{%
    \setbox\tikz@lib@spybox=\hbox{\pgfpicture#1\endpgfpicture}}}}
\makeatother

\begin{tikzpicture}[spy using outlines={circle,yellow,magnification=5,size=5cm, connect spies}]
\fill [black, even odd rule]
  (0,0) rectangle (15, 15) (7.5,7.5) circle [radius=5] circle [radius=2.5]
  (6,0) rectangle (9,15)  (0,6) rectangle (15,9);

\tikzset{spy on other={
  \fill [left color=red, right color=blue, even odd rule]
    (0,0) rectangle (15, 15) (7.5,7.5) circle [radius=5] circle [radius=2.5]
    (6,0) rectangle (9,15)  (0,6) rectangle (15,9);
}}
\spy on (9,12) in node [right] at (16,12);
\spy on (12,6) in node [right] at (16,3);
\spy on (6,3) in node [left] at (-1,3);
\spy on (3,9) in node [left] at (-1,12);

\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .