Re: imwrite png DPI



Simon Hilsenbeck wrote:
Hello,
using imwrite i want to save a png image with 300 DPI.

imwrite(rand(100,100),'dpiTest.png', 'png', 'XResolution',
300, 'YResolution', 300);

But the resolution specification seems to be ignored. The
file is saved with 96 DPI.

imagesc(rand(100,100)); print('-f1', '-r300', '-dpng',
'dpiTest.png');
This works, but i do not want the space around pictures,
common when images are displayed as figures.

How to save an image without border as png with 300 DPI?
Thank you.

Are you able to adjust the position of the axes so it fills more of the figure before printing it?

%create my figure
figure;
imagesc(rand(100,100));

%save current axes position
axpos = get(gca, 'position');

%expand axes to fill figure window
outerpos = get(gca, 'outerposition');
insetpos = get(gca, 'tightinset');
set(gca, 'position', [insetpos(1) insetpos(2) ...
outerpos(3)-insetpos(3) outerpos(4)-insetpos(4)]);

%create output file
print('-f1', '-r300', '-dpng','dpiTestx.png');

%restore axes position
set(gca, 'position', axpos);

If you didn't want the axes at all you could set the position to be [0 0 1 1] to completely fill the interior of figure window (assuming the units are normalized, of course)

--

Richard Quist
Software Developer
The MathWorks, Inc.
.



Relevant Pages

  • Re: imwrite png DPI
    ... that it doesn't work with imwrite? ... using imwrite i want to save a png image with 300 DPI. ... Are you able to adjust the position of the axes so it ... 'XResolution', dpm, ... ...
    (comp.soft-sys.matlab)
  • Re: imwrite png DPI
    ... that it doesn't work with imwrite? ... using imwrite i want to save a png image with 300 DPI. ... Are you able to adjust the position of the axes so it ... %save current axes position ...
    (comp.soft-sys.matlab)
  • imwrite png DPI
    ... using imwrite i want to save a png image with 300 DPI. ... But the resolution specification seems to be ignored. ...
    (comp.soft-sys.matlab)
  • Re: Help on Matlab GUIs
    ... I'm trying to display a .png image on a GUI figure i have created. ... I have tried to set the current axes using this command: ...
    (comp.soft-sys.matlab)