主要内容

本页采用了机器翻译。点击此处可查看英文原文。

创建图像映射

在 HTML 或 PDF 报告中,您可以将图像的区域指定为链接。点击 HTML 浏览器中图像的链接区域即可打开目标。您可以将图像中的不同区域映射到不同的链接目标。

  1. 为每个要作为链接的图像区域创建一个 mlreportgen.dom.ImageArea 对象。如果图像不可见,您可以指定要显示的文本。

    您可以指定图像区域具有以下形状之一:

    • 矩形

    • 圆圈

    • 多边形

    有关详细信息,请参阅 mlreportgen.dom.ImageArea

  2. 创建一个 mlreportgen.dom.ImageMap 对象来将链接区域与图像关联。将 ImageArea 对象追加到 ImageMap 对象。

例如,您可以创建从绘图图像到有关绘图的文档的链接。

import mlreportgen.dom.*
d = Document("imageArea","pdf");
open(d);

% Set page size to A4
pageSize = d.CurrentPageLayout.PageSize;
pageSize.Height = "297mm";
pageSize.Width = "230mm";

% Set margins to 0
pageMargins = d.CurrentPageLayout.PageMargins;
pageMargins.Top = "0mm";
pageMargins.Bottom = "0mm";
pageMargins.Left = "0mm";
pageMargins.Right = "0mm";

% Create a plot and save it as an image file
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y);
annotation("textbox", [0.2,0.4,0.1,0.1],...
           "string", "Help on plot function");
saveas(gcf,"plot_img.png");

% Create the DOM image object and append it to your document
plot1 = Image("plot_img.png");
append(d,plot1);

% Define the area and link target using ImageArea
target = ["https://www.mathworks.com/help/matlab/ref/" ...
"plot.html?searchHighlight=plot"];
area1 = ImageArea( target, ...
"plot function help",160,340,383,392);

% Create the image map object and append the area to it
map = ImageMap();
append(map,area1);
plot1.Map = map;

close(d);
rptview(d.OutputPath);

另请参阅

函数

主题