翻譯|產(chǎn)品更新|編輯:李顯亮|2019-07-03 10:58:25.643|閱讀 223 次
概述:近期我們更新了Aspose.Slides For .Net v19.6,其中很重要的是豐富了改進(jìn)的圖像管理支持功能。其中,基于.NET的API中可用的內(nèi)容也適用于Java,Android,通過(guò)基于Java和C ++的API。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
近期我們更新了Aspose.Slides For .Net v19.6,其中很重要的是豐富了改進(jìn)的圖像管理支持功能。其中,基于.NET的API中可用的內(nèi)容也適用于Java,Android,通過(guò)基于Java和C ++的API。通過(guò)這種方式,用戶可以輕松使用他們正在使用的API,并且可以使用相同的功能。
Aspose.Words For .Net是一種高級(jí)Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務(wù)。API支持生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔,而無(wú)需在跨平臺(tái)應(yīng)用程序中直接使用Microsoft Word。此外,API支持所有流行的Word處理文件格式,并允許將Word文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
接下來(lái),將詳細(xì)講解一些非常有趣且重要的新功能以及API進(jìn)行的一些改進(jìn)。
【下載Aspose.Words for .NET最新試用版】
處理PowerPoint演示文稿時(shí),在演示文稿中處理圖像起著關(guān)鍵作用。有時(shí)需要在演示中添加大量圖像。MS PowerPoint包括blob等圖像。新版中為IImageCollection接口和ImageCollection類(lèi)添加了一個(gè)新方法,以支持將大圖像作為流添加以將它們視為BLOB。
下面這個(gè)例子演示了如何包含大BLOB(圖像)并防止高內(nèi)存消耗:
//文檔目錄的路徑。 string dataDir = RunExamples.GetDataDir_PresentationSaving(); string pathToLargeImage = dataDir + "large_image.jpg"; //創(chuàng)建一個(gè)包含此圖像的新演示文稿 using (Presentation pres = new Presentation()) { using (FileStream fileStream = new FileStream(pathToLargeImage, FileMode.Open)) { //讓我們將圖像添加到演示文稿中 - 我們選擇KeepLocked行為,因?yàn)槲覀儧](méi)有 //有意訪問(wèn)“l(fā)argeImage.png”文件。 IPPImage img = pres.Images.AddImage(fileStream, LoadingStreamBehavior.KeepLocked); pres.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 0, 0, 300, 200, img); //保存演示文稿 盡管輸出演示將是 //較大時(shí),內(nèi)存消耗將低于pres對(duì)象的整個(gè)生命周期 pres.Save(dataDir + "presentationWithLargeImage.pptx", SaveFormat.Pptx); } }
類(lèi)似的基于Java的示例:
//文檔目錄的路徑。 String dataDir = Utils.getDataDir(AddBlobImageToPresentation.class); //假設(shè)我們想要包含在演示文稿中的大圖像文件 String pathToLargeImage = dataDir + "large_image.jpg"; //創(chuàng)建一個(gè)包含此圖像的新演示文稿 Presentation pres = new Presentation(); try { FileInputStream fip = new FileInputStream(pathToLargeImage); try { //讓我們將圖像添加到演示文稿中 - 我們選擇KeepLocked行為 //意圖訪問(wèn)“l(fā)argeImage.png”文件。 IPPImage img = pres.getImages().addImage(fip, LoadingStreamBehavior.KeepLocked); pres.getSlides().get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, 300, 200, img); //保存演示文稿 // 較大時(shí),pres對(duì)象的整個(gè)生命周期內(nèi)的內(nèi)存消耗將較低 pres.save(dataDir + "presentationWithLargeImage.pptx", SaveFormat.Pptx); } finally { fip.close(); } } catch (java.io.IOException e) { e.printStackTrace(); } finally { pres.dispose(); }
基于C ++的類(lèi)似示例:
//假設(shè)我們想要包含在演示文稿中的大圖像文件 System::String pathToLargeImage = u"../templates/largeImage.jpg"; //創(chuàng)建一個(gè)包含此圖像的新演示文稿 auto pres = System::MakeObject(); auto fileStream = System::MakeObject(pathToLargeImage, System::IO::FileMode::Open); //讓我們將圖像添加到演示文稿中 - 我們選擇KeepLocked行為 //意圖訪問(wèn)“l(fā)argeImage.png”文件。 auto img = pres->get_Images()->AddImage(fileStream, LoadingStreamBehavior::KeepLocked); pres->get_Slides()->idx_get(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 0.0f, 0.0f, 300.0f, 200.0f, img); //保存演示文稿 // 較大時(shí),pres對(duì)象的整個(gè)生命周期內(nèi)的內(nèi)存消耗將較低 pres->Save(u"../out/presentationWithLargeImage.pptx", Aspose::Slides::Export::SaveFormat::Pptx);
在這個(gè)版本中,Aspose.Slides提供了表示幻燈片有效背景的支持,其中包含有效填充格式和有效效果格式的信息。為此,添加了IBackgroundEffectiveData接口及其BackgroundEffectiveData類(lèi)的實(shí)現(xiàn)。
CreateBackgroundEffective方法已添加到IBaseSlide接口和BaseSlide類(lèi)中。此方法允許獲得幻燈片背景的有效值。以下示例顯示如何獲取幻燈片的有效背景值。
//文檔目錄的路徑。 string dataDir = RunExamples.GetDataDir_Slides_Presentations_Background(); //實(shí)例化表示演示文稿文件的Presentation類(lèi) Presentation pres = new Presentation(dataDir + "SamplePresentation.pptx"); IBackgroundEffectiveData effBackground = pres.Slides[0].CreateBackgroundEffective(); if (effBackground.FillFormat.FillType == FillType.Solid) Console.WriteLine("Fill color: " + effBackground.FillFormat.SolidFillColor); else Console.WriteLine("Fill type: " + effBackground.FillFormat.FillType);
類(lèi)似的基于Java的示例:
//文檔目錄的路徑。 String dataDir = Utils.getDataDir(GetBackgroundEffectiveValues.class); Presentation pres = new Presentation(dataDir + "SamplePresentation.pptx"); IBackgroundEffectiveData effBackground = pres.getSlides().get_Item(0).createBackgroundEffective(); if (effBackground.getFillFormat().getFillType() == FillType.Solid) System.out.println("Fill color: " + effBackground.getFillFormat().getSolidFillColor()); else System.out.println("Fill type: " + effBackground.getFillFormat().getFillType());
基于C ++的類(lèi)似示例:
const String templatePath = u"../templates/SamplePresentation.pptx"; auto pres = System::MakeObject(templatePath); System::SharedPtreffBackground = pres->get_Slides()->idx_get(0)->CreateBackgroundEffective(); if (effBackground->get_FillFormat()->get_FillType() == Aspose::Slides::FillType::Solid) { System::Console::WriteLine(System::String(u"Fill color: ") + effBackground->get_FillFormat()->get_SolidFillColor()); } else { System::Console::WriteLine(System::String(u"Fill type: ") + System::ObjectExt::ToString(effBackground->get_FillFormat()->get_FillType())); }
使用時(shí),Aspose.Slides有時(shí)需要保存大量的演示文件或?qū)⒋笮脱菔疚募D(zhuǎn)換為PDF。在這種情況下,API用戶可能經(jīng)歷等待狀態(tài)直到保存或呈現(xiàn)過(guò)程完成的時(shí)間并且這種情況有時(shí)令人討厭。為了緩解這種情況,在ISaveOptions接口和SaveOptions抽象類(lèi)中添加了一個(gè)新的IProgressCallback接口。IProgressCallback接口表示用于以百分比保存進(jìn)度更新的回調(diào)對(duì)象。
下面的示例演示了在導(dǎo)出到PDF時(shí)使用新功能:
//文檔目錄的路徑。 string dataDir = RunExamples.GetDataDir_Conversion(); using (Presentation presentation = new Presentation(dataDir + "ConvertToPDF.pptx")) { ISaveOptions saveOptions = new PdfOptions(); saveOptions.ProgressCallback = new ExportProgressHandler(); presentation.Save(dataDir + "ConvertToPDF.pdf", SaveFormat.Pdf, saveOptions); }
class ExportProgressHandler : IProgressCallback { public void Reporting(double progressValue) { // Use progress percentage value here int progress = Convert.ToInt32(progressValue); Console.WriteLine(progress + "% file converted"); } }
類(lèi)似的基于Java的示例:
//文檔目錄的路徑。 String dataDir = Utils.getDataDir(CovertToPDFWithProgressUpdate.class); Presentation presentation = new Presentation(dataDir + "ConvertToPDF.pptx"); try { ISaveOptions saveOptions = new PdfOptions(); saveOptions.setProgressCallback((IProgressCallback) new ExportProgressHandler()); presentation.save(dataDir + "ConvertToPDF.pdf", SaveFormat.Pdf, saveOptions); }finally { presentation.dispose(); }
//文檔目錄的路徑。 class ExportProgressHandler implements IProgressCallback { public void reporting(double progressValue) { //在此使用進(jìn)度百分比值 } }
基于C ++的類(lèi)似示例:
const String templatePath = u“ ../ templates/ SamplePresentation.pptx ” ; const String outPath = u“ ../out/SamplePresentation_out.pptx ” ; auto presentation = System :: MakeObject(templatePath); System :: SharedPtrsaveOptions = System :: MakeObject(); System :: SharedPtrcallBack = System :: MakeObject(); saveOptions-> set_ProgressCallback(callBack); presentation-> Save(outPath,Aspose :: Slides :: Export :: SaveFormat :: Pdf,saveOptions);
class ExportProgressHandler : public IProgressCallback { public: void Reporting(double progressValue) { //... } };
此版本中包含許多其他功能,增強(qiáng)功能和錯(cuò)誤修復(fù)程序。更多更新細(xì)則可參考【Aspose.Slides For .Net v19.6更新說(shuō)明】
*如有更多疑惑和資源需求可加入ASPOSE控件討論QQ群(642018183),與大神們一起交流討論!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: