1. 产品
  2.   图片
  3.   .NET
  4.   Aspose.Imaging for .NET

Aspose.Imaging for .NET

 
 

C# .NET API 用于创建、编辑和转换图像

一个有用的 C# ASP.NET 高级图像处理 API,允许软件开发人员创建、编辑、加载、操作、转换和压缩图像。

Aspose.Imaging for .NET 是一个功能强大且灵活的库,它提供高级图像处理功能,无需在机器上安装任何图像编辑器。该库支持多种图像文件格式,包括 JPEG、BMP、TIFF、GIF、PNG、DICOM、TGA、ICO、EMZ、WMZ、WebP、Svg、Svgz 等等。该库非常灵活,可以与 ASP.NET Web 应用程序以及 Windows 桌面应用程序一起使用。

Aspose.Imaging for .NET 库包含各种图像绘制功能,例如旋转、翻转、缩放、裁剪、绘制和填充基本形状(线、多边形、矩形、三次贝塞尔曲线、曲线、圆弧、椭圆、饼图和路径)、裁剪到矩形区域、矩阵变换、矢量到光栅导出、自定义用户图像等。它还提供了一套全面的 API 来处理 EXIF 和 IPTC 元数据,使开发人员能够读取和写入图像元数据,包括图像描述、作者等。

Aspose.Imaging for .NET 针对高速图像处理进行了优化,并支持并行处理,使软件开发人员能够快速高效地执行复杂的图像处理任务。该库具有高度可定制性,允许开发人员轻松扩展库以满足他们的特定需求。例如,他们可以创建自定义图像过滤器并通过几个简单的步骤将其应用于图像。他们还可以创建自定义图像格式处理程序,使他们能够处理库不支持的独特图像格式。

Previous Next

开始使用 Aspose.Imaging for .NET

安装 Aspose.Imaging for .NET 的推荐方法是使用 NuGet。请使用以下命令顺利安装。

通过 NuGet 安装 Aspose.Imaging for .NET

NuGet\Install-Package Aspose.Imaging -Version 22.12.0 
您也可以直接从Aspose 产品页面下载它。

通过 .NET API 创建和管理图像

Aspose.Imaging for .NET 包含了在 .NET 应用程序内创建和管理新图像的完整功能。该库允许软件开发人员从头开始创建新图像、通过设置路径生成图像、使用流创建图像等。该库还允许用户从磁盘或流中打开现有图像、对其进行所需的更改并将其保存到他们选择的位置。该库支持图像颜色调整、设置亮度和对比度、调整伽玛、应用模糊效果、应用图像透明度、调整图像大小、提取文本作为形状等等。

如何通过 .NET API 使用流创建图像?

using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;
using Aspose.Imaging.Sources;
using System.IO;

string templatesFolder = @"c:\Users\USER\Downloads\templates\";
string dataDir = templatesFolder;

// Creates an instance of BmpOptions and set its various properties
BmpOptions ImageOptions = new BmpOptions();
ImageOptions.BitsPerPixel = 24;

// Create an instance of System.IO.Stream
Stream stream = new FileStream(dataDir + "result1.bmp", FileMode.Create);

// Define the source property for the instance of BmpOptions Second boolean parameter determines if the Stream is disposed once get out of scope
ImageOptions.Source = new StreamSource(stream, true);

// Creates an instance of Image and call Create method by passing the BmpOptions object
using (Image image = Image.Create(ImageOptions, 500, 500))
{
    // Do some image processing
    image.Save(dataDir + "result2.bmp");
}

File.Delete(dataDir + "result1.bmp");
File.Delete(dataDir + "result2.bmp");

通过 C# .NET API 进行图像转换

Aspose.Imaging for .NET 使软件开发人员能够在自己的应用程序内转换不同类型的图像。通常需要将彩色图像转换为黑白或灰度以用于打印或存档。该库支持多种图像格式,包括 JPEG、BMP、TIFF、GIF、PNG、DICOM、TGA、ICO、EMZ、WMZ、WebP、SVG、SVGZ 等等。一些常见的图像转换示例包括将 GIF 图像的图层转换为 TIFF、将光栅图像转换为 PDF、将 RGB 颜色系统转换为 CMYK、将 SVG 转换为光栅图像、将 SVG 转换为 PNG 以及将 SVG 转换为 Bmp 等等。

通过 C# API 将图像转换为灰度图像

using Aspose.Imaging;
using System.IO;

string templatesFolder = @"c:\Users\USER\Downloads\templates\";
string dataDir = templatesFolder;

// Load an image in an instance of Image
using (Image image = Image.Load(dataDir + "template.jpg"))
{
    // Cast the image to RasterCachedImage and Check if image is cached                
    RasterCachedImage rasterCachedImage = (RasterCachedImage)image;
    if (!rasterCachedImage.IsCached)
    {
        // Cache image if not already cached
        rasterCachedImage.CacheData();
    }

    // Binarize image with predefined fixed threshold and Save the resultant image                
    rasterCachedImage.Grayscale();
    rasterCachedImage.Save(dataDir + "result.jpg");
}


File.Delete(dataDir + "result.jpg");

使用 .NET API 进行图像处理

Aspose.Imaging for .NET 使软件开发人员能够在自己的 C# .NET 应用程序中创建新图像并处理不同类型的图像。该库提供了与图像处理相关的几个重要功能,例如图像背景去除、应用中值和维纳滤波器、将图像转换为不同的文件格式、合并图像、裁剪、旋转和调整图像大小、设置图像属性、处理多页图像格式等。此外,该库还支持处理不同的图像文件格式,例如 JPEG、CMX、CorelDraw、GNG、TMA、SVG、BMP、TIFF、GIF、PNG、DICOM、TGA、ICO、EMZ、WMZ 等。

通过 C# API 对 PNG 图像应用过滤器

using Aspose.Imaging;
using Aspose.Imaging.FileFormats.Png;
using Aspose.Imaging.ImageOptions;
using System.IO;

string templatesFolder = @"c:\Users\USER\Downloads\templates\";
string dataDir = templatesFolder;

using (PngImage png = (PngImage)Image.Load(dataDir + "template.png"))
{
    // Create an instance of PngOptions, Set the PNG filter method and Save changes to the disc
    PngOptions options = new PngOptions();
    options.FilterType = PngFilterType.Paeth;
    png.Save(dataDir + "result.png", options);
}

File.Delete(dataDir + "result.png");

通过 .NET API 绘制图像和形状

Aspose.Imaging for .NET 完全支持轻松绘制各种类型的形状和图像。它允许软件开发人员绘制不同类型的形状和图像,如线条、椭圆、矩形、圆弧、贝塞尔曲线等。该库还支持使用核心功能绘制图像,例如处理图像的位图信息,或使用 Graphics 和 GraphicsPath 等高级功能借助不同的画笔和笔在图像表面上绘制形状。该库可以轻松检索图像区域的像素信息并根据用户需要对其进行操作。

如何通过 .NET API 在图像表面添加矩形形状?

using Aspose.Imaging;
using Aspose.Imaging.Brushes;
using Aspose.Imaging.ImageOptions;
using Aspose.Imaging.Sources;
using System.IO;

string templatesFolder = @"c:\Users\USER\Downloads\templates\";
string dataDir = templatesFolder;

// Creates an instance of FileStream
using (FileStream stream = new FileStream(dataDir + "result.bmp", FileMode.Create))
{
    // Create an instance of BmpOptions and set its various properties
    BmpOptions saveOptions = new BmpOptions();
    saveOptions.BitsPerPixel = 32;

    // Set the Source for BmpOptions and Create an instance of Image
    saveOptions.Source = new StreamSource(stream);
    using (Image image = Image.Create(saveOptions, 100, 100))
    {
        // Create and initialize an instance of Graphics class,  Clear Graphics surface, Draw a rectangle shapes and  save all changes.
        Graphics graphic = new Graphics(image);
        graphic.Clear(Color.Yellow);
        graphic.DrawRectangle(new Pen(Color.Red), new Rectangle(30, 10, 40, 80));
        graphic.DrawRectangle(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40));
        image.Save();
    }
}

File.Delete(dataDir + "result.bmp");
 中国人