您的问题似乎不完整,您是想询问关于C语言编程的某个具体问题吗?比如C语言的语法、编程技巧、项目开发等。请提供更具体的信息,这样我才能给出更准确的回答。
- 内容介绍
- 文章标签
- 相关推荐
本文共计422个文字,预计阅读时间需要2分钟。
要实现PPT转图片的功能,首先需要引用两个DLL:Microsoft.Office.Interop.PowerPoint和Microsoft.Office.Interop.OfficeCore。以下是简化后的代码示例:
csharpprivate void pptToImg(string pptPath, string imgPath){ // 创建PowerPoint应用程序实例 PowerPoint.Application pptApp=new PowerPoint.Application(); // 隐藏PowerPoint应用程序窗口 pptApp.Visible=false; // 打开PPT文件 PowerPoint.Presentation ppt=pptApp.Presentations.Open(pptPath); // 遍历PPT中的每一页 foreach (PowerPoint.Slide slide in ppt.Slides) { // 获取幻灯片的宽度与高度 int slideWidth=(int)slide.Width; int slideHeight=(int)slide.Height; // 创建一个图片对象 System.Drawing.Image image=new System.Drawing.Bitmap(slideWidth, slideHeight); // 将幻灯片绘制到图片上 using (System.Drawing.Graphics graphics=System.Drawing.Graphics.FromImage(image)) { graphics.CopyFromScreen(pptApp.HwndPresentation, 0, 0, slideWidth, slideHeight, System.Drawing.CopyPixelOperation.SourceCopy); } // 保存图片到指定路径 image.Save(imgPath); // 释放图片资源 image.Dispose(); } // 关闭PPT文件 ppt.Close(); // 退出PowerPoint应用程序 pptApp.Quit(); // 释放对象 System.Runtime.InteropServices.Marshal.ReleaseComObject(ppt); System.Runtime.InteropServices.Marshal.ReleaseComObject(pptApp);}
要实现PPT转图片,首先需要引用两个DLL。
我这里用的这个这个版本
- Microsoft.Office.Interop.PowerPoint 12.0
- Microsoft Office 12.0 object Library
如下图:
代码如下:
private void pptToImg(string pptPath, string imgPath) { var app = new Microsoft.Office.Interop.PowerPoint.Application(); var ppt = app.Presentations.Open(pptPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); var index = 0; var fileName = Path.GetFileNameWithoutExtension(pptPath); foreach (Microsoft.Office.Interop.PowerPoint.Slide slid in ppt.Slides) { ++index; //设置图片大小 slid.Export(imgPath+string.Format("page{0}.png",index.ToString()), "png", 1024, 768); //根据屏幕尺寸。设置图片大小 //slid.Export(imgPath+string.Format("page{0}.jpg",index.ToString()), "jpg", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); } //释放资源 ppt.Close(); app.Quit(); GC.Collect(); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。
本文共计422个文字,预计阅读时间需要2分钟。
要实现PPT转图片的功能,首先需要引用两个DLL:Microsoft.Office.Interop.PowerPoint和Microsoft.Office.Interop.OfficeCore。以下是简化后的代码示例:
csharpprivate void pptToImg(string pptPath, string imgPath){ // 创建PowerPoint应用程序实例 PowerPoint.Application pptApp=new PowerPoint.Application(); // 隐藏PowerPoint应用程序窗口 pptApp.Visible=false; // 打开PPT文件 PowerPoint.Presentation ppt=pptApp.Presentations.Open(pptPath); // 遍历PPT中的每一页 foreach (PowerPoint.Slide slide in ppt.Slides) { // 获取幻灯片的宽度与高度 int slideWidth=(int)slide.Width; int slideHeight=(int)slide.Height; // 创建一个图片对象 System.Drawing.Image image=new System.Drawing.Bitmap(slideWidth, slideHeight); // 将幻灯片绘制到图片上 using (System.Drawing.Graphics graphics=System.Drawing.Graphics.FromImage(image)) { graphics.CopyFromScreen(pptApp.HwndPresentation, 0, 0, slideWidth, slideHeight, System.Drawing.CopyPixelOperation.SourceCopy); } // 保存图片到指定路径 image.Save(imgPath); // 释放图片资源 image.Dispose(); } // 关闭PPT文件 ppt.Close(); // 退出PowerPoint应用程序 pptApp.Quit(); // 释放对象 System.Runtime.InteropServices.Marshal.ReleaseComObject(ppt); System.Runtime.InteropServices.Marshal.ReleaseComObject(pptApp);}
要实现PPT转图片,首先需要引用两个DLL。
我这里用的这个这个版本
- Microsoft.Office.Interop.PowerPoint 12.0
- Microsoft Office 12.0 object Library
如下图:
代码如下:
private void pptToImg(string pptPath, string imgPath) { var app = new Microsoft.Office.Interop.PowerPoint.Application(); var ppt = app.Presentations.Open(pptPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); var index = 0; var fileName = Path.GetFileNameWithoutExtension(pptPath); foreach (Microsoft.Office.Interop.PowerPoint.Slide slid in ppt.Slides) { ++index; //设置图片大小 slid.Export(imgPath+string.Format("page{0}.png",index.ToString()), "png", 1024, 768); //根据屏幕尺寸。设置图片大小 //slid.Export(imgPath+string.Format("page{0}.jpg",index.ToString()), "jpg", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); } //释放资源 ppt.Close(); app.Quit(); GC.Collect(); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

