翻譯|產品更新|編輯:李顯亮|2019-10-11 10:31:43.697|閱讀 284 次
概述:近期發布了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體驗
*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”微信公眾號,及時獲取更多產品最新動態及最新資訊
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn