matlab how custom background image

Copyright: Reprinted indicate the source https://blog.csdn.net/qq_43157190/article/details/88904895

When we use the following code is run after the command line may be generated a pushbutton

figure
a=uicontrol('parent',gcf,'style','pushbutton',...
    'String','哈','position',[10 270 30 30],...
    'backgroundcolor',[1 1 1],...
    'foregroundcolor',[0 0 0],'fontsize',12,...
    );


string text editing key is used to
position in the figure is used to specify the position and size of
the type specified control style

If we need to change the key code required background image is as follows:

   home=imread('home.jpg'); % home.jpg 是想要的图标
   set(GUI.home,'cdata',home);    %GUI.home 是想要更改的控件
   

FIG Effect:

CDATA uicontrol is a property used to store color data, it is to be noted that, CDATA must be true color data, that is, each pixel has three RGB data, but can not be a grayscale image, a two-dimensional grayscale image data but the three-dimensional data as true color images.

For example:

reading a true color image, which can be seen as a three-dimensional storage array (double type), and now we look at the storage grayscale:

the picture thought of as a matrix of 30 × 30 pixels, originally it has three double-data represents the color at each pixel, when it is converted into grayscale data into a three double-data representing a gradation according to a formula. Cdata This data can not be used.

Guess you like

Origin blog.csdn.net/qq_43157190/article/details/88904895