is there any way to export the figure into an appropriates
graphic format for transparent background (MATLAB default is
white)?
The finale purpose is the import it into a power point
presentation using the ppt default slide background.
Thank you,
Bruno
using menu: Preferences -> Figure copy template -> Copy
options -> Check "transparent background" to on
Set the 'Color' property of all axes of the figure to 'none'
Use the menu 'Edit' -> 'Copy figure' to copy the graphic
into the clipboard, then past it to the powerpoint slide.
Bruno
> ...
> Use the menu 'Edit' -> 'Copy figure' to copy the graphic
> into the clipboard, then past it to the powerpoint slide
a note: you will get even better results if you do this
peaks(128);
print -dmeta -r400;
% - NO file name
% - -rX depends on your memory
% then paste into your app
just a thought
us
"Bruno Luong" <b.l...@fogale.fr> wrote in message <g2itg7$ino$1...@fred.mathworks.com>...
Yes. Download export_fig (http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig). Now try the following:
peaks;
set(gcf, 'color', 'none');
set(gca, 'color', 'none');
export_fig test.png
Now open test.png in your ppt presentation and voila! Not only anti-alised graphics (which are optional, btw), but also beautifully alpha-blended too. It even works with semi-transparent patches.
HTH,
Oliver
Figure Color needs to bet set to 'none', did you do that?
Bruno
In the case of xy plots, the culprit is likely the renderer used to display the plot, which is chosen automatically by Matlab based on the data being displayed. The "painter" that is likely being used for your xy plots does not respect transparency settings. See the following link for a description of the renderers in Matlab.
http://www.oit.uci.edu/dcslib/matlab/matlab-v60/help/techdoc/printing/printfi2.html
Fortunately, the rendering engine can be changed on the fly by the user. Here's what I used, with success, to export plots to PowerPoint using the actxserver:
% Setup the plot & figure properties prior to export
set(gcf,'renderer','OpenGL'); % Sets renderer to OpenGL
set(gcf,'color','none');
set(gcf,'color','none');
print -dmeta -r400; % copy figure to clipboard in metafile format at quality of 400
% Now export to ppt (assumes a ppt slide handle named "newSlide" has already been created) and set transparency
imageObject = invoke(newSlide.Shapes,'paste'); % paste clipboard image to ppt
set(imageObject.PictureFormat,'TransparentBackground','msoTrue');
set(imageObject.PictureFormat,'TransparentColor','16777215'); % Set transparency color to while
set(imageObject.Fill,'Transparency',1);
set(imageObject.Fil,'Visible','msoFalse');
As I said, the above worked for me, though this was after extensive experimentation so some of the above lines may not be necessary. Feel free to experiment with the above, especially if you want to change what color is white.
In the case of xy plots, the culprit is likely the renderer used to display the plot, which is chosen automatically by Matlab based on the data being displayed. The "painter" that is likely being used for your xy plots does not respect transparency settings. See the following link for a description of the renderers in Matlab.
I sincerely wish TMW would make this feature WISIWYG at *some* point! I ended up just using the white-background in my presentation, which is NOT what I wanted AT ALL. :-(
Bummed....
Matt, I'd be grateful if you could email me the figure so I can take a look. It's useful to have failure cases.
Also, I suggest you try using export_fig with the zbuffer and painters renderers if it's not working well with the default (opengl for bitmaps). Just pass in the option -zbuffer or -painters. Make sure you have the latest version of export_fig though, as this functionality was only added recently.
Oliver
Thanks,
Claus
"Paul Shoemaker" <psho...@hotmail.com> wrote in message <hf6cec$ml7$1...@fred.mathworks.com>...
Will do Oliver. I will have to change some things on the plot before I can let you see it (I am sure you understand that!), so I might not get to it till later. Also, I was using the latest version because I just downloaded it two days ago.
Matt
Claus, I will post the code you requested when I return to the office
next Tuesday. Yes, it is possible to paste multiple figures to ppt as
you go along by using the actxserver functionality in Matlab.
A totally different approach...
I've always just saved the image with the default white background and then in the picture toolbar in PowerPoint you can set a transparent colour by pushing the button in the menu and then clicking on an area of the image which is the colour you want to make transparent.
It works for me, and seems a little simplier than some of the suggestions here.
Downsides to this are that you get non-anti-aliased bitmap graphics, you can't have semi-transparent patches over a transparent background, and also any objects that are the same colour as the background will be made transparent too.
Also, you're saving to png (or other bitmap), then opening it in powerpoint, then setting the transparent colour. If you switch to printing to png using export_fig (my approach: export_fig out.png) then you miss out the last step. If you follow Us' approach (print -dmeta -r400) it's even easier as you don't need to open a file - just paste.
Oliver
I agree your method is proably better. It's just that mine is easier and is usually ok quality wise for me.
>
> Oliver
Claus,
As promised, here is the code to paste to ppt. The approach I outline allows you to paste to ppt without having to save figure as file and also sets the transparency for you automatically. This is helpful for jobs that export a large number of figures. Note that the below code is very stripped down. You could easily modify it to paste to existing ppt or the currently open ppt. Also, you could put the image editing portion in a for loop to paste multiple images, even multiple per page, with ease.
Also, note that this requires that the user has Office installed on their machine. In my testing, it seems to work with both Office 2003 and 2007.
[myFile myPath] = uiputfile('*.ppt','Create New PPT File'); % New ppt file. Modify if you want to append to existing. Remove if you want to use current active presentation (see exportPreso comment below)
filename = fullfile(myPath,myFile);
pptserver = actxserver('PowerPoint.Application'); % create ppt actx server
exportPreso = invoke(pptserver.Presentations,'Add'); % Open new presentation. To append to existing ppt, use 'open'. To append to currently active ppt, use exportPreso = get(pptserver,'ActivePresentation');
slideCount = get(exportPreso.Slides,'Count'); % Get page count of preso
slideCount = int32(double(slideCount)+1); % find the 'next' preso page
newSlide = invoke(exportPreso.Slides,'Add',slideCount,11); % create new slide
slideWidth = get(exportPreso.PageSetup,'SlideWidth'); % get slide width
slideHeight = get(exportPreso.PageSetup,'SlideHeight'); % get slide height
set(newSlide.Shapes.Title.TextFrame.TextRange,'Text',' '); % set slide title to blank
% Example plot below. For export of multiple plots, the below should be put in a for-loop. To
% paste multiple figures to each slide, modify the image size and position
% accordingly)
figure
plot(1:.1:10,sin(1:.1:10));
oldPosition = get(gca,'position');
oldRenderer = get(gcf,'renderer');
oldGCFcolor = get(gcf,'color');
oldGCAcolor = get(gca,'color');
set(gca,'position',get(gca,'outerposition')-get(gca,'tightinset')*[-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]); % make plot image 'tight' and remove whitespace. Seems to behave differently in Office 2007
set(gcf,'Renderer','OpenGL'); % change renderer to openGL
set(gcf,'color','none');
set(gca,'color','none');
print(gcf,'-dmeta','-r400'); % copy figure image to clipboard in meta format
set(gca,'position',oldPosition); % change figure properties back
set(gcf,'Renderer',oldRenderer);
set(gcf,'color',oldGCFcolor);
set(gca,'color',oldGCAcolor);
imageObject = invoke(newSlide.Shapes,'paste'); % page image to the new slide
set(imageObject.PictureFormat,'TransparentBackground','msoTrue'); % Set picture to transparent
set(imageObject.PictureFormat,'TransparencyColor','16777215'); % Set whites to be transparent
set(imageObject.Fill,'Transparency',1); % Fill is transparent
set(imageObject.Fill,'Visible','msoFalse'); % make fill invisible
set(imageObject,'width',0.8*slideWidth); % set size of pasted image
imageWidth = get(imageObject,'width');
imageHeight = get(imageObject,'height');
imageTop = 1.2*(slideHeight-imageHeight)/2;
imageLeft = (slideWidth-imageWidth)/2;
set(imageObject,'Top',imageTop,'Left',imageLeft); % set position of image in ppt
invoke(exportPreso,'SaveAs',filename,1); % Assumes new file. Modify to use an existing file. Remove if pasting to currently active preso
invoke(exportPreso,'Close'); % Remove if pasting to currently active preso