彩票走势图

10月新发!Aspose.Imaging for .NET v19.10新版6大功能增强上线!

翻译|产品更新|编辑:李显亮|2019-10-11 10:31:43.697|阅读 246 次

概述:近期发布了Aspose.Imaging for .NET v19.10,优化Cmx格式的速度或内存,优化针对Jpeg格式的速度或内存,优化Aspose.Imaging.Graphics等等,欢迎下载体验。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

Aspose.Imaging for .NET一种高级图像处理控件,允许开发人员创建,编辑,绘制或转换图像。图像导出和转换是API核心功能之一,它允许在不安装Photoshop应用程序或任何其他图像编辑器的情况下保存为AdobePhotoshop®本机格式。

近期发布了Aspose.Imaging for .NET v19.10,优化Cmx格式的速度或内存,优化针对Jpeg格式的速度或内存,优化Aspose.Imaging.Graphics等等,下面我们一起用示例为大家详细解读。

>>欢迎下载Aspose.Imaging for .NET v19.10体验

主要优化

  • 优化Cmx格式的速度或内存
  • 优化针对Jpeg格式的速度或内存
  • 优化Aspose.Imaging.Graphics

增强功能

  • 将EMF转换为PDF文件将生成具有很小视图的pdf页面
  • 本机在图元文件中使用VectorRasterizationOptions功能
  • 将BNG上的TruecolorWithAlpha转换修复为PNG

*10月狂欢季,现在购买Aspose系列产品,惊喜红包享不停,万元折扣等你来领!了解详情点击哦~~


用法示例

▲IMAGINGNET-3383 Aspose.Imaging.Graphics中的支持优化策略

 const int ImageSize = 2000;
ImageOptionsBase createOptions = new PngOptions();
createOptions.Source = new FileCreateSource(this.GetFileInOutputFolder("temporary.png"));
createOptions.BufferSizeHint = 30; // Memory limit is 30 Mb
using (Image image = Image.Create(createOptions, ImageSize, ImageSize)) {
Graphics graphics = new Graphics(image);
// You can use any graphic operations here, all of them will be performed within the established memory limit
// For example:
   graphics.Clear(Color.LightSkyBlue);
   graphics.DrawLine(new Pen(Color.Red, 3f), 0, 0, image.Width, image.Height);
  
}

// A large number of graphic operations are also supported:
const int OperationAreaSize = 10;
createOptions = new PngOptions();
createOptions.Source = new FileCreateSource(this.GetFileInOutputFolder("temporary.png"));
createOptions.BufferSizeHint = 30; // Memory limit is 30 Mb
using (Image image = Image.Create(createOptions, ImageSize, ImageSize)) {
Graphics graphics = new Graphics(image);
graphics.BeginUpdate();
   graphics.Clear(Color.LightSkyBlue);
int x, y;
 for (int column = 0; column * OperationAreaSize < ImageSize; column++)
    {
       for (int row = 0; row * OperationAreaSize < ImageSize; row++)
        {
           operations++;

           x = column * OperationAreaSize;
           y = row * OperationAreaSize;

           bool reversed = (column + row) % 2 != 0;
           if (reversed)
            {
               graphics.DrawLine(
                   new Pen(Color.Red),
                   x + OperationAreaSize - 2,
                   y,
                   x,
                   y + OperationAreaSize);
            }
           else
            {
               graphics.DrawLine(
                   new Pen(Color.Red),
                   x,
                   y,
                   x + OperationAreaSize - 2,
                   y + OperationAreaSize);
            }
        }
    }

   // About 40k operations will be applied here, while they do not take up too much memory 
   // (since they are already unloaded into the external file, and will be loaded from there one at a time)
   graphics.EndUpdate();
}

▲IMAGINGNET-3419允许Cmx格式的速度或内存优化策略

 // Setting a memory limit of 10 megabytes for target loaded image
using (Image image = Image.Load("example.cmx", new LoadOptions() { BufferSizeHint = 10 }))
{
   image.Save(
       "output.png",
       new PngOptions()
            {
               VectorRasterizationOptions =
                   new CmxRasterizationOptions { TextRenderingHint = TextRenderingHint.SingleBitPerPixel, SmoothingMode = SmoothingMode.AntiAlias, Positioning = PositioningTypes.DefinedByDocument}
            });
}

▲IMAGINGNET-3404允许针对Jpeg格式的速度或内存优化策略

 // Setting a memory limit of 50 megabytes for target loaded image
using (Image image = Image.Load("inputFile.jpg", new LoadOptions() { BufferSizeHint = 50 })) {
image.Save("outputFile_Baseline.jpg", new JpegOptions { CompressionType = JpegCompressionMode.Baseline, Quality = 100 });
image.Save("outputFile_Progressive.jpg", new JpegOptions { CompressionType = JpegCompressionMode.Progressive });
image.Save("outputFile_Lossless.jpg", new JpegOptions
                                                  {
                                                     ColorType = JpegCompressionColorMode.YCbCr,
                                                     CompressionType = JpegCompressionMode.Lossless,
                                                     BitsPerChannel = 4
                                                  });
image.Save("outputFile_JpegLs.jpg", new JpegOptions
                                                  {
                                                     ColorType = JpegCompressionColorMode.YCbCr,
                                                     CompressionType = JpegCompressionMode.JpegLs,
                                                     JpegLsInterleaveMode = JpegLsInterleaveMode.None,
                                                     JpegLsAllowedLossyError = 3,
                                                     JpegLsPreset = null
                                                  });
}

// Setting a memory limit of 50 megabytes for target created image
ImageOptionsBase createOptions = new JpegOptions { CompressionType = JpegCompressionMode.Progressive };
createOptions.BufferSizeHint = 50;
createOptions.Source = new FileCreateSource("createdFile.jpg", false);
using (var image = Image.Create(createOptions, 1000, 1000)) {
image.Save(); // save to same location
}

▲IMAGINGNET-2279将EMF转换为PDF文件正在生成视图很小的pdf页面[.Net]

 string baseFolder = "D:";
           string file = "16BE10100024023005-1-1.emf";
           string inputFileName = Path.Combine(baseFolder, file);
           string outputFileName = inputFileName + ".pdf";
           using (Image image = Image.Load(inputFileName))
            {
               image.Save(outputFileName, new PdfOptions()
               {
                   VectorRasterizationOptions = new EmfRasterizationOptions() { PageSize = image.Size } 
               });
           }

▲IMAGINGNET-3276将BNG上的TruecolorWithAlpha转换修复为PNG

string dir = "c:\\aspose.imaging.net\\IMAGINGNET\\3276\\";

using (Image image = Image.Load(dir + "test.bmp"))
{
   RasterImage rasterImage = (RasterImage)image;
   Color[] colors = rasterImage.LoadPixels(image.Bounds);
   int numberOfFullyTransparentPixels = 0;
   int totalNumberOfPixels = image.Width * image.Height;
   foreach (Color c in colors)
    {
       if (c.A == 0)
        {
           numberOfFullyTransparentPixels++;
        }
    }

   // All pixels are fully opaque.
   Assert.AreEqual(0, numberOfFullyTransparentPixels);

   PngOptions options = new PngOptions() { ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha };
   image.Save(dir + "test.bmp.png", options);
}

▲IMAGINGNET-3280本机在图元文件中使用VectorRasterizationOptions功能

 1. Add border
input files: attachment:image1.emf, attachment:image2.wmf
output files: attachment:result_image1.emf, attachment:result_image2.wmf
~~~ csharp
            string baseFolder = "D:";                        
           int borderLeft = 50;
           int borderTop = 50;
           int borderRight = 50;
           int borderBottom = 50;

            string[] files = new[] { "image1.emf", "image2.wmf" };
            foreach (string fileName in files)
            {
                string inputFile = Path.Combine(baseFolder, fileName);
                string outputFile = Path.Combine(baseFolder, "result_" + fileName);
                using (MetaImage image = (MetaImage)Image.Load(inputFile))
                {
                    image.ResizeCanvas(new Rectangle(-borderLeft, -borderTop, image.Width + borderLeft + borderRight, image.Height + borderTop + borderBottom));
                    image.Save(outputFile);
                }
            }
2. Resize
            string baseFolder = @"D:\";
            string[] files = new[] {"image3.emf", "image4.wmf"};
            foreach (string fileName in files)
            {
                string inputFile = Path.Combine(baseFolder, fileName);
                string outputFile = Path.Combine(baseFolder, "result_" + fileName);
                using (MetaImage image = (MetaImage) Image.Load(inputFile))
                {
                    image.Resize(image.Width/4, image.Height/4);
                    image.Save(outputFile);
                }
            }
3. Change background
            string baseFolder = @"D:\";
            string[] files = new[] {"image1.emf", "image2.wmf"};
            foreach (string fileName in files)
            {
                string inputFile = Path.Combine(baseFolder, fileName);
                string outputFile = Path.Combine(baseFolder, "result_bg_" + fileName);
                using (MetaImage image = (MetaImage) Image.Load(inputFile))
                {
                    FileFormat fileFormat = image.FileFormat;
                   if (fileFormat == FileFormat.Emf)
                    {
                        AddBackgroundRectangleEmf((EmfImage)image, Color.Blue);
                    }
                   else
                    {
                        AddBackgroundRectangleWmf((WmfImage)image, Color.Blue);
                    }
                    image.Save(outputFile);
                }
            }
              private static void AddBackgroundRectangleEmf(EmfImage image, Color color)
        {
            image.CacheData();
           if (image.Records.Count < 1)
            {
               return;
            }

           //Set Rectangle
           EmfRectangle rectangle = new EmfRectangle();
            rectangle.Box = image.Header.EmfHeader.Bounds;

           //Set Brush
           EmfCreateBrushIndirect brush = new EmfCreateBrushIndirect();
            brush.LogBrush = new EmfLogBrushEx();
            brush.LogBrush.Argb32ColorRef = color.ToArgb();

           //Select brush
           EmfSelectObject selectObject = new EmfSelectObject();
            selectObject.ObjectHandle = 0;

           //Remove brush
           EmfDeleteObject deleteObject = new EmfDeleteObject();
            deleteObject.ObjectHandle = 0;

           //Add records
           image.Records.Insert(1, brush);
            image.Records.Insert(2, selectObject);
            image.Records.Insert(3, rectangle);
            image.Records.Insert(4, deleteObject);
        }

        private static void AddBackgroundRectangleWmf(WmfImage image, Color color)
        {
            image.CacheData();
           if (image.Records.Count < 1)
            {
               return;
            }

           //Set Rectangle
           WmfRectangle rectangle = new WmfRectangle();
            rectangle.Rectangle = image.FrameBounds;

           //Set Brush
           WmfCreateBrushInDirect brush = new WmfCreateBrushInDirect();
            brush.LogBrush = new EmfLogBrushEx();
            brush.LogBrush.Argb32ColorRef = color.ToArgb();

           //Select brush
           WmfSelectObject selectObject = new WmfSelectObject(brush);

           //Remove brush
           WmfDeleteObject deleteObject = new WmfDeleteObject(brush);

           //Add records
           image.Records.Insert(0, brush);
            image.Records.Insert(1, selectObject);
            image.Records.Insert(2, rectangle);
            image.Records.Insert(3, deleteObject);
        }


ASPOSE技术交流QQ群(642018183)已开通,各类资源及时分享,欢迎交流讨论!

扫描关注“慧聚IT”微信公众号,及时获取更多产品最新动态及最新资讯

1562572142.jpg



标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP