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

64 visualizaciones (últimos 30 días)
Jasmine
Jasmine el 9 de Ag. de 2012
Comentada: Adam Danz el 20 de Oct. de 2020
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 comentario
Adam Danz
Adam Danz el 20 de Oct. de 2020
Update: starting in r2020a uibuttons can also host animated GIF images and truecolor image arrays (examples).

Iniciar sesión para comentar.

Respuesta aceptada

TAB
TAB el 9 de Ag. de 2012
Editada: TAB el 9 de Ag. de 2012
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 comentarios
Lam Nguyen Van
Lam Nguyen Van el 19 de Abr. de 2020
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 el 19 de Abr. de 2020
I want to After that deleting the original image will not have any effect on your GUI.

Iniciar sesión para comentar.

Más respuestas (3)

Raxeee
Raxeee el 29 de En. de 2013
"he command imread('MyImageFile.jpg') . So image will be "
So where is the location of MyImageFile.jpg on the hard disk.
Please clarify.
  2 comentarios
TAB
TAB el 30 de En. de 2013
Editada: TAB el 30 de En. de 2013
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 el 3 de Feb. de 2013
okay...thanks

Iniciar sesión para comentar.


Jonathan Siliézar
Jonathan Siliézar el 3 de Oct. de 2017
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 el 15 de Nov. de 2018
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?

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by