Saving an axes as jpg file using saveas
Afficher commentaires plus anciens
Hallo All
I have been trying to save an axes object on an gui as jpg file but it takes up weird pictures, like sometime the photo has only the centre part of the axes and sometimes it doesn't save the picture of the axes at all instead it takes picture of the pushbuttons besides the axes (in the GUI). Have been trying to set this error for a long time.
Thanks a lot.
Réponse acceptée
Plus de réponses (1)
Prajwol Tamrakar
le 6 Oct 2023
When using App Designer and you do not have the latest version 2020 or later, it is literally IMPOSSIBLE to save an image from the figure (app.UIAxes). It seems easy previously (of course easy when using GUIDE or just simple code, but Not for App Designer 2019a version). I wasted lots of hours trying to find a solution for this. The best solution ever found was - just get the screen short using the following code.
SOURCE and FULL Credit: https://www.mathworks.com/matlabcentral/answers/362358-how-do-i-take-a-screenshot-using-matlab
% Take screen capture
robot = java.awt.Robot();
pos = [0 0 400 400]; % [left top width height]
rect = java.awt.Rectangle(pos(1),pos(2),pos(3),pos(4));
cap = robot.createScreenCapture(rect);
% Convert to an RGB image
rgb = typecast(cap.getRGB(0,0,cap.getWidth,cap.getHeight,[],0,cap.getWidth),'uint8');
imgData = zeros(cap.getHeight,cap.getWidth,3,'uint8');
imgData(:,:,1) = reshape(rgb(3:4:end),cap.getWidth,[])';
imgData(:,:,2) = reshape(rgb(2:4:end),cap.getWidth,[])';
imgData(:,:,3) = reshape(rgb(1:4:end),cap.getWidth,[])';
% Show or save to file
imshow(imgData)
imwrite(imgData,'out.png')
Catégories
En savoir plus sur Printing and Saving dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



