IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
save_as_png.m
Go to the documentation of this file.
1 %>@file
2 %>@ingroup graphicsapi ioio
3 %>@brief Saves PNG
4 %
5 %> @param h =gcf() Handle to figure
6 %> @param fn =(new) File name
7 %> @param dpi =0 Dots Per Inch = resolution. 0 = screen resolution
8 function save_as_png(h, fn, dpi)
9 
10 pause(0.1); % It may be work to let MATLAB get sorted before saving
11 
12 if nargin < 1 || isempty(h)
13  if is_2014' % Working around changes starting from R2014a
14  f = gcf();
15  h = f.Number;
16  else
17  h = gcf();
18  end;
19 end;
20 if nargin < 2 || isempty(fn)
21  fn = find_filename('irr_figure', [], 'png');
22 end;
23 if nargin < 3 || isempty(dpi)
24  dpi = 0;
25 end;
26 
27 % This did the trick!!! Saving beautifully now
28 set(h, 'PaperPositionMode', 'auto', 'Units', 'pixels');
29 
30 print(['-f', int2str(h)], '-dpng', ['-r', int2str(dpi)], '-opengl', fn);
function save_as_png(in h, in fn, in dpi)
function is_2014()
function find_filename(in prefix, in suffix, in extension, in flag_return_ext)