フィルターのクリア

Axes box incompletely copied to clipboard

5 ビュー (過去 30 日間)
Matt J
Matt J 2022 年 9 月 1 日
移動済み: Matt J 2023 年 3 月 23 日
I am trying to put a red box around an image, like the following, and then copy/paste into a PowerPoint file.
imagesc(ones);hax=gca;
set(hax.XAxis,'Color','r','LineWidth',8)
set(hax.YAxis,'Color','r','LineWidth',8);
xticks([]);
yticks([]);
When rendered in a Matlab figure window, it looks fine. However, when I copy it to PowerPoint using,
copygraphics(gcf, 'BackgroundColor', 'none', 'ContentType', 'vector');
or just the Copy Figure option from the figure Edit menu, the copied figure has a small chunk missing from the upper-left corner. Is there a remedy for this?
  2 件のコメント
Matt J
Matt J 2022 年 9 月 2 日
移動済み: Matt J 2023 年 3 月 23 日
export_fig from the File Exchange seems to be able to copy the figure gracefully to the clipboard.
imagesc(ones);hax=gca;
set(hax.XAxis,'Color','r','LineWidth',6)
set(hax.YAxis,'Color','r','LineWidth',6);
xticks([]);
yticks([]);
axis image
export_fig(hax,'-transparent','-clipboard')
Matt J
Matt J 2022 年 9 月 2 日
移動済み: Matt J 2023 年 3 月 23 日
Unfortunately, figure transparency is not preserved with the -clipboard switch :-(

サインインしてコメントする。

採用された回答

Yair Altman
Yair Altman 2022 年 12 月 4 日
移動済み: Matt J 2023 年 3 月 23 日
@Matt J export_fig(gcf,'-transparent','-clipboard') v3.28 now supports figure transparency for image fomats as well as EMF (where transparency was already supported in previous releases).
Please report export_fig issues on GitHub from now on, not in a FEX or Answers comment - I nearly missed this and only saw it by chance.
  1 件のコメント
Matt J
Matt J 2022 年 12 月 4 日
移動済み: Matt J 2023 年 3 月 23 日
Great news, Yair!

サインインしてコメントする。

その他の回答 (1 件)

Kevin Holly
Kevin Holly 2022 年 9 月 2 日
移動済み: Matt J 2022 年 9 月 2 日
Have you tried getframe?
h = getframe(hax)
Image = h.CData;
You can save the Image to PowerPoint as shown below (Note, you will need to adjust the placement and size of the image within the PowerPoint):
%% Open PowerPoint as a COM Automation server
h = actxserver('PowerPoint.Application')
uiwait(msgbox('Select folder to save PowerPoint'))
folder = uigetdir;
% Show the PowerPoint window
h.Visible = 1;
h.Help
%% ADD PRESENTATION
% View the methods that can be invoked
h.Presentation.invoke
% Add a presentation via "Add" method
Presentation = h.Presentation.Add
%% ADD SLIDES
% View the methods that can be invoked
Presentation.Slides.invoke
% Add a slide via "Add" method
% IF USING OFFICE 2003, use these commands:
% % Slide1 = Presentation.Slides.Add(1,'ppLayoutBlank')
% % Slide2 = Presentation.Slides.Add(2,'ppLayoutBlank')
% IF USING OFFICE 2007, use these commands:
blankSlide = Presentation.SlideMaster.CustomLayouts.Item(1);
Slide1 = Presentation.Slides.AddSlide(1,blankSlide);
Slide2 = Presentation.Slides.AddSlide(1,blankSlide);
%% GENERATE MATLAB IMAGES
figure;
image(Image)
print('-dpng','-r150',fullfile(folder,'test1.png'))
%% ADD IMAGES TO SLIDES WITH TITLES
% Note: Change the image file full path names to where you save them
Image1 = Slide1.Shapes.AddPicture(fullfile(folder,'test1.png'),'msoFalse','msoTrue',100,20,200,500)
Title1 = Slide1.Shapes.AddTextbox('msoTextOrientationHorizontal',200,10,200,70)
Title1.TextFrame.TextRange.Text = 'Image 1'
%% SAVE PRESENTATION
% Note: Change the presentation full path name to where you save it
Presentation.SaveAs(fullfile(folder,'ExamplePresentation.ppt'))
%% Close PowerPoint as a COM Automation server
h.Quit;
h.delete;
  1 件のコメント
Matt J
Matt J 2022 年 9 月 2 日
編集済み: Matt J 2022 年 9 月 2 日
Thanks Kevin,
That does indeed get rid of the artifact in the upper-left corner (and is also a nice illustration of the fancy things you can do with automatic PowerPoint generation). However, I would ideally like to have a solution that sends the image to the clipboard, so that it can be pasted into other environments as well.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by