搞定,花了半个小时看了 imshow 函数,其实既然 figure 行,那你就应该 edit imshow 看看它里面的玄机。我把重要的部分抽取了出来,通用性方面当然是不如 imshow 函数的了,你将就一下吧:-
- A = imread(yourfilename);
- im_handle = imshow(A);
- set(handles.axes1, 'Units', 'pixels'); %这个是关键,我没有想到要先进行设置
- ax_pos = get(handles.axes1, 'Position');
- image_width = size(get(im_handle, 'CData'),2);
- image_height = size(get(im_handle, 'CData'),1);
- set(handles.axes1, 'Position', [ax_pos(1), ax_pos(2), image_width, image_height]);
复制代码 以上适合 fig 文件方式的GUI 程序,m文件方式的 GUI 自己修改一下句柄即可。事实上,上述代码实现了 non stretch-to-fill behavior,即 autosize 的功能
[ 本帖最后由 eight 于 2008-4-22 11:20 编辑 ] |