开发者

Display image using GUI MATLAB in a specific region

I'm looking for how can I display an image in my GUI in a specific region of my interf开发者_高级运维ace.


In GUIDE, you can draw axes into the GUI. Then, in a callback function, you can plot an image into the axes.

Personally, I would rather not have the image inside the GUI, because it makes it harder to resize everything properly, and if you want to have a closer look at the image, or capture it to paste into another application, having the figure as part of the GUI can be inconvenient. Thus, I prefer to have the image open in a separate figure window.


Try the following code:

function movingimage
    %# Plotting a figure
    fig1=figure('Name','Plotting an image',...
        'Unit','normalized', 'Position',[.1 .1 .8 .8]);
    uicontrol(fig1,'Style','text','Unit','Normalized',...
        'Position',[.9 .85 .1 .07],'String','Press the button below to move the image location.');
    uicontrol(fig1,'Style','pushbutton','Unit','Normalized',...
        'Position',[.9 .8 .05 .05],'String','Move','Callback',{@action_Callback});

    %# Say, you wish to plot an image of relative dimension (.3 x .3) to the figure.
    xdim=.3; ydim=.3;
    %# Image's movable range in x is (1 - xdim)
    dx=1-xdim;
    %# Image's Movable range in y is (1 - ydim)
    dy=1-ydim;
    %# considering the size of the image...
    pos = [.5*dx .5*dy xdim ydim];  %# Initial location of the image is at the center of the figure.
    ax1 = axes('position',pos);
    img = load('mandrill');
    image(img.X)
    colormap(img.map);axis off;axis equal;

    function action_Callback(hObj,eventdata)
        pos=[rand(1)*dx rand(1)*dy xdim ydim];
        set(ax1,'position',pos);
    end
end


The most direct and easy way I find to do this is to use the Axis component as shown in this tutorial:

http://www.aboutcodes.com/2012/06/how-to-display-image-in-gui-using.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜