How to print axes area on GUI?
Mostrar comentarios más antiguos
1. Axes on the GUI-window (not figure) 2. GUI-win property "Resizable=on" maybe set 3. I need to obtain jpg or bmp file with only axes area (plus annotations&title) at actual screen size. By simple way... 4. It's better to don't change GUI-win properties.
My attempts, 3 ways
function bmp_Callback(hObject, eventdata, handles)
% hObject handle to bmp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h=handles.axes1;rect=get(h,'OuterPosition');
photo=getframe(h,rect);[photo,cmp]=frame2im(photo);
imwrite(photo,'photo2.jpg','jpg','Quality',80);
beep;
% --------------------------------------------------------------------
function jpg_Callback(hObject, eventdata, handles)
% hObject handle to jpg (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
saveas(handles.output,'photo.jpg');
print('photo1','-noui','-djpeg','-r200');
beep;
1 comentario
Igor
el 27 de Mayo de 2011
Respuestas (2)
Matt Fig
el 27 de Mayo de 2011
This works on my computer, you may have to tweak a few things.
close all
figure('units','pix','pos',[200 200 850 750])
ax = axes;
plot((1:10).^2)
set(ax,'units','pix')
legend('x^2')
xlabel('X Label','fontsize',12)
ylabel('Y Label','fontsize',12)
title('Title','fontsize',24)
drawnow
% Now capture the axes and labels.
P = get(ax,'pos');
T = get(ax,'tightinset');
h = [P(1)-T(1)-5 P(2)-T(2)-5 P(3)+P(1)/2+T(3)+15 P(4)+P(2)/2+T(4)+10];
F = getframe(gcf,h);
[X,Map] = frame2im(F);
% I put the funny background color so the captured area stands out.
figure('color',[.6 .2 .2],'units','pix','pos',[26 33 1184 925])
image(X)
set(gca,'visible','off')
axis normal
imwrite(X,'myimage.jpg') % save the image.
2 comentarios
Igor
el 28 de Mayo de 2011
Matt Fig
el 28 de Mayo de 2011
I was using the figure frame of reference and you were using the axes. Both can be made to work, with some adjustment.
I see now what you did, and I think you could make it work. Try modifying your code to this:
rect = get(h,'Position');
drect = get(h,'TightInset');
rect([3 4]) = rect([3 4]) + drect([3 4]) + rect([1 2])/2 +dh;
rect([1 2]) = - drect([1 2]) + dh;
That should work...
Walter Roberson
el 27 de Mayo de 2011
0 votos
I suggest you consider the MATLAB File Exchange contribution export_fig written by Oliver.
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!