2014-04-02 1 views
1

이 코드에 단추를 추가하면 창을 닫고 그림을 회전시킬 때 그림을 저장할 수 있습니다. 여기 저기 몇 가지 해킹으로GUI에 단추를 추가하는 방법

function rotationGUI(a) 
    I = imread(a); 

    %# c 
    hFig = figure('menu','none'); 
    hAx = axes('Parent',hFig); 

    uicontrol('Parent',hFig, 'Style','slider', 'Value',0, 'Min',0,... 
     'Max',360, 'SliderStep',[1 10]./360, ... 
     'Position',[150 5 300 20], 'Callback',@slider_callback) 
    hTxt = uicontrol('Style','text', 'Position',[290 28 20 15], 'String','0'); 
    %# show image 
    imshow(I, 'Parent',hAx) 
    %# Callback function 
    function slider_callback(hObj, eventdata) 
     angle = round(get(hObj,'Value'));  %# get rotation angle in degrees 
     imshow(imrotate(I,angle), 'Parent',hAx) %# rotate image 
     set(hTxt, 'String',num2str(angle))  %# update text 
    end 
function ok_Callback(hObject, eventdata, handles) 
set(hTxt, 'String','save') 
end 

end 

답변

1

은, 여기 간다 -

주요 기능

function rotationGUI(a) 
I = imread(a); 

%# c 
hFig = figure('menu','none'); 
hAx = axes('Parent',hFig); 

hTxt = uicontrol('Style','text', 'Position',[290 28 20 15], 'String','0'); 
uicontrol('Parent',hFig, 'Style','slider', 'Value',0, 'Min',0,... 
    'Max',360, 'SliderStep',[1 10]./360, ... 
    'Position',[150 5 300 20], 'Callback',{@slider_callback,I,hAx,hTxt,hFig}) 

uicontrol(hFig,'Style','pushbutton','String','Save and Close',... 
    'Position',[10 20 120 40],'Callback',{@ok_Callback,I,hTxt,hFig}); 

%# show image 
imshow(I, 'Parent',hAx) 
%# Callback function 

return; 

관련 기능 -1

function slider_callback(hObj, eventdata,I,hAx,hTxt,hFig) 

global Irot 
angle = round(get(hObj,'Value'));  %# get rotation angle in degrees 
Irot = imrotate(I,angle); 
imshow(Irot, 'Parent',hAx) %# rotate image 
set(hTxt, 'String',num2str(angle))  %# update text 

return; 

Associ ated에 기능 -2

function ok_Callback(hObj, eventdata,I,hTxt,hFig) 

global Irot 

set(hTxt, 'String','save') 

[filename, pathname] = uiputfile('*.jpg', 'Save Image as'); 
imwrite(Irot,strcat(pathname,filename)); 

delete(hFig); 
return; 

편집 1 : -

편집 기능 rotationGUI -

원본 이미지로 회전 된 이미지를 저장하고 싶은 경우에, 그것은 이러한 변경을 사용하여, 그것을 덮어이다
uicontrol(hFig,'Style','pushbutton','String','Save and Close',... 
    'Position',[10 20 120 40],'Callback',{@ok_Callback,I,hTxt,hFig,a}); 

편집 기능 ok_callback -

function ok_callback(hObj, eventdata,I,hTxt,hFig,path1) 

global Irot 

set(hTxt, 'String','save') 
imwrite(Irot,path1); 

delete(hFig); 
end 
+0

tnx friend !!! :) – Sportac

+0

@ user2347210 함수를 끝내는 좋은 방법은'END' 대신'RETURN'을 사용하는 것입니다. – Divakar

+0

그리고 만약 내가 원래의 그림에 내가 바꿀 필요가있는 것을 저장하고 싶다면? – Sportac