彩票走势图

示例演示!图像处理控件Aspose.Imaging最新版新功能上线!实现一系列图像创建动画功能

原创|产品更新|编辑:李显亮|2021-01-04 10:06:57.557|阅读 164 次

概述: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

整合所有格式API处理控件Aspose永久授权正在慧都网火热销售中,立马1分钟了解全部咨询!

新增与改善

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修复

用法示例

IMAGINGNET-4154 实现了从图像阵列创建动画的功能

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));
}

IMAGINGNET-4144 支持访问丢失的Exif属性

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");
}

IMAGINGNET-4010 重做多页图像相关的方法和属性,以使其易于使用

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));
}

IMAGINGNET-4227 改善GraphCutHelper性能和异步实现

### 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; }

还想要更多吗?您可以点击阅读【2020 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(761297826),我们很高兴为您提供查询和咨询

标签:

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


为你推荐

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


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP