请问怎么把图片圈住一块,然后将“圈住的块”局部放大?

发布于 2021-08-27 18:13:48

请问怎么把图片圈住一块,然后将“圈住的块”局部放大?实现下图效果
aaaaaaaaaaaaaa.png

查看更多

关注者
0
被浏览
2.3k
寄存器
寄存器 2021-08-28
这家伙很懒,什么也没写!

用TikZ实现了一下:插图局部放大的一种实现方式


用楼上的方法实现了一下:

\documentclass{standalone}

% 插图宏包
\usepackage{graphicx}
% 引入TikZ宏包
\usepackage{tikz}
% TikZ宏包扩展库
\usetikzlibrary{fit}% 坐标适配
\usetikzlibrary{spy}% 局部缩放库
\usetikzlibrary{arrows.meta}% 箭头样式

\input{formats.tex}% \drawgrid命令的定义

\begin{document}

\def\imgratio{0.85}

\begin{tikzpicture}[%
  spy using outlines = {rectangle,
                        magnification=3,
                        connect spies}]

  % 载入图像(注意定位锚点为西南,即左下角)
  \node[anchor=south west, inner sep=0] (img1) at (0,0)
  {\includegraphics[width=\imgratio\textwidth]{example-image-a}};

  % 限定坐标区域
  \begin{scope}[x={(img1.south east)}, y={(img1.north west)}]
    % 绘制坐标辅助网络
    % \drawgrid

    % 定位缩放点
    \coordinate (spypoint) at (0.46, 0.66);
    \coordinate (magnifyglass) at (0.0, 0.0);
  \end{scope}

  \spy[anchor=south west, red, size=2.5cm, very thick] on (spypoint)
    in node[fill=white] at (magnifyglass);
\end{tikzpicture}
\end{document}

实现结果为:
2021-08-28_14-55.png

3 个回答
感知+认知+智能
这家伙很懒,什么也没写!

这个可以用pgfplots来实现,下面提供一个实现的方式(自己添加自己的图片):

\documentclass{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{pgfplots}
\usetikzlibrary{spy}
\pgfplotsset{width=11cm,height=8cm}
\begin{document}

\begin{tikzpicture}[spy using outlines=
{circle, magnification=6, connect spies}]
\begin{axis}[no markers,grid=major,
hide axis,
every axis plot post/.append style={thick}]

\addplot graphics
[
includegraphics cmd=\pgfimage,
xmin=-5, xmax=90,
ymin=-0.5, ymax=1.1
] {back.pdf};

\coordinate (spypoint)
at (280,130);
\coordinate (magnifyglass) at (800,80);
\end{axis}
\spy [orange, size=2cm,thick] on (spypoint)
in node[fill=white] at (magnifyglass);
\end{tikzpicture}

\end{document}

fig1.jpg

坐标绘图的和矩形标记的:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{pgfplots}
\usetikzlibrary{spy}
\pgfplotsset{width=11cm,height=8cm}
\begin{document}

\begin{tikzpicture}[spy using outlines=
{rectangle, magnification=6, connect spies}]
\begin{axis}[no markers,grid=major,
%hide axis,
every axis plot post/.append style={thick}]
\addplot
coordinates
{(0, 0) (0, 0.9) (1, 0.9) (2, 1) (3, 0.9) (80, 0)};
\addplot+ [line join=round] coordinates
{(0, 0) (0, 0.9) (2, 0.9) (3, 1) (4, 0.9) (80, 0)};
\addplot+ [line join=bevel] coordinates
{(0, 0) (0, 0.9) (3, 0.9) (4, 1) (5, 0.9) (80, 0)};
\addplot+ [miter limit=5] coordinates
{(0, 0) (0, 0.9) (4, 0.9) (5, 1) (6, 0.9) (80, 0)};

\coordinate (spypoint)
at (40,100);
\coordinate (magnifyglass) at (700,80);
\end{axis}
\spy [orange, size=2cm,thick] on (spypoint)
in node[fill=white] at (magnifyglass);
\end{tikzpicture}
\end{document}

fig2.jpg

拿了橘子跑啊
拿了橘子跑啊 2021-08-30
这家伙很懒,什么也没写!

弄啥累。。。。
tikz的有个名叫spy的 library 不就是干这个活的么?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.fractals,spy}
\begin{document}
\begin{tikzpicture}[spy using outlines={circle, magnification=4, size=2cm, connect spies}]
  \draw [help lines] (0,0) grid (3,2);
  \draw [decoration=Koch curve type 1] decorate { decorate{ decorate{ decorate{ (0,0) -- (2,0) }}}};
  \spy [red] on (1.6,0.3) in node [left] at (3.5,-1.25);
  \spy [blue, size=1cm] on (1,1) in node [right] at (0,-1.25);
\end{tikzpicture}
\end{document}

image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览