printpreview Not Displaying Desired Dimensions

2 visualizaciones (últimos 30 días)
Isabella
Isabella el 17 de Mayo de 2024
Respondida: Yatharth el 29 de Mayo de 2024
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?

Respuestas (1)

Yatharth
Yatharth el 29 de Mayo de 2024
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()

Categorías

Más información sobre Printing and Saving en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by