How to put a picture on a button in a GUI?

조회 수: 64 (최근 30일)
Jasmine
Jasmine 2012년 8월 9일
댓글: Adam Danz 2020년 10월 20일
Hi,
I wish to create a GUI to use with a SIMULINK model. I want to have a picture on my buttons in my GUI. How do I do this?
Thanks,
Jasmine
  댓글 수: 1
Adam Danz
Adam Danz 2020년 10월 20일
Update: starting in r2020a uibuttons can also host animated GIF images and truecolor image arrays (examples).

댓글을 달려면 로그인하십시오.

채택된 답변

TAB
TAB 2012년 8월 9일
편집: TAB 2012년 8월 9일
See
In these examples, image is read every time when GUI is created or opened. So image file must be present every time.
If you are using GUIDE to to design your GUI, you can embed the image directly in the button so that image file is not required again, here is the procedure:
  1. Double click on button to open Property inspector
  2. Go to CDATA property and enter the command imread('MyImageFile.jpg') . So image will be read and will be saved in fig file directly.
  3. After that deleting the original image will not have any effect on your GUI.
  댓글 수: 4
Lam Nguyen Van
Lam Nguyen Van 2020년 4월 19일
Help me! How can i do it: CDATA : I create code files that generate GUIs as functions or scripts (programmatic GUI construction)?
Lam Nguyen Van
Lam Nguyen Van 2020년 4월 19일
I want to After that deleting the original image will not have any effect on your GUI.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Raxeee
Raxeee 2013년 1월 29일
"he command imread('MyImageFile.jpg') . So image will be "
So where is the location of MyImageFile.jpg on the hard disk.
Please clarify.
  댓글 수: 2
TAB
TAB 2013년 1월 30일
편집: TAB 2013년 1월 30일
Offcourse on hard disk or on other secondary storage like USB stick flash memory. You can give the path also like
imread('C:\Documents\My Picture\MyImageFile.jpg')
on windows OS.
Raxeee
Raxeee 2013년 2월 3일
okay...thanks

댓글을 달려면 로그인하십시오.


Jonathan Siliézar
Jonathan Siliézar 2017년 10월 3일
Hi, thanks for the information, it was very helpful. Once I've loaded the .jpg image to the push button (I'm trying to create an icon with basic info for the user on how to use the program) the image is very large, how do I resize it to fit the push button's dimensions? Thanks in advance.

Sujith Roy
Sujith Roy 2018년 11월 15일
Can you adjust the position of the icon in the button?
This command works - imread('MyImageFile.jpg').
But how do I position the image to the left and then add some text on the button?

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by