How to load the images using the code approach

1 回表示 (過去 30 日間)
Othman Alkandri
Othman Alkandri 2023 年 1 月 30 日
コメント済み: Walter Roberson 2023 年 1 月 30 日
Hello,
I have a set of images in the folder of the app project. I am trying to implement the following.
Based on the dropdown selection, a desired image should be loaded to the app window using UIAxies or Image, as shown in the screenshot.
1-How to load the images using the code approach?
2-Which is better to load the image UIAxies or Image?

採用された回答

Kevin Holly
Kevin Holly 2023 年 1 月 30 日
編集済み: Kevin Holly 2023 年 1 月 30 日
1.
properties
folder
filename
end
% Call back for pushbutton to load image
[app.filename, app.folder] = uigetfile('*.*');
if ~ischar(app.filename); return; end %user cancel
[~,~,ext] = fileparts(app.filename);
files = dir(fullfile(app.folder,['*' ext]));
% Update dropdown box with file names in the same folder with the same extension as file loaded.
app.ImageFileDropDown.Items = {files.name};
app.ImageFileDropDown.Value = app.filename;
% Read image
Img = imread(fullfile(app.folder,app.filename)); % or imread(fullfile(app.folder,app.ImageFileDropDown.Value))
imshow(app.UIAxes) % to load on axes
app.Image.ImageSource = fullfile(app.folder,app.filename) % to load on Image
2. If you plan on ploting or playing graphical objects ontop of image, I would use app.UIAxes.
  4 件のコメント
Othman Alkandri
Othman Alkandri 2023 年 1 月 30 日
Thank you
Walter Roberson
Walter Roberson 2023 年 1 月 30 日
You can configure ItemsData to return particular values for a choice, so you can configure Items to be the list of things the user is shown, and ItemsData to be the corresponding filenames to use.
Img = imread(fullfile(app.folder,app.filename)); % or imread(fullfile(app.folder,app.ImageFileDropDown.Value))
imshow(app.UIAxes) % to load on axes
That should be
Img = imread(fullfile(app.folder,app.filename)); % or imread(fullfile(app.folder,app.ImageFileDropDown.Value))
imshow(app.UIAxes, Img) % to load on axes

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by