Tikz クリップ画像から内部部分を抽出する

Tikz クリップ画像から内部部分を抽出する

MWE について考えてみましょう。

\documentclass{article}
    \usepackage{tikz}
    \usepackage{graphicx}

% % COMPILED WITH PDFLATEX

    \newif\ifdeveloppath
    \tikzset{/tikz/develop clipping path/.is if=developpath,
      /tikz/develop clipping path=true}

    \newcommand{\clippicture}[2]{
      \begin{tikzpicture}
      \ifdeveloppath
      \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=1.0\linewidth,keepaspectratio]{example-image-a}};
    \else
      \node[anchor=south west,inner sep=0] (image) at (0,0) {\phantom{\includegraphics[width=1.0\linewidth,keepaspectratio]{example-image-a}}};
    \fi
    \pgfresetboundingbox
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
      % Draw grid 
      \ifdeveloppath
        \draw[help lines,xstep=.02,ystep=.02] (0,0) grid (1,1);
        \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
        \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
        \draw[red, ultra thick] #2 -- cycle;
      \else
        % Use the path to clip
        \path[clip] #2 -- cycle;
        \node[anchor=south west,inner sep=0pt] {\includegraphics[width=1.0\linewidth,keepaspectratio]{example-image-a}};
      \fi
    \end{scope}
    \end{tikzpicture}
    }

\begin{document}
\thispagestyle{empty}

     \clippicture{[width=1.0\textwidth]{some-image}}{(0.359,0.268) -- (0.48,0.73) -- (0.52,0.73) -- (0.64,0.27) -- (0.60,0.27) -- (0.562,0.403) -- (0.43,.403) -- (0.395, 0.268) -- (0.359,0.268)}

\newpage
\thispagestyle{empty}

    \tikzset{develop clipping path=false}

\begin{center}
    \clippicture{[width=1.0\textwidth]{some-image}}{(0.359,0.268) -- (0.48,0.73) -- (0.52,0.73) -- (0.64,0.27) -- (0.60,0.27) -- (0.562,0.403) -- (0.43,.403) -- (0.395, 0.268) -- (0.359,0.268)}
\end{center}
\end{document}

出力は次のようになります:

ここに画像の説明を入力してください

ここに画像の説明を入力してください

質問: 私のクリッピングパスは閉回路なので、出力は大文字の外側の部分になります。手紙の抽出を完了するにはどうすればよいでしょうか手紙の適切な内側部分も切り取って?

ありがとう。

答え1

「A」の内側の三角形を反時計回りに(「非ゼロルール」を使用して)パスに追加して、次のようになります。

(0.359,0.268) -- (0.48,0.73) -- (0.52,0.73) -- (0.64,0.27) -- (0.60,0.27) -- (0.562,0.403) -- (0.43,.403) -- (0.395, 0.268) -- (0.359,0.268) (0.440,0.438) -- (0.555,0.438) -- (0.498,0.675)  -- (0.44,0.44)

赤いアウトラインの灰色のグリッド上の「A」 「A」

閉じたパスを作成するときは、cycle最初の座標を繰り返すのではなく、 を使用する方がよいでしょう。これにより、パスは次のようになります。

(0.359,0.268) -- (0.48,0.73) -- (0.52,0.73) -- (0.64,0.27) -- (0.60,0.27) -- (0.562,0.403) -- (0.43,.403) -- (0.395, 0.268) -- cycle (0.440,0.438) -- (0.555,0.438) -- (0.498,0.675) -- cycle

関連情報