Aspose.Imaging for .NET(点击下载)是一种高级图像处理控件,允许开发人员创建,编辑,绘制或转换图像。图像导出和转换是API核心功能之一,它允许在不安装Photoshop应用程序或任何其他图像编辑器的情况下保存为AdobePhotoshop®本机格式。
近期发布了Aspose.Imaging for .NET v19.9,优化基本栅格图像滤波操作,优化RasterCachedImage类中抖动操作,优化Bmp格式的速度或内存等等,下面我们一起用示例为大家详细解读。
主要优化
- 优化RasterCachedImage类中抖动操作
- 在基本图像中支持优化策略调整大小操作
- 优化基本光栅图像滤波操作
▲IMAGINGNET-3382支持RasterCachedImage类中抖动操作的优化策略
//为目标加载的图像设置50兆字节的内存限制 using (var image = Image.Load(imageFilePath, new LoadOptions() { BufferSizeHint = 50 })) { //执行抖动操作 image.Dither(DitheringMethod.FloydSteinbergDithering, 1); }
▲IMAGINGNET-3456在基本图像中支持优化策略调整大小操作
//为目标加载的图像设置50兆字节的内存限制 using (var image = Image.Load(imageFilePath, new LoadOptions() { BufferSizeHint = 50 })) { // 执行调整大小操作 image.Resize(300, 200, ResizeType.LanczosResample); }
▲IMAGINGNET-3457支持基本光栅图像滤波操作中的优化策略
using Aspose.Imaging.ImageFilters.FilterOptions; //限制“BigRectangularFilter”过滤的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { FilterOptionsBase filterOptions = new BigRectangularFilterOptions(); rasterImage.Filter(rasterImage.Bounds, filterOptions); rasterImage.Save("BigRectangularFilter.png") } //限制“SmallRectangularFilter”过滤的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { FilterOptionsBase filterOptions = new SmallRectangularFilterOptions(); rasterImage.Filter(rasterImage.Bounds, filterOptions); rasterImage.Save("SmallRectangularFilter.png") } //限制“MedianFilter”过滤的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { FilterOptionsBase filterOptions = new MedianFilterOptions(6 /*size*/); rasterImage.Filter(rasterImage.Bounds, filterOptions); rasterImage.Save("MedianFilter.png") } // 限制“GaussWienerFilter”过滤的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { FilterOptionsBase filterOptions = new GaussWienerFilterOptions(5 /*radius*/, 1.5 /*smooth*/) { Brightness = 1, Snr = 0.003 }; rasterImage.Filter(rasterImage.Bounds, filterOptions); rasterImage.Save("GaussWienerFilter.png") } // 限制“MotionWienerFilter”过滤的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { FilterOptionsBase filterOptions = new MotionWienerFilterOptions(10 /*length*/, 1 /*smooth*/, 0 /*angle*/) { Brightness = 1, Snr = 0.007 }; rasterImage.Filter(rasterImage.Bounds, filterOptions); rasterImage.Save("MotionWienerFilter.png") } // 限制“GaussianBlurFilter”过滤的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { FilterOptionsBase filterOptions = new GaussianBlurFilterOptions(5 /*radius*/, 4 /*sigma*/); rasterImage.Filter(rasterImage.Bounds, filterOptions); rasterImage.Save("GaussianBlurFilter.png") } // 限制“SharpenFilter”过滤的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { FilterOptionsBase filterOptions = new SharpenFilterOptions(); rasterImage.Filter(rasterImage.Bounds, filterOptions); rasterImage.Save("SharpenFilter.png") } //限制“BilateralSmoothingFilter”过滤的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { FilterOptionsBase filterOptions = new BilateralSmoothingFilterOptions(3 /*size*/); rasterImage.Filter(rasterImage.Bounds, filterOptions); rasterImage.Save("BilateralSmoothingFilter.png") } // 限制“BinarizeFixed”过滤操作的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { rasterImage.BinarizeFixed(180 /*threshold*/); rasterImage.Save("BinarizeFixed.png") } //限制“BinarizeOtsu”过滤操作的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { rasterImage.BinarizeOtsu(); rasterImage.Save("BinarizeOtsu.png") } //限制“BinarizeBradley”过滤操作的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { rasterImage.BinarizeBradley(-2 /*brightness difference*/); rasterImage.Save("BinarizeBradley.png") } // 限制“灰度”过滤操作的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { rasterImage.Grayscale(); rasterImage.Save("Grayscale.png") } // 限制“AdjustBrightness”过滤操作的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { rasterImage.AdjustBrightness(70 /*brightness*/); rasterImage.Save("AdjustBrightness.png") } // 限制“AdjustContrast”过滤操作的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { rasterImage.AdjustContrast(50 /*contrast*/); rasterImage.Save("AdjustContrast.png") } //限制“AdjustGamma”过滤操作的内存使用量(50 Mb) using (RasterImage rasterImage = (RasterImage)Image.Load("inputImage.png", new LoadOptions { BufferSizeHint = 50 })) { rasterImage.AdjustGamma(3 /*gamma*/); rasterImage.Save("AdjustGamma.png") }
来源:oschina
链接:https://my.oschina.net/u/4087915/blog/3104996