要件の説明に画像を挿入するAPIはありますか?

7 vues (au cours des 30 derniers jours)
MathWorks Support Team
MathWorks Support Team le 9 Jan 2026 à 0:00
要件の説明に画像を挿入するAPIはありますか?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 9 Jan 2026 à 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);

Plus de réponses (0)

Tags

Aucun tag saisi pour le moment.

Produits


Version

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!