原創|產品更新|編輯:李顯亮|2021-01-04 10:06:57.557|閱讀 225 次
概述:Aspose.Imaging for .NET更新至最新版v20.12,實現從一系列圖像創建動畫的功能,支持訪問丟失的Exif屬性,本文為你用示例演示這些新功能。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.Imaging是一種高級圖像處理控件,允許開發人員創建,編輯,繪制或轉換圖像。圖像導出和轉換是API核心功能之一,它允許在不安裝Photoshop應用程序或任何其他圖像編輯器的情況下保存為AdobePhotoshop®本機格式。
事實證明,Aspose.Imaging是處理各種圖像格式的強大API。除單頁圖像外,Aspose.Imaging還支持處理多頁圖像,包括GIF,TIFF,PSD,DICOM,CDR和WebP。
近期發布了Aspose.Imaging for .NET v20.12,實現從一系列圖像創建動畫的功能,支持訪問丟失的Exif屬性,還沒使用過的朋友可以點擊下載最新版Aspose.Imaging
key | 概述 | 類別 |
---|---|---|
IMAGINGNET-4215 | 實現公共API來確定圖像是否使用了調色板 | 功能 |
IMAGINGNET-4154 | 實現從一系列圖像創建動畫的功能 | 功能 |
IMAGINGNET-4144 | 支持訪問丟失的Exif屬性 | 功能 |
IMAGINGNET-4233 | Tga Creator始終會創建損壞的圖像 | 增強功能 |
IMAGINGNET-4227 | 提高GraphCutHelper性能和異步實現 | 增強功能 |
IMAGINGNET-4194 | 從EMF導出為PNG文件格式時發生異常 | Bug修復 |
IMAGINGNET-4190 | 將BMP轉換為PNG時,圖像導出失敗異常 | Bug修復 |
IMAGINGNET-4187 | TgaImage的Resize,Crop,RotateFlip和Rotate方法不起作用 | Bug修復 |
IMAGINGNET-4155 | 合并Tiff的異常 | Bug修復 |
IMAGINGNET-4010 | 重做與多頁圖像相關的方法和屬性,以使其易于使用 | Bug修復 |
input files in test.zip string baseFolder = Path.Combine(@"D:\", "test"); string outFileName = "MultipageImageCreateTest.tif"; string outputFilePath = Path.Combine(baseFolder, outFileName); string[] files = new string[]{ "33266.tif", "Animation.gif", "elephant.png", "Input.jp2", "eye.wmf", "tiger.bmp", "MultiPage.cdr", "juanmontoya_lingerie.svg" }; Listimages = new List(); foreach (var file in files) { string filePath = Path.Combine(baseFolder, file); images.Add(Image.Load(filePath)); } using (Image image = Image.Create(images.ToArray(), true)) { image.Save(outputFilePath, new TiffOptions(TiffExpectedFormat.TiffJpegRgb)); }
using (var image = (JpegImage)Image.Load("Sample.jpg")) { foreach (var makerNote in image.ExifData.MakerNotes) { Console.WriteLine("{0}: {1}", makerNote.Name, makerNote.Value); } Console.ReadKey(); } **IMAGINGNET-4155 Exception on combining Tiff** {{code}} using (var page1 = (TiffImage)Image.Load("Image1.tif")) { using (var page2 = (TiffImage)Image.Load("Image2.tif")) { page1.AddFrame(TiffFrame.CopyFrame(page2.ActiveFrame)); } page1.Save("Result.tif"); }
string baseFolder = Path.Combine(@"D:\", "test"); string outFileName = "MultipageImageCreateTest.tif"; string outputFilePath = Path.Combine(baseFolder, outFileName); string[] files = new string[]{ "33266.tif", "Animation.gif", "elephant.png", "Input.jp2", "eye.wmf", "tiger.bmp", "MultiPage.cdr", "juanmontoya_lingerie.svg" }; Listimages = new List(); foreach (var file in files) { string filePath = Path.Combine(baseFolder, file); images.Add(Image.Load(filePath)); } using (Image image = Image.Create(images.ToArray(), true)) { image.Save(outputFilePath, new TiffOptions(TiffExpectedFormat.TiffJpegRgb)); }
### GraphCutHelper async operations Test that all types of masking operations (ImageMasking.Decompose, ImageMasking.DecomposeAsync, IMaskingSession.Decompose, IMaskingSession.DecomposeAsync) produce the same result. string inputFilePath = "fileName"; string outputFilePath1 = "outputfileName_1.png"; string outputFilePath2 = "outputfileName_2.png"; string outputFilePath3 = "outputfileName_3.png"; string outputFilePath4 = "outputfileName_4.png"; string tempFilePath = outputFilePath1 + "_temp"; using (RasterImage image = (RasterImage)Image.Load(inputFilePath)) { int featheringRadius = (Math.Max(image.Width, image.Height) / 500) + 1; AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions { AssumedObjects = null, CalculateDefaultStrokes = true, FeatheringRadius = featheringRadius, Method = SegmentationMethod.GraphCut, Decompose = false, ExportOptions = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha, Source = new FileCreateSource(tempFilePath) }, BackgroundReplacementColor = Color.Transparent, }; using (MaskingResult results = new ImageMasking(image).Decompose(options)) { using (RasterImage resultImage = (RasterImage)results[1].GetImage()) { resultImage.Save(outputFilePath1, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } } } using (RasterImage image = (RasterImage)Image.Load(inputFilePath)) { int featheringRadius = (Math.Max(image.Width, image.Height) / 500) + 1; AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions { AssumedObjects = null, CalculateDefaultStrokes = true, FeatheringRadius = featheringRadius, Method = SegmentationMethod.GraphCut, Decompose = false, ExportOptions = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha, Source = new FileCreateSource(tempFilePath) }, BackgroundReplacementColor = Color.Transparent, }; IAsyncTask asyncTask = new ImageMasking(image).DecomposeAsync(options); asyncTask.RunAsync(); asyncTask.AsyncWaitHandle.WaitOne(); using (MaskingResult results = (MaskingResult)asyncTask.Result) { using (RasterImage resultImage = (RasterImage)results[1].GetImage()) { resultImage.Save(outputFilePath2, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } } } using (RasterImage image = (RasterImage)Image.Load(inputFilePath)) { int featheringRadius = (Math.Max(image.Width, image.Height) / 500) + 1; AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions { AssumedObjects = null, CalculateDefaultStrokes = true, FeatheringRadius = featheringRadius, Method = SegmentationMethod.GraphCut, Decompose = false, ExportOptions = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha, Source = new FileCreateSource(tempFilePath) }, BackgroundReplacementColor = Color.Transparent, }; using (IMaskingSession maskingSession = new ImageMasking(image).CreateSession(options)) { using (MaskingResult results = maskingSession.Decompose()) { using (RasterImage resultImage = (RasterImage)results[1].GetImage()) { resultImage.Save(outputFilePath3, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } } } } using (RasterImage image = (RasterImage)Image.Load(inputFilePath)) { int featheringRadius = (Math.Max(image.Width, image.Height) / 500) + 1; AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions { AssumedObjects = null, CalculateDefaultStrokes = true, FeatheringRadius = featheringRadius, Method = SegmentationMethod.GraphCut, Decompose = false, ExportOptions = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha, Source = new FileCreateSource(tempFilePath) }, BackgroundReplacementColor = Color.Transparent, }; using (IMaskingSession maskingSession = new ImageMasking(image).CreateSession(options)) { IAsyncTask asyncTask = maskingSession.DecomposeAsync(); asyncTask.RunAsync(); asyncTask.AsyncWaitHandle.WaitOne(); using (MaskingResult results = (MaskingResult)asyncTask.Result) { using (RasterImage resultImage = (RasterImage)results[1].GetImage()) { resultImage.Save(outputFilePath4, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } } } } // All result images should be identical. ### GraphCutHelper progress reporting Test GraphCutHelper progress reporting support. StringBuilder eventLog = new StringBuilder(); ProgressEventHandler eventHandler = delegate(ProgressEventHandlerInfo info) { eventLog.AppendLine(string.Format("{0} / {1} : {2}", info.Value, info.MaxValue, info.EventType)); }; string inputFilePath = "fileName"; string outputFilePath = "outputfileName.png"; using (RasterImage image = (RasterImage) Image.Load(inputFilePath)) { int featheringRadius = (Math.Max(image.Width, image.Height) / 500) + 1; AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions { AssumedObjects = null, CalculateDefaultStrokes = true, FeatheringRadius = featheringRadius, PrecalculationProgressEventHandler = eventHandler, Method = SegmentationMethod.GraphCut, Decompose = false, ExportOptions = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha, Source = new FileCreateSource(outputFilePath + "_temp") }, BackgroundReplacementColor = Color.Transparent, }; IAsyncTask asyncTask = new ImageMasking(image).DecomposeAsync(options); asyncTask.RunAsync(); asyncTask.AsyncWaitHandle.WaitOne(); using (MaskingResult results = (MaskingResult) asyncTask.Result) { using (RasterImage resultImage = (RasterImage) results[1].GetImage()) { resultImage.Save(outputFilePath, new PngOptions() {ColorType = PngColorType.TruecolorWithAlpha}); } } } bool isProgressLogged = eventLog.ToString() == "1 / 1 : Initialization\r\n" + "2 / 3 : PreProcessing\r\n" + "3 / 3 : Processing\r\n" + "4 / 9 : RelativeProgress\r\n" + "5 / 9 : RelativeProgress\r\n" + "6 / 9 : RelativeProgress\r\n" + "7 / 9 : RelativeProgress\r\n" + "8 / 9 : RelativeProgress\r\n" + "9 / 9 : Finalization\r\n"; ### GraphCutHelper with OrphanedPoints specified Test that OrphanedPoints specification in the AutoMaskingGraphCutOptions does have an effect on the masking result in a MaskingSession. string inputFilePath = "Gorilla.bmp"; string tempFilePath = "temp.png"; string initialOutputFilePath = "initialOutput.png"; string improvedOutputFilePath = "improvedOutput.png"; using (RasterImage image = (RasterImage)Image.Load(inputFilePath)) { AutoMaskingGraphCutOptions maskingOptions = new AutoMaskingGraphCutOptions() { Method = SegmentationMethod.GraphCut, Args = new AutoMaskingArgs { ObjectsRectangles = new Rectangle[] { new Rectangle(86, 6, 270, 364), } }, Decompose = false, ExportOptions = new PngOptions() { Source = new FileCreateSource(tempFilePath) }, BackgroundReplacementColor = Color.Orange, CalculateDefaultStrokes = true, FeatheringRadius = 2 }; using (IMaskingSession maskingSession = new ImageMasking(image).CreateSession(maskingOptions)) { MaskingResult maskingResult = maskingSession.Decompose(); using (RasterImage resultImage = (RasterImage)maskingResult[1].GetImage()) { resultImage.Save(initialOutputFilePath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } // At this point initial masking results can be viewed and analyzed. // Orphaned points should be from the foreground/background points // or areas where foreground/background points are supposed to be. var orphanedPoints = new List(); orphanedPoints.AddRange(GetRectanglePoints(new Rectangle[] { new Rectangle(0, 0, 200, 300), })); orphanedPoints.AddRange(maskingOptions.DefaultForegroundStrokes); orphanedPoints.AddRange(maskingOptions.DefaultBackgroundStrokes); maskingResult = maskingSession.ImproveDecomposition(new AutoMaskingArgs() { OrphanedPoints = orphanedPoints.ToArray() }); using (RasterImage resultImage = (RasterImage)maskingResult[1].GetImage()) { resultImage.Save(improvedOutputFilePath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } // At this point we can check that the result image has changed. } } // Return all points that belongs to the specified rectangles. Point[] GetRectanglePoints(params Rectangle[] rectangles) { int arraySize = 0; foreach (Rectangle rectangle in rectangles) { arraySize += rectangle.Width * rectangle.Height; } Point[] pointArray = new Point[arraySize]; int arrayIndex = 0; foreach (Rectangle rectangle in rectangles) { for (int x = rectangle.Left; x < rectangle.Right; x++) { for (int y = rectangle.Top; y < rectangle.Bottom; y++) { pointArray[arrayIndex++] = new Point(x, y); } } } return pointArray; }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn