Class PngImage

Class PngImage

名称: Aspose.Imaging.FileFormats.Png 收藏: Aspose.Imaging.dll (25.4.0)

使用我们的多元化 API 操纵移动网络图形(PNG)图像,支持压缩水平和各种颜色深度,包括Grayscale、Indexed Color、TrueColor 和 Alpha 频道 无缝处理 XMP 数据,允许全面的图像数据管理,同时轻松加载 PNG 图像,进行多种操作,应用过滤器,并将图像转换为其他文件最佳多样性和定制的格式。

[JsonObject(MemberSerialization.OptIn)]
public class PngImage : RasterCachedImage, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata

Inheritance

object DisposableObject DataStreamSupporter Image RasterImage RasterCachedImage PngImage

Implements

IDisposable , IObjectWithBounds , IRasterImageArgb32PixelLoader , IRasterImageRawDataLoader , IHasXmpData , IHasMetadata

继承人

RasterCachedImage.CacheData() , RasterCachedImage.Blend(Point, RasterImage, Rectangle, byte) , RasterCachedImage.Resize(int, int, ResizeType) , RasterCachedImage.Resize(int, int, ImageResizeSettings) , RasterCachedImage.RotateFlip(RotateFlipType) , RasterCachedImage.Rotate(float, bool, Color) , RasterCachedImage.Crop(Rectangle) , RasterCachedImage.Dither(DitheringMethod, int, IColorPalette) , RasterCachedImage.Grayscale() , RasterCachedImage.NormalizeHistogram() , RasterCachedImage.BinarizeFixed(byte) , RasterCachedImage.BinarizeOtsu() , RasterCachedImage.BinarizeBradley(double, int) , RasterCachedImage.BinarizeBradley(double) , RasterCachedImage.AdjustBrightness(int) , RasterCachedImage.AdjustContrast(float) , RasterCachedImage.AdjustGamma(float, float, float) , RasterCachedImage.AdjustGamma(float) , RasterCachedImage.OnCached() , RasterCachedImage.OnPaletteChanged(IColorPalette, IColorPalette) , RasterCachedImage.IsCached , RasterImage.xmpData , RasterImage.RemoveMetadata() , RasterImage.Save(Stream, ImageOptionsBase, Rectangle) , RasterImage.GetModifyDate(bool) , RasterImage.Dither(DitheringMethod, int) , RasterImage.Dither(DitheringMethod, int, IColorPalette) , RasterImage.GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader) , RasterImage.GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings) , RasterImage.GetDefaultArgb32Pixels(Rectangle) , RasterImage.GetDefaultRawData(Rectangle, RawDataSettings) , RasterImage.GetArgb32Pixel(int, int) , RasterImage.GetPixel(int, int) , RasterImage.SetArgb32Pixel(int, int, int) , RasterImage.SetPixel(int, int, Color) , RasterImage.ReadScanLine(int) , RasterImage.ReadArgb32ScanLine(int) , RasterImage.WriteScanLine(int, Color[]) , RasterImage.WriteArgb32ScanLine(int, int[]) , RasterImage.LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader) , RasterImage.LoadPartialPixels(Rectangle, IPartialPixelLoader) , RasterImage.LoadArgb32Pixels(Rectangle) , RasterImage.LoadArgb64Pixels(Rectangle) , RasterImage.LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader) , RasterImage.LoadPixels(Rectangle) , RasterImage.LoadCmykPixels(Rectangle) , RasterImage.LoadCmyk32Pixels(Rectangle) , RasterImage.LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader) , RasterImage.LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader) , RasterImage.SaveRawData(byte[], int, Rectangle, RawDataSettings) , RasterImage.SaveArgb32Pixels(Rectangle, int[]) , RasterImage.SavePixels(Rectangle, Color[]) , RasterImage.SaveCmykPixels(Rectangle, CmykColor[]) , RasterImage.SaveCmyk32Pixels(Rectangle, int[]) , RasterImage.SetResolution(double, double) , RasterImage.SetPalette(IColorPalette, bool) , RasterImage.Resize(int, int, ImageResizeSettings) , RasterImage.Rotate(float, bool, Color) , RasterImage.Rotate(float) , RasterImage.BinarizeFixed(byte) , RasterImage.BinarizeOtsu() , RasterImage.BinarizeBradley(double) , RasterImage.BinarizeBradley(double, int) , RasterImage.Blend(Point, RasterImage, Rectangle, byte) , RasterImage.Blend(Point, RasterImage, byte) , RasterImage.Grayscale() , RasterImage.NormalizeHistogram() , RasterImage.AdjustBrightness(int) , RasterImage.AdjustContrast(float) , RasterImage.AdjustGamma(float, float, float) , RasterImage.AdjustGamma(float) , RasterImage.GetSkewAngle() , RasterImage.NormalizeAngle() , RasterImage.NormalizeAngle(bool, Color) , RasterImage.Filter(Rectangle, FilterOptionsBase) , RasterImage.ReplaceColor(Color, byte, Color) , RasterImage.ReplaceColor(int, byte, int) , RasterImage.ReplaceNonTransparentColors(Color) , RasterImage.ReplaceNonTransparentColors(int) , RasterImage.ToBitmap() , RasterImage.ReleaseManagedResources() , RasterImage.UpdateMetadata() , RasterImage.UpdateDimensions(int, int) , RasterImage.PremultiplyComponents , RasterImage.UseRawData , RasterImage.UpdateXmpData , RasterImage.XmpData , RasterImage.RawIndexedColorConverter , RasterImage.RawCustomColorConverter , RasterImage.RawFallbackIndex , RasterImage.RawDataSettings , RasterImage.UsePalette , RasterImage.RawDataFormat , RasterImage.RawLineSize , RasterImage.IsRawDataAvailable , RasterImage.HorizontalResolution , RasterImage.VerticalResolution , RasterImage.HasTransparentColor , RasterImage.HasAlpha , RasterImage.TransparentColor , RasterImage.ImageOpacity , RasterImage.DataLoader , Image.CanLoad(string) , Image.CanLoad(string, LoadOptions) , Image.CanLoad(Stream) , Image.CanLoad(Stream, LoadOptions) , Image.Create(ImageOptionsBase, int, int) , Image.Create(Image[]) , Image.Create(MultipageCreateOptions) , Image.Create(string[], bool) , Image.Create(string[]) , Image.Create(Image[], bool) , Image.GetFileFormat(string) , Image.GetFileFormat(Stream) , Image.GetFittingRectangle(Rectangle, int, int) , Image.GetFittingRectangle(Rectangle, int[], int, int) , Image.Load(string, LoadOptions) , Image.Load(string) , Image.Load(Stream, LoadOptions) , Image.Load(Stream) , Image.GetProportionalWidth(int, int, int) , Image.GetProportionalHeight(int, int, int) , Image.RemoveMetadata() , Image.CanSave(ImageOptionsBase) , Image.Resize(int, int) , Image.Resize(int, int, ResizeType) , Image.Resize(int, int, ImageResizeSettings) , Image.GetDefaultOptions(object[]) , Image.GetOriginalOptions() , Image.ResizeWidthProportionally(int) , Image.ResizeHeightProportionally(int) , Image.ResizeWidthProportionally(int, ResizeType) , Image.ResizeHeightProportionally(int, ResizeType) , Image.ResizeWidthProportionally(int, ImageResizeSettings) , Image.ResizeHeightProportionally(int, ImageResizeSettings) , Image.RotateFlip(RotateFlipType) , Image.Rotate(float) , Image.Crop(Rectangle) , Image.Crop(int, int, int, int) , Image.Save() , Image.Save(string) , Image.Save(string, ImageOptionsBase) , Image.Save(string, ImageOptionsBase, Rectangle) , Image.Save(Stream, ImageOptionsBase) , Image.Save(Stream, ImageOptionsBase, Rectangle) , Image.GetSerializedStream(ImageOptionsBase, Rectangle, out int) , Image.SetPalette(IColorPalette, bool) , Image.UpdateContainer(Image) , Image.GetCanNotSaveMessage(ImageOptionsBase) , Image.GetFitRectangle(Rectangle) , Image.GetImage2Export(ImageOptionsBase, Rectangle, IImageExporter) , Image.GetFitRectangle(Rectangle, int[]) , Image.OnPaletteChanged(IColorPalette, IColorPalette) , Image.OnPaletteChanging(IColorPalette, IColorPalette) , Image.ReleaseManagedResources() , Image.BitsPerPixel , Image.Bounds , Image.Container , Image.Height , Image.Palette , Image.UsePalette , Image.Size , Image.Width , Image.InterruptMonitor , Image.BufferSizeHint , Image.AutoAdjustPalette , Image.HasBackgroundColor , Image.FileFormat , Image.BackgroundColor , DataStreamSupporter.timeout , DataStreamSupporter.CacheData() , DataStreamSupporter.Save() , DataStreamSupporter.Save(Stream) , DataStreamSupporter.Save(string) , DataStreamSupporter.Save(string, bool) , DataStreamSupporter.SaveData(Stream) , DataStreamSupporter.ReleaseManagedResources() , DataStreamSupporter.OnDataStreamContainerChanging(StreamContainer) , DataStreamSupporter.DataStreamContainer , DataStreamSupporter.IsCached , DisposableObject.Dispose() , DisposableObject.ReleaseManagedResources() , DisposableObject.ReleaseUnmanagedResources() , DisposableObject.VerifyNotDisposed() , DisposableObject.Disposed , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

此示例显示如何从文件中加载 PNG 图像。

string dir = "c:\\temp\\";

                                                                  // Load a PNG image from a file.
                                                                  using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(dir + "sample.png"))
                                                                  {
                                                                      // Transform the image to grayscale representation
                                                                      pngImage.Grayscale();

                                                                      // Save to a file.
                                                                      pngImage.Save(dir + "sample.grayscale.png");
                                                                  }

Constructors

PngImage(int , int , int)

启动 Aspose.Imaging.FileFormats.Png.PngImage 类的新对象,通过提供宽度和高度参数. 这种构建器简化了 PNG 的创建图像,允许开发人员直接指定尺寸,方便在其应用中有效管理 PNG 图像数据。

public PngImage(int width, int height)

Parameters

width int

宽度。

height int

身高。

Examples

此示例显示如何创建指定的尺寸的 PNG 图像,用坚固的颜色填写并将其保存到文件中。

string dir = "c:\\temp\\";

                                                                                                                                // Create a PNG image of 100x100 px.
                                                                                                                                using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(100, 100))
                                                                                                                                {
                                                                                                                                    // Do some image processing, e.g. fill the entire image in red.
                                                                                                                                    Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
                                                                                                                                    Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
                                                                                                                                    graphics.FillRectangle(brush, pngImage.Bounds);

                                                                                                                                    // Save to a file.
                                                                                                                                    pngImage.Save(dir + "output.png");
                                                                                                                                }

PngImage(线条)

使用路径构建 Aspose.Imaging.FileFormats.Png.PngImage 类的新例子参数指定图像文件的位置加载。允许开发人员通过从文件上加载它们来方便地创建 PNG 图像,在应用程序中简化使用 PNG 图像的过程。

public PngImage(string path)

Parameters

path string

路径上传图像。

Examples

此示例显示如何从文件中加载 PNG 图像。

string dir = "c:\\temp\\";

                                                                  // Load a PNG image from a file.
                                                                  using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(dir + "sample.png"))
                                                                  {
                                                                      // Transform the image to grayscale representation
                                                                      pngImage.Grayscale();

                                                                      // Save to a file.
                                                                      pngImage.Save(dir + "sample.grayscale.png");
                                                                  }

PngImage(RasterImage)

创建 Aspose.Imaging.FileFormats.Png.PngImage 类的新例子,提供一个拉斯特图像作为一个参数. 这个构建器允许开发人员直接启动一个PNG 图像对象使用现有拉斯特图像,简化过程在他们的应用中使用PNG图像。

public PngImage(RasterImage rasterImage)

Parameters

rasterImage RasterImage

拉斯特图像。

Examples

此示例显示如何从 BMP 图像上传 PNG 图像。

string dir = "c:\\temp\\";

                                                                     // Load a TrueColor PNG image from a BMP image.
                                                                     // First, create a temporal BMP image that will be a foundation for building a PNG image.
                                                                     // You can also load BMP image from a file or use an image of any other raster format.
                                                                     using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100))
                                                                     {
                                                                         // Fill the entire BMP image in red.
                                                                         Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
                                                                         Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
                                                                         gr.FillRectangle(brush, bmpImage.Bounds);

                                                                         using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(bmpImage))
                                                                         {
                                                                             System.Console.WriteLine("The PNG color type: {0}", pngImage.GetOriginalOptions());
                                                                             pngImage.Save(dir + "output.png");
                                                                         }
                                                                     }

PngImage(彩色,PngColorType)

启动 Aspose.Imaging.FileFormats.Png.PngImage 类的新例子,通过指定路径到图像文件和颜色类型. 这个构建器允许方便创建不同颜色类型的文件中的 PNG 图像,提供灵活处理各种图像格式。

public PngImage(string path, PngColorType colorType)

Parameters

path string

路径上传图像。

colorType PngColorType

颜色类型。

Examples

此示例显示如何从指定的颜色类型的文件上传 PNG 图像。

string dir = "c:\\temp\\";

                                                                                                // Load a PNG image from a file.
                                                                                                // Note that the colorful image will be converted to grayscale automatically.
                                                                                                using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(dir + "sample.png", Aspose.Imaging.FileFormats.Png.PngColorType.Grayscale))
                                                                                                {
                                                                                                    // Save to a file.
                                                                                                    pngImage.Save(dir + "sample.grayscale.png");
                                                                                                }

Exceptions

ArgumentNullException

PngImage(彩色,PngColorType)

创建 Aspose.Imaging.FileFormats.Png.PngImage 类的新例子,指定一个拉斯特图像和颜色类型. 这个构建器允许开发人员直接将拉斯特图像转换为 PNG 格式,同时指定所需的颜色类型,提供色彩代表性的灵活性。

public PngImage(RasterImage rasterImage, PngColorType colorType)

Parameters

rasterImage RasterImage

拉斯特图像。

colorType PngColorType

颜色类型。

Examples

此示例显示如何从 BMP 图像上传 PNG 图像与指定的颜色类型。

string dir = "c:\\temp\\";

                                                                                                   // Load a grayscale PNG image from a colored BMP image.
                                                                                                   // First, create a temporal BMP image that will be a foundation for building a PNG image.
                                                                                                   // You can also load BMP image from a file or use an image of any other raster format.
                                                                                                   using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100))
                                                                                                   {
                                                                                                       // Fill the entire BMP image in red.
                                                                                                       Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
                                                                                                       Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
                                                                                                       gr.FillRectangle(brush, bmpImage.Bounds);

                                                                                                       // The colors of the image pixels will be converted to their grayscale counterparts.
                                                                                                       using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(bmpImage, Aspose.Imaging.FileFormats.Png.PngColorType.Grayscale))
                                                                                                       {
                                                                                                           pngImage.Save(dir + "output.grayscale.png");
                                                                                                       }
                                                                                                   }

PngImage(Stream)

创建 Aspose.Imaging.FileFormats.Png.PngImage 类的新例子,通过启动它这个构建器允许开发人员直接加载 PNG 图像从一个流,提供灵活的图像从不同的来源的回收。

public PngImage(Stream stream)

Parameters

stream Stream

流来加载图像。

Examples

此示例显示如何从文件或文件流中加载 PNG 图像。

string dir = "c:\\temp\\";

                                                                                   // Load a PNG image from a file stream.
                                                                                   using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.png"))
                                                                                   {
                                                                                       using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(stream))
                                                                                       {
                                                                                           // Transform the image to grayscale representation
                                                                                           pngImage.Grayscale();

                                                                                           // Save to a file.
                                                                                           pngImage.Save(dir + "sample.grayscale.png");
                                                                                       }
                                                                                   }

PngImage(int, int, PngColorType)

即时启动 Aspose.Imaging.FileFormats.Png.PngImage 类的新例子,指定所需的宽度、高度和颜色类型参数. 此构建器可快速创建定制尺寸和颜色配置的 PNG 图像,促进各种应用和工作流的简化图像生成。

public PngImage(int width, int height, PngColorType colorType)

Parameters

width int

宽度。

height int

身高。

colorType PngColorType

颜色类型。

Examples

此示例显示如何使用指定的颜色类型创建指定的尺寸的 PNG 图像,用坚固的颜色填写并将其保存到文件中。

string dir = "c:\\temp\\";

                                                                                                                                                              // Create a grayscale PNG image of 100x100 px.
                                                                                                                                                              // All colors will be automatically converted to the grayscale format.
                                                                                                                                                              using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(100, 100, Aspose.Imaging.FileFormats.Png.PngColorType.Grayscale))
                                                                                                                                                              {
                                                                                                                                                                  // Do some image processing, e.g. fill the entire image in red.
                                                                                                                                                                  Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
                                                                                                                                                                  Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
                                                                                                                                                                  graphics.FillRectangle(brush, pngImage.Bounds);

                                                                                                                                                                  // Save to a file.
                                                                                                                                                                  pngImage.Save(dir + "output.grayscale.png");
                                                                                                                                                              }

PngImage(PngOptions, int, int)

启动 Aspose.Imaging.FileFormats.Png.PngImage 类的新例子,包含PNG 选项与宽度和高度参数相结合。开发人员创建可自定义设置和尺寸的 PNG 图像,提供图像生成中的灵活性,适用于各种使用情况。

public PngImage(PngOptions pngOptions, int width, int height)

Parameters

pngOptions PngOptions

png选项。

width int

宽度。

height int

身高。

Examples

此示例显示如何使用指定的选项创建 PNG 图像,用线性格拉迪特颜色填写它,并将其保存到文件中。

string dir = "c:\\temp\\";

                                                                                                                                                Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                                                                // The number of bits per color channel
                                                                                                                                                createOptions.BitDepth = 8;

                                                                                                                                                // Each pixel is a (red, green, blue) triple followed by the alpha component.
                                                                                                                                                createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

                                                                                                                                                // The maximum level of compression.
                                                                                                                                                createOptions.CompressionLevel = 9;

                                                                                                                                                // Usage of filters allows to compress continuous tonal images more effectively.
                                                                                                                                                createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;

                                                                                                                                                // Use progressive loading
                                                                                                                                                createOptions.Progressive = true;

                                                                                                                                                // Create a PNG image with custom parameters.
                                                                                                                                                using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(createOptions, 100, 100))
                                                                                                                                                {
                                                                                                                                                    Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
                                                                                                                                                            new Aspose.Imaging.Point(0, 0),
                                                                                                                                                            new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
                                                                                                                                                            Aspose.Imaging.Color.Blue,
                                                                                                                                                            Aspose.Imaging.Color.Transparent);

                                                                                                                                                    Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);

                                                                                                                                                    // Fill the image with a semi-transparent gradient.
                                                                                                                                                    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

                                                                                                                                                    // Save to a file.
                                                                                                                                                    pngImage.Save(dir + "output.explicitoptions.png");
                                                                                                                                                }

Properties

BackgroundColor

返回图像的背景颜色,如果一个是指定的。有助于需要识别和潜在操纵的应用程序背景图像的颜色。

public override Color BackgroundColor { get; set; }

财产价值

Color

Examples

下面的示例显示如何为不支持阿尔法频道的 TrueColor PNG 图像的一部分设置完全透明的颜色。

Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                                                                                   createOptions.Source = new Aspose.Imaging.Sources.FileCreateSource("c:\\temp\\transparent.png", false);
                                                                                                                                                   createOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.Truecolor;

                                                                                                                                                   // Create a TrueColor PNG image of 100x100 px.
                                                                                                                                                   using (Aspose.Imaging.Image image = Image.Create(createOptions, 100, 100))
                                                                                                                                                   {
                                                                                                                                                       Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)image;
                                                                                                                                                       Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(pngImage);

                                                                                                                                                       // All red pixels will be considered as fully transparent.
                                                                                                                                                       pngImage.TransparentColor = Aspose.Imaging.Color.Red;
                                                                                                                                                       pngImage.HasTransparentColor = true;

                                                                                                                                                       // All transparent pixels will have a background color.
                                                                                                                                                       pngImage.BackgroundColor = Aspose.Imaging.Color.Green;
                                                                                                                                                       pngImage.HasBackgroundColor = true;

                                                                                                                                                       // Fill the entire image with white color.
                                                                                                                                                       gr.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.White), pngImage.Bounds);

                                                                                                                                                       // Fill the top-left quarter of the image with the transparent color.
                                                                                                                                                       // This makes the top-left quarter colored in the background color.
                                                                                                                                                       Rectangle rect = new Rectangle(0, 0, pngImage.Width / 2, pngImage.Height / 2);
                                                                                                                                                       gr.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red), rect);

                                                                                                                                                       pngImage.Save();
                                                                                                                                                   }

BitsPerPixel

恢复图像的比特每像素值. 此属性提供关键关于图像的颜色深度的信息,使开发人员能够了解图像数据中的细节和颜色准确度。

public override int BitsPerPixel { get; }

财产价值

int

FileFormat

返回与图像示例相关的文件格式。财产提供有关文件类型的基本信息,可以具体格式要求为基础的有效处理和处理。

public override FileFormat FileFormat { get; }

财产价值

FileFormat

HasAlpha

返回一个 boolean 值,表明图像是否有 alpha 频道,确定其透明度. 此属性对应用有用需要处理透明度,使开发人员能够确定是否需要额外的处理,以便处理图像中的透明区域。

public override bool HasAlpha { get; }

财产价值

bool

Examples

下面的示例显示如何检查 PNG 图像是否支持 Alpha 频道。

// Get all supported PNG color types.
                                                                                          System.Array colorTypes = System.Enum.GetValues(typeof(Aspose.Imaging.FileFormats.Png.PngColorType));

                                                                                          foreach (Aspose.Imaging.FileFormats.Png.PngColorType colorType in colorTypes)
                                                                                          {
                                                                                              Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                              createOptions.Source = new Sources.StreamSource(new System.IO.MemoryStream());
                                                                                              createOptions.ColorType = colorType;

                                                                                              using (Aspose.Imaging.Image image = Image.Create(createOptions, 100, 100))
                                                                                              {
                                                                                                  Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)image;

                                                                                                  if (pngImage.HasAlpha)
                                                                                                  {
                                                                                                      System.Console.WriteLine("A {0} PNG image supports alpha channel", createOptions.ColorType);
                                                                                                  }
                                                                                                  else
                                                                                                  {
                                                                                                      System.Console.WriteLine("A {0} PNG image doesn't support alpha channel", createOptions.ColorType);
                                                                                                  }
                                                                                              }
                                                                                          }

                                                                                          // The output looks like this:
                                                                                          // A Grayscale PNG image doesn't support alpha channel
                                                                                          // A Truecolor PNG image doesn't support alpha channel
                                                                                          // A IndexedColor PNG image doesn't support alpha channel
                                                                                          // A GrayscaleWithAlpha PNG image supports alpha channel
                                                                                          // A TruecolorWithAlpha PNG image supports alpha channel

HasBackgroundColor

返回一个 boolean 值,表明图像是否有背景颜色。此属性对应用程序有用,需要确定图像是否包含背景颜色,这对各种处理可能很重要。任务如编辑、交付或出口。

public override bool HasBackgroundColor { get; set; }

财产价值

bool

Examples

下面的示例显示如何为不支持阿尔法频道的 TrueColor PNG 图像的一部分设置完全透明的颜色。

Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                                                                                   createOptions.Source = new Aspose.Imaging.Sources.FileCreateSource("c:\\temp\\transparent.png", false);
                                                                                                                                                   createOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.Truecolor;

                                                                                                                                                   // Create a TrueColor PNG image of 100x100 px.
                                                                                                                                                   using (Aspose.Imaging.Image image = Image.Create(createOptions, 100, 100))
                                                                                                                                                   {
                                                                                                                                                       Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)image;
                                                                                                                                                       Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(pngImage);

                                                                                                                                                       // All red pixels will be considered as fully transparent.
                                                                                                                                                       pngImage.TransparentColor = Aspose.Imaging.Color.Red;
                                                                                                                                                       pngImage.HasTransparentColor = true;

                                                                                                                                                       // All transparent pixels will have a background color.
                                                                                                                                                       pngImage.BackgroundColor = Aspose.Imaging.Color.Green;
                                                                                                                                                       pngImage.HasBackgroundColor = true;

                                                                                                                                                       // Fill the entire image with white color.
                                                                                                                                                       gr.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.White), pngImage.Bounds);

                                                                                                                                                       // Fill the top-left quarter of the image with the transparent color.
                                                                                                                                                       // This makes the top-left quarter colored in the background color.
                                                                                                                                                       Rectangle rect = new Rectangle(0, 0, pngImage.Width / 2, pngImage.Height / 2);
                                                                                                                                                       gr.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red), rect);

                                                                                                                                                       pngImage.Save();
                                                                                                                                                   }

HasTransparentColor

提供一个 boolean 值,表明图像是否包含透明此属性对于需要处理的应用程序至关重要透明度,使开发人员能够确定是否有额外的处理需要在图像中处理透明区域。

public override bool HasTransparentColor { get; set; }

财产价值

bool

Examples

下面的示例显示如何为不支持阿尔法频道的 TrueColor PNG 图像的一部分设置完全透明的颜色。

Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                                                                                   createOptions.Source = new Aspose.Imaging.Sources.FileCreateSource("c:\\temp\\transparent.png", false);
                                                                                                                                                   createOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.Truecolor;

                                                                                                                                                   // Create a TrueColor PNG image of 100x100 px.
                                                                                                                                                   using (Aspose.Imaging.Image image = Image.Create(createOptions, 100, 100))
                                                                                                                                                   {
                                                                                                                                                       Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)image;
                                                                                                                                                       Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(pngImage);

                                                                                                                                                       // All red pixels will be considered as fully transparent.
                                                                                                                                                       pngImage.TransparentColor = Aspose.Imaging.Color.Red;
                                                                                                                                                       pngImage.HasTransparentColor = true;

                                                                                                                                                       // All transparent pixels will have a background color.
                                                                                                                                                       pngImage.BackgroundColor = Aspose.Imaging.Color.Green;
                                                                                                                                                       pngImage.HasBackgroundColor = true;

                                                                                                                                                       // Fill the entire image with white color.
                                                                                                                                                       gr.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.White), pngImage.Bounds);

                                                                                                                                                       // Fill the top-left quarter of the image with the transparent color.
                                                                                                                                                       // This makes the top-left quarter colored in the background color.
                                                                                                                                                       Rectangle rect = new Rectangle(0, 0, pngImage.Width / 2, pngImage.Height / 2);
                                                                                                                                                       gr.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red), rect);

                                                                                                                                                       pngImage.Save();
                                                                                                                                                   }

Height

获取图像的高度. 此属性返回垂直的尺寸图像,允许开发人员确定其尺寸在像素沿着垂直轴。

public override int Height { get; }

财产价值

int

HorizontalResolution

修复或修改图像的水平分辨率。代表每英寸的像素数量,沿着垂直轴的图像:调整此分辨率可能会影响图像的物理大小印刷或显示。

public override double HorizontalResolution { get; set; }

财产价值

double

Examples

下面的示例显示如何设置 PNG 图像的水平/垂直分辨率。

string dir = "c:\\temp\\";

                                                                                                using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
                                                                                                {
                                                                                                    Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)image;

                                                                                                    // Get horizontal and vertical resolution of the PngImage.
                                                                                                    double horizontalResolution = pngImage.HorizontalResolution;
                                                                                                    double verticalResolution = pngImage.VerticalResolution;
                                                                                                    System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
                                                                                                    System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);

                                                                                                    if (horizontalResolution != 96.0 || verticalResolution != 96.0)
                                                                                                    {
                                                                                                        // Use the SetResolution method for updating both resolution values in a single call.
                                                                                                        System.Console.WriteLine("Set resolution values to 96 dpi");
                                                                                                        pngImage.SetResolution(96.0, 96.0);

                                                                                                        System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", pngImage.HorizontalResolution);
                                                                                                        System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", pngImage.VerticalResolution);
                                                                                                    }
                                                                                                }

Interlaced

返回一个 boolean 值,表明 Aspose.Imaging.FileFormats.Png.PngImage 是否相互关联,确定图像数据是否存储在一个进展性更快的充电或传输。

public bool Interlaced { get; }

财产价值

bool

IsInterlaced

返回一个 boolean 值,表明图像示例是否相互关联。财产是优化负载策略和确保效率至关重要的在图像处理或显示任务时的性能。

public bool IsInterlaced { get; }

财产价值

bool

RawDataFormat

访问图像的原始数据格式. 此属性提供洞察力图像数据如何内部结构化,这对先进的图像数据有用图像处理任务或格式转换。

public override PixelDataFormat RawDataFormat { get; }

财产价值

PixelDataFormat

Examples

下面的例子上传了PNG图像,并打印了关于原始数据格式和阿尔法频道的信息。

// The PNG images to load.
                                                                                                                 string[] fileNames = new string[]
                                                                                                                 {
                                                                                                                     @"c:\temp\sample.png",
                                                                                                                     @"c:\temp\alpha.png",
                                                                                                                 };

                                                                                                                 foreach (string fileName in fileNames)
                                                                                                                 {
                                                                                                                     using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(fileName))
                                                                                                                     {
                                                                                                                         Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)image;
                                                                                                                         System.Console.WriteLine("ImageFile={0}, FileFormat={1}, HasAlpha={2}", fileName, pngImage.RawDataFormat, pngImage.HasAlpha);
                                                                                                                     }
                                                                                                                 }

                                                                                                                 // The output may look like this:
                                                                                                                 // ImageFile=c:\temp\sample.png, FileFormat=Rgb24Bpp, used channels: 8,8,8, HasAlpha=False
                                                                                                                 // ImageFile=c:\temp\alpha.png, FileFormat=RGBA32Bpp, used channels: 8,8,8,8, HasAlpha=True

TransparentColor

回收图像的透明颜色,如果它存在。对需要准确处理透明区域的申请有价值在图像中,允许开发人员访问和操纵特定使用透明色彩。

public override Color TransparentColor { get; set; }

财产价值

Color

Examples

下面的示例显示如何为不支持阿尔法频道的 TrueColor PNG 图像的一部分设置完全透明的颜色。

Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                                                                                   createOptions.Source = new Aspose.Imaging.Sources.FileCreateSource("c:\\temp\\transparent.png", false);
                                                                                                                                                   createOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.Truecolor;

                                                                                                                                                   // Create a TrueColor PNG image of 100x100 px.
                                                                                                                                                   using (Aspose.Imaging.Image image = Image.Create(createOptions, 100, 100))
                                                                                                                                                   {
                                                                                                                                                       Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)image;
                                                                                                                                                       Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(pngImage);

                                                                                                                                                       // All red pixels will be considered as fully transparent.
                                                                                                                                                       pngImage.TransparentColor = Aspose.Imaging.Color.Red;
                                                                                                                                                       pngImage.HasTransparentColor = true;

                                                                                                                                                       // All transparent pixels will have a background color.
                                                                                                                                                       pngImage.BackgroundColor = Aspose.Imaging.Color.Green;
                                                                                                                                                       pngImage.HasBackgroundColor = true;

                                                                                                                                                       // Fill the entire image with white color.
                                                                                                                                                       gr.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.White), pngImage.Bounds);

                                                                                                                                                       // Fill the top-left quarter of the image with the transparent color.
                                                                                                                                                       // This makes the top-left quarter colored in the background color.
                                                                                                                                                       Rectangle rect = new Rectangle(0, 0, pngImage.Width / 2, pngImage.Height / 2);
                                                                                                                                                       gr.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red), rect);

                                                                                                                                                       pngImage.Save();
                                                                                                                                                   }

VerticalResolution

提供图像垂直分辨率的访问,开发人员可以使用该财产收回或修改解散设置,该设置表示图像垂直轴的每英寸像素数量(PPI)。

public override double VerticalResolution { get; set; }

财产价值

double

Examples

下面的示例显示如何设置 PNG 图像的水平/垂直分辨率。

string dir = "c:\\temp\\";

                                                                                                using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
                                                                                                {
                                                                                                    Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)image;

                                                                                                    // Get horizontal and vertical resolution of the PngImage.
                                                                                                    double horizontalResolution = pngImage.HorizontalResolution;
                                                                                                    double verticalResolution = pngImage.VerticalResolution;
                                                                                                    System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
                                                                                                    System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);

                                                                                                    if (horizontalResolution != 96.0 || verticalResolution != 96.0)
                                                                                                    {
                                                                                                        // Use the SetResolution method for updating both resolution values in a single call.
                                                                                                        System.Console.WriteLine("Set resolution values to 96 dpi");
                                                                                                        pngImage.SetResolution(96.0, 96.0);

                                                                                                        System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", pngImage.HorizontalResolution);
                                                                                                        System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", pngImage.VerticalResolution);
                                                                                                    }
                                                                                                }

Width

允许恢复图像的宽度,提供必需信息关于它的尺寸. 这个属性经常被开发人员使用确定图像的宽度,使其能够执行基于不同的操作在它的尺寸

public override int Width { get; }

财产价值

int

XmpData

访问或修改附属的扩展式数据平台(XMP)的数据此属性使提取、修改或添加代数据,使图像相关信息能够全面管理。

public override XmpPacketWrapper XmpData { get; set; }

财产价值

XmpPacketWrapper

Methods

GetDefaultOptions(对象[])

获取默认选项。

public override ImageOptionsBase GetDefaultOptions(object[] args)

Parameters

args object ( )

这些论点。

Returns

ImageOptionsBase

默认选项

GetModifyDate(博尔)

回收时间表,显示资源的最新修改图像. 此方法提供访问至关重要的代数据,允许应用程序确认图像最后更改时,方便版本跟踪和内容管理。

public override DateTime GetModifyDate(bool useDefault)

Parameters

useDefault bool

如果设置为“真实”,则使用 FileInfo 的信息作为默认值。

Returns

DateTime

资源图像的日期和时间最后修改。

GetOriginalOptions()

获得基于原始文件设置的选项。这可能有助于保持原始图像的细节深度和其他参数不变。例如,如果我们加载一张黑白的PNG图像,每像素1比特,然后使用Aspose.Imaging.DataStreamSupporter.Save(System.String)方法,输出PNG图像,每像素将产生8位。要避免它,并以每像素1比特保存PNG图像,使用此方法获得相应的储蓄选项并通过它们。在 Aspose.Imaging.Image.Save(System.String,Aspose.Imaging.ImageOptionsBase)方法作为第二个参数。

public override ImageOptionsBase GetOriginalOptions()

Returns

ImageOptionsBase

基于原始文件设置的选项。

OnPaletteChanged(色彩,色彩,色彩)

被称为当板块变更时。

protected override void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

旧的板块。

newPalette IColorPalette

新的板块。

SaveData(Stream)

保存数据。

protected override void SaveData(Stream stream)

Parameters

stream Stream

流的。

UpdateDimensions(int , int , int)

更新尺寸。

protected override void UpdateDimensions(int newWidth, int newHeight)

Parameters

newWidth int

新的宽度。

newHeight int

新高度。

UpdateMetadata()

更新图像的最后修改日期和时间。

protected override void UpdateMetadata()
 中文