How to print figure to clipboard by PRINT function with the quality identical to 'Edit-->Copy Figure' option?

StackOverflow https://stackoverflow.com/questions/4453639

  •  10-10-2019
  •  | 
  •  

Question

Is there any way to print the figure to the clipboard so that the quality is identical to what the Edit-->Copy Figure option provides?

I used to save the figure to powerpoint file by using saveppt.m obtained from Matlab Central. It worked well until yesterday. I noticed that the stored image quality was somehow degraded. I tried to re-generate some ppt slides with exactly the same script and the same source data, but the new slides are simply of worse quality.

I investigated into this problem a little bit and discovered that when the figure is copied to clipboard by running print -dmeta, the image in the clipboard is already degraded, while if I use the Edit-->Copy Figure option in the figure window, I get the image as clear as the original image in the figure window.

Following is an example for your reference. I copied the image from a figure to the clipboard by two different methods, and paste it to Microsoft Paint program, and cut a piece of it to show below:

The image using print -dmeta: stored figure using "print -dmeta"

The image using Edit-->Copy Figure: stored figure using "Copy Figure"

If you compare the Xtick label '50', you may see that the image from Edit-->Copy Figure is smoother.

At the beginning I thought it was a problem of the resolution, but setting -rN to change the resolution does not seem to resolve my problem, at least not for N<=300.

Thank you for your help.

Was it helpful?

Solution 2

I think I found the answer myself. Using print -dmeta -painters to specify the renderer resolves my problem.

In File-->Preference-->Figure Copy Template-->Copy Option I noticed there are 3 options:

  1. Metafile
  2. Preserve information
  3. Bitmap

I found that if I select 1, the Edit-->Copy Figure outputs the same image as print -dmeta. So I kind of confirmed the information I need is in the Preserve information option. A quick google search led me to the discussion about the potential difference of the applied renderer, and eventually I confirmed that using painters will print the image to the clipboard in the way I wanted.

The image in the question seems to be generated by the renderer zbuffer and painters, respectively. I still don't know why the default renderer of paint -dmeta changes, though.

OTHER TIPS

The short answer... Use the same function invoked in the callback for that menu item:

editmenufcn(gcf,'EditCopyFigure');


The longer answer... How exactly did I find this? You can look at my previous answer to a related question about reproducing what is done by a File menu option. The concept is the same, just for a different figure menu. For example, this will find the callback you want for the currently active figure window:

>> hCopyFigure = findall(gcf,'Label','Copy &Figure');  %# Handle for the "Copy
                                                       %#   Figure" menu item
>> get(hCopyFigure,'Callback')  %# Callback invoked when that item is selected

ans =

editmenufcn(gcbf,'EditCopyFigure')

The function EDITMENUFCN is another one of those sparsely documented functions, but looking through the code (by typing edit editmenufcn.m) shows that it either invokes Java (if you're on a Mac) or the undocumented function UIMENUFCN.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top