saving png with the correct format (legend)
14 views (last 30 days)
I am saving .fig to .png using saveas. I can't get the png output looks exactly like what the .fig shows on the screen. I have tried the set the .fig size to 1200 by 900 before saving, but the png output still looks like the default size. So the legend ends up taking 1/3 of the png space, and became a useless chart for me.
bmp works, but it saves too slow so when I automate the process to save many plots, it doesn't work. Plus, the size of file is too big.
I have been struggling with it for awhile, assistance will be appreciated
Shaun VanWeelden on 19 Apr 2013
Also, check out any screenshot mfiles, most will figure out the position of the figure if you give it the figure handle. They will take a screenshot of exactly what is on the screen, just like pressing the "print screen" button on your keyboard would do, but just for the figure window.
One version on the FEX is here: http://www.mathworks.com/matlabcentral/fileexchange/24323-screencapture-get-a-screen-capture-of-a-figure-frame-or-component
My version I have used is here: (and if I remember correctly, you can just give it the values returned by get(fHandle,'position') for the rect. and it should work.
function [img] = getScreenShot(rect)
%example rect: [200 300 600 400]
%This could use a LOT of improvement!
%they used normalized units
rect([1 3])=rect([1 3]).*width;
rect([2 4])=rect([2 4]).*height;
rect([1 3])=min(rect([1 3]),width);
rect([2 4])=min(rect([2 4]),height);
robo = java.awt.Robot;
image = robo.createScreenCapture(target); %take screenshot at rect
rasta=image.getRGB(0,0,width,height,,0,width); %get RGB data from bufferedimage