Matlab Production Server and saving images

3 次查看(过去 30 天)
Have have a working Matlab Production Server (MPS) environment that is being used to generate images that can be transferred to another computer (not the MPS). In particular, we are trying to make an image that is appropriately sized for an 8.5" by 11" letter paper size to be printed once it gets transferred.
We currently use the following syntax to build the figure (Note, this is the same syntax that I have used for ~10 years to make high resolution print figures to scale for academic publishing.)
GUISize = [11 8.5]*2.54;
hObject = figure;
set( hObject , 'Tag' , 'Figure_Tag' , ...
'Toolbar' , 'none' ,...
'MenuBar' , 'none' ,...
'Units' , 'normalized' ,...
'Position' , [0.1 0.1 0.9 0.9] ,...
'PaperType' , '<custom>' ,...
'PaperOrientation' , 'landscape' ,...
'PaperPositionMode' , 'auto' ,...
'PaperUnits' , 'centimeters' ,...
'PaperSize' , GUISize ,...
'Color' , [1 1 1] ,...
'Resize' , 'off' ,...
'NumberTitle' , 'off' ,...
'Renderer' , 'zbuffer' ,...
'Visible' , 'on' );
set( hObject , 'Units' , 'centimeters' );
set( hObject , 'Position' , [0 0 GUISize(1) GUISize(2)] );
I remove toolbars and menubars. Then the figure is positioned within the bounds of the monitor uing the 'Units' and 'Position' properties. I then set the paper to the appropriate size (11" by 8" in landscape mode). I use centimeters for scaling the figure correctly so I have to multiply by the 2.54 factor. This then makes the figure - hObject - that I can use in subsequent steps.
I then separately set the Units back to centimeters and then make the Position match the paper size. The intention here is that everything in the figure should get printed with the appropriate margins, spacing, fontsize, etc., if everything is drawn the figure to scale. (Once again, I've used this syntax for academic publishing for 10+ years so I know this works. If I want a figure that 3" wide by 4" high, I get a 3" wide figure by 4" high...)
Matlab has a gajillion ways to print figures to file. I am looking to print this figure to a *.png file with fairly high resolution (300 DPI). At 11" by 8.5", this should be a figure that is 3300x2550x3 (when converted to a matrix RGB image.
Using print
file01 = fullfile( pwd , 'Image01.png' );
print( file01 , '-r300' , '-dpng' );
This command prints the current figure (gcf) to file. Variable file01 is a fullfile string to where the image should be saved.
Using exportgraphics
file02 = fullfile( pwd , 'Image02.png' );
exportgraphics( hObject , file02 , 'Resolution' , 300 );
This command uses the exportgraphics function on the hObject and saves the file to file02 (which is a fullfile string).
Using saveas
file03 = fullfile( pwd , 'Image03.png' );
saveas( hObject , file03 )
This command uses the saveas command to save hObject to file. Once again, file03 is a fullfile string.
In the first two cases, when I run the code locally on my machine (Matlab 2020A 64-bit), I get what I expect, which is PNG images with the appropriate dimensions (3300 by 2550). When I run the third one, I get a 1650 by 1275 which is 150 DPI. This matches my screen resolution from my graphics cards and monitor, etc. In all three cases, the image are whole and nothing is cropped or cut off.
When I run the code on the MPS, I get a different story. The images end up being slight smaller, 3212 (W) by 2341 (H) pixels for the first two instances and 1606 by 1170 for the saveas instance. Also, the images have sections that are cropped, specifically on the top and right sides. The left side and bottom appears to have the same margins as the desired image.
Other things:
  • Please do not ask "why not just make the image smaller with smaller resolution". 1) this doesn't get to the heart of the matter as why my computer and the MPS running the same code gives different answers. 2) the purpose of this is to ultimately get an 11" by 8.5" printout that contains a ton of information that must be contained on one sheet of paper. To print the information correctly, I need spacing and size tightly controlled, hence making it to scale. I CANNOT shrink the image any more to account for it getting cropped.
  • The image includes a 1 cm margin on all sides to account for the printing border. I do not believe the issue is that I am trying to print a photo on a non-photo printer type of issue.
  • When I generate the image on my local machine and then transfer it to the machine that connects to the MPS and also the printer, and then use the same print driver (to the physical printer, not the MPS), I get the appropriate printout with correct margins and no cropping. So I know the correct image will be printed correctly but the MPS appears to be generating the incorrect image.
I have the following questions:
  1. How can I generate image files on the MPS so that they are both high resolution and do not get cropped in the printing/saving process? Other options like imwrite do not work (near as I can tell) because I need to use that with getframe or something else and I sacrifice resolution when I do this.
  2. Why would the MPS crop an image when that same image and same code doesn't get cropped on my local machine?
  3. How do I adjust printer settings on the MPS? I tried the same sequence and made PDF files and I got the same thing! Locally, my files are fine and high resolution. On the MPS, the images get cropped on the top and right side. Also, sometimes the high resolution is not maintained (grainy images/files). I suspect that this might be the culprit because it does this for both the PNG and the PDF files, suggesting it is some printer resolution thing.
  4. is there some other aspect that I am missing?
Any help is greatly appreciated.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by