How do I control the image size when printing to a file?
53 views (last 30 days)
Show older comments
I wanted to save a image of 1280 by 1080 to a file in the png format. The solution I found to do this, by reading the Matlab documentation was
% trick Matlab to save the file at correct size:
% set unit to inches
% set resolution at 100 dots/inch
% set X size to 12.8 -> image size will be 12.8*100 = 1280
% set Y size to 10.8 => image size will be 10.8*100 = 1080
set(gca,'position',[0 0 1 1],'units','normalized');
%set(gcf,'PaperUnits','inches','PaperPosition',[0 0 4.8 2.4]);
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 12.8 10.8]);
print(hF,'-dpng','-r100','out.png');
The code does not include the portion in which I generated an image of exactly 1280 by 1080 pixels. The problem is that the output image was 1281 by 1080. One pixel to many for the width. For smaller sizes, like 480 by 240 the output was of the required dimensions. But for 800 by 600 and for 1280 by 1080, the same problem: 1 pixel to many for the width.
Can this be solved in some manner? I need the output at exactly the resolution, one extra column is no good!
0 Comments
Answers (3)
Guillaume
on 30 Sep 2015
If the image you want to save is actually an image and not a figure (i.e. a 1280x1080 array of pixels and not a vector plot) then use imwrite.
0 Comments
See Also
Categories
Find more on Display Image in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!