在Aspose.Imaging for .NET v19.11中,支持调整SVG图像大小和监视文档转换进度的新功能。接下来我们用示例为大家演示调整SVG图像大小和监视文档转换进度的用法。
在Aspose.Imaging for .NET v19.11中,支持调整SVG图像大小和监视文档转换进度的新功能。接下来我们用示例为大家演示调整SVG图像大小和监视文档转换进度的用法。
>>欢迎下载Aspose.Imaging for .NET v19.11体验
*双旦狂欢,限时购买Aspose.Total,直接立减10000元,还有惊喜红包享不停!了解详情点击“咨询在线客服”哦~~
调整SVG格式
SVG是可伸缩矢量图形文件格式,并利用基于XML的内容来描述图形。由于利用内容来描绘图形,因此可以将SVG文件格式缩放为各种大小,而不会影响质量。换句话说,SVG格式与分辨率无关。为此,Aspose中增加了一种新的方法调整大小。想象一个可以用来根据需要更改SVG文件大小的方法。以下示例演示了此功能的用法:
void ResizeSvg(){ string inputFileName = "Logotype.svg"; using (Image image = Image.Load(inputFileName)) { image.Resize(image.Width * 10,image.Height * 15); image.Save("Logotype_10_15.png", new PngOptions() { VectorRasterizationOptions = new SvgRasterizationOptions() }); }}
类似的基于Java的实现如下:
String inputFileName = "Logotype.svg";try (Image image = Image.load(inputFileName)){image.resize(image.getWidth() * 10,image.getHeight() * 15);image.save("Logotype_10_15.png", new PngOptions(){{setVectorRasterizationOptions(new SvgRasterizationOptions());}});}
支持文档转换进度
有时,使用大型图像文件,并且在将此类文件渲染为其他格式时,根据文件大小需要很长时间才能完成渲染过程。在这种情况下,确定转换进度非常方便,因为如果打算向最终用户显示有关转换过程的某些状态,则很有用。为此,已在Aspose.Imaging中添加了新属性ProgressCallback。以下示例演示了此功能的用法:
using (var image = Image.Load(fileName, new LoadOptions { ProgressEventHandler = ProgressCallback })){ image.Save(fileName+".psd", new PsdOptions() { ProgressEventHandler = ExportProgressCallback });}internal void ProgressCallback(ProgressEventHandlerInfo info){ Console.WriteLine("{0} : {1}/{2}", info.EventType, info.Value, info.MaxValue);}internal void ExportProgressCallback(ProgressEventHandlerInfo info){ Console.WriteLine("Export event {0} : {1}/{2}", info.EventType, info.Value, info.MaxValue);}// Example of use of operation progress event handlerusing (var image = Image.Load(fileName, new LoadOptions { ProgressEventHandler = ProgressCallback })){ image.Save();}internal void ProgressCallback(ProgressEventHandlerInfo info){ Console.WriteLine("{0} : {1}/{2}", info.EventType, info.Value, info.MaxValue);}
类似的基于Java的实现如下:
String fileName = "some file to load";LoadOptions loadOptions = new LoadOptions();loadOptions.setProgressEventHandler(new ProgressEventHandler(){@Overridepublic void invoke(ProgressEventHandlerInfo info){System.out.format("Load event %s : %d/%dn", EventType.toString(EventType.class, info.getEventType()), info.getValue(), info.getMaxValue());}});try (Image image = Image.load(fileName, loadOptions)){PsdOptions psdOptions = new PsdOptions();psdOptions.setProgressEventHandler(new ProgressEventHandler(){@Overridepublic void invoke(ProgressEventHandlerInfo info){System.out.format("Export event %s : %d/%dn", EventType.toString(EventType.class, info.getEventType()), info.getValue(), info.getMaxValue());}});image.save(fileName + ".psd", psdOptions);}
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!