MATLAB Answers

Add static images with APP designer

1,097 views (last 30 days)
M G
M G on 9 May 2018
It seems that there are no standard tools (from the Component Library) to add a static (i.e., not changing) image to the Display field of a App Designer app. Is there, in fact, a way to do this (perhaps with programmatic tools)? I am interested in showing images that would help the user of the App to understand the data-input requirements and how the outputs are to be applied in practice.

  0 Comments

Sign in to comment.

Answers (3)

Melinda Toth-Zubairi
Melinda Toth-Zubairi on 25 Mar 2019
Starting in R2019a you can use the uiimage function to create an image component in your App Designer apps.
f = uifigure;
im = uiimage(f);
im.ImageSource = 'peppers.png';
MLAnswers_uiimage.png
For information about scaling and other properties of the image component, see Image Properties in the MATLAB documentation.

  0 Comments

Sign in to comment.


Kevin Chng
Kevin Chng on 31 Aug 2018
Edited: Kevin Chng on 31 Aug 2018
Hi, Mr Gan
In my practice, i use axes to host image. App designer don't allow you to modify the generated GUI code except call back. Therefore,
1) Design your GUI in app designer, drag a axes on the GUI.
2) Then, you copy the whole code then paste it in the .m file in your matlab.
3) name the .m file properly, at the first row of script, you will see this "classdef app1 < matlab.apps.AppBase", please ensure the name of your .m file is also app1. If you want to name them other than app1, we may discuss further.
4) find this in your script,
function createComponents(app)
.....
....
app.UIAxes = uiaxes(app.UIFigure);
app.UIAxes.Position = [52 313 560 99];
imshow('Picture1.png','Parent',app.UIAxes);
......
......
Add the imshow below the app.UIAxes.
5) Done. The limitation of this method is you can't compile it through web apps compiler. However, it don't have any issue with MATLAB compiler.
2nd Method is use Button to host your image.
1) In your app designer, you drag the button in your GUI.
2) Double click on your button, then you try to find more properties in your button properties on the bottom left of your screen.
3) click on more properties, then you will see Icon File.
4) Select the image you wanted to insert, then delete the text/words of button.
5) Done

  4 Comments

Show 1 older comment
Kevin Chng
Kevin Chng on 31 Aug 2018
Thanks Chris.
Just for clarification, for your suggested method, we have to code the UIAXES and IMSHOW in m.file instead of .mlapp?
Refer to picture below, How we initiate the image in the axes in app designer? The createComponent's part is not allowed to be edited.
pp designer?The part of create component is not allowed to be edited. It has been my pain quite long.
Chris Portal
Chris Portal on 31 Aug 2018
If you'd like to show an image when the app opens, you can show it by configuring the UIBUTTON Icon property during design time. If you're using the UIAXES approach, create a startup function on the app by right clicking on the canvas where you drag and drop components and choosing Callbacks->StartupFcn.
There, you can do:
imshow(myImage, 'Parent', app.UIAxes);
Hope this helps.
Kevin Chng
Kevin Chng on 1 Sep 2018
Appreciate your well explanation. I didn't know there is callback for startup. It definitely will help me a lot in future.
Thanks.

Sign in to comment.


Chris Portal
Chris Portal on 12 May 2018
There are currently 2 options available which are described here:
https://www.mathworks.com/matlabcentral/answers/283215-insert-image-in-appdesigner-gui

  1 Comment

M G
M G on 12 May 2018
Thank you for taking the time to reply to my question. In this case, I have followed your link, and found that the trail runs cold (it links to a link which is no longer valid).
In Matlab, I looked at the Component Library, and in my version (R2018a), there isn't an ICON component.
Apparently, when 'packaging' the App, the software can pull in image files that it discovers and add those to the Package, but I see no way of adding them at the 'design' stage. M

Sign in to comment.

Sign in to answer this question.