How to change the size of an image loaded into the push button automatically when the window size of a GUI(GUIDE) changes.
5 ビュー (過去 30 日間)
古いコメントを表示
Hello, I'm new to GUI. I am creating an user interface in GUI fusing GUIDE. I would like to include a fancy ''close'' image into the push button such that when I push the GUI should close. I successfully imported using property ''CData''. I am using the GUI size to proportional. I adjusted several times adjusting the size of push button and later when I resize the GUI the size of push button is changing automatically but not the image. Do I need to implement new function for this? Would you please suggest something on this code? I am attaching the image,code GUI, script file.
I need help and it's urgent.
0 件のコメント
採用された回答
Image Analyst
2013 年 12 月 6 日
Make sure the 'Units' property of all the controls on your GUI is set to 'Normalized'.
0 件のコメント
その他の回答 (1 件)
Anil Turkkan
2015 年 12 月 3 日
I don't think changing units property will do anything on buttons. If you display an image using an axis, the image will be scaled as you change the GUI size. However, if you attach an image to a button, you need to use SizeChangedFcn callback of your GUI. My GUI has 4 buttons with images attached and this is how I do the scaling:
% --- Executes when mainGUI is resized.
function mainGUI_SizeChangedFcn(hObject, eventdata, handles)
% hObject handle to mainGUI (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%image and button list
images={'newButton.jpg','loadButton.jpg','prbOptimizerButton.jpg','help.png'};
buttons={'newButton','loadButton','prbButton','helpButton'};
for i=1:length(images)
%read the images
if isempty(strfind(images{i},'png'))
images{i}=imread(images{i});
else
images{i}=imread(images{i},'BackGroundColor',[0.961 0.98 0.98]);
end
%get the button new button sizes and resize images accordingly
handles.(buttons{i}).Units='pixels';
images{i}=imresize(images{i},fliplr(handles.(buttons{i}).Position(1,3:4)));
handles.(buttons{i}).Units='normalized';
handles.(buttons{i}).CData=images{i};
end
I stored image and button names in a cell array so I don't need to write the same code for all buttons. First, I read the image file and store in the same cell array. We can then resize the image according to the new button size and attach the new scaled image to the button.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!