要件の説明に画像を挿入するAPIはありますか?
7 views (last 30 days)
Show older comments
MathWorks Support Team
on 9 Jan 2026 at 0:00
Answered: MathWorks Support Team
on 9 Jan 2026 at 8:34
要件の説明に画像を挿入するAPIはありますか?

Accepted Answer
MathWorks Support Team
on 9 Jan 2026 at 0:00
要件エディター右側プロパティにあるイメージ取り込みボタンと同等の処理を、直接実行できるAPIは提供されておりません。
ただし、要件の「説明」や「根拠」欄にはリッチテキスト(HTML)を設定できるAPIがございます。画像をBase64形式のData URIとして<img>タグで埋め込むことで、同様の表示を実現することが可能です。
% 1) 要件セットを新規作成(既存を使うなら slreq.load でもOK)
rs = slreq.new('image_in_description.slreqx');
% 2) 要件を1つ追加
req = add(rs, Summary="画像埋め込みのサンプル");
% 3) PNGファイルを取得
pngFile = fullfile(pwd, 'Image1.png');
% 4) 画像バイト列を読み込み → Base64化(MATLAB組み込み)
fid = fopen(pngFile, 'rb');
bytes = fread(fid, '*uint8');
fclose(fid);
b64 = matlab.net.base64encode(bytes);
% 5) data URI を組み立てて <img> を Description にセット
datauri = "data:image/png;base64," + b64;
html = [ ...
"<p>この要件の説明にPNG画像をインラインで埋め込みます:</p>", ...
"<figure>", ...
"<img src=""" + datauri + """ alt=""embedded image"" width=""480"">", ...
"</figure>" ...
];
req.Description = strjoin(html, newline);
% 6) 保存
save(rs);
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!