printpreview Not Displaying Desired Dimensions
2 次查看(过去 30 天)
显示 更早的评论
Hello! I've got an image I'd like to print on letter paper with a width of 25.4 cm, and a height of 21.2 cm (the 2D array is 212 x 254 elements, so I'd like each element to take up a millimeter of space on printed paper). I'm using the printpreview function to take a look at the image before I print it, and the Layout and Paper sections seem to have the specifications I'm looking for, but the image does not appear to be the size I'd like it to be. To overexaggerate, I changed the figure dimensions to be something larger than the size of the paper itself, but the software seems to be handling it just fine. What should I do so that the image fits the dimensions I specify?
0 个评论
回答(1 个)
Yatharth
2024-5-29
Hi Isabella,
To acheive the specific image fit, you will need to make sure the figure's size and the image's aspect ratio are correctly configured.
Here is how you can acheive it:
1. Setting up the figure sizes
width_cm = 25.4; % The desired width in cm
height_cm = 21.2; % The desired height in cm
width_in = width_cm / 2.54; % Convert width from cm to inches
height_in = height_cm / 2.54; % Convert height from cm to inches
figure;
set(gcf, 'Units', 'inches', 'Position', [0, 0, width_in, height_in]);
imgData = rand(212, 254); % Example image data
imshow(imgData, 'InitialMagnification', 'fit'); % Display the image
axis on; % Show axes, which you might want to turn off with 'axis off'
2. Adjusting the Axes and Figure
set(gca, 'Unit', 'normalized', 'Position', [0 0 1 1]); % Make axes fill the figure
set(gcf, 'PaperPositionMode', 'auto'); % Match printing to figure size
3. Saving the image and viewing it using "printpreview" function
Note: Given that 1 inch = 25.4 mm, and you want each pixel to correspond to 1 mm, a resolution of 25.4 DPI should theoretically give you 1 pixel per mm. However, printers and viewing software might handle this differently, so you may need to adjust this value.
% To save to a file, for example, a PNG
dpi = 25.4; % Dots per inch for 1 pixel per mm
print('-dpng', '-r25.4', 'MyImage.png'); % Adjust filename and format as needed
printpreview()
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!