How can I assign a GIF to a pushbutton?
1 view (last 30 days)
Show older comments
I need to assign a gif to a pushbutton in a MATLAB GUI. I am using GUIDE, and I have the gif. I would like to have the gif show on the pushbutton, then show an image displayed at random. Basically I have a gif of a dice rolling. I would like to hit the pushbutton, show the gif of the dice rolling, then any one of a die side. Thank you.
1 Comment
Answers (1)
Tony Mohan Varghese
on 21 Mar 2018
You cannot assign a gif image to a pushbutton using GUIDE. A true colour RGB image can be assigned to a push button.
To display an image on a GUI component, try these four steps:
1. Read in the image you want to be displayed on the component.
2. Make sure that it is a True Color Image.
3. Resize the image to fit on the component.
4. Create the component and set the 'cdata' property to be the image.
Below is a quick example of how to display an image on a pushbutton:
[x,map]=imread('ngc6543a.jpg');
I2=imresize(x, [42 113]);
h=uicontrol('style','pushbutton',...
'units','pixels',...
'position',[20 20 113+10 42+10],...
'cdata',I2)
If it is not a True color image, then you can use one of the conversion functions in the Image Processing Toolbox to convert it.
ind2rgb - Convert indexed image to RGB image.
isrgb - Return true for RGB image.
rgb2gray - Convert RGB image or colormap to grayscale.
rgb2ind - Convert RGB image to indexed image.
If you are using a GUIDE GUI and wish to modify an existing component that exists in the 'handles' structure, use the SET command to set the 'CDATA' property as shown below:
set(handles.pushbutton1,'cdata',I2);
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!