Class PngImage

Class PngImage

Tên không gian: Aspose.Imaging.FileFormats.Png Tổng hợp: Aspose.Imaging.dll (25.4.0)

Manipulate Portable Network Graphics (PNG) raster hình ảnh với API đa dạng của chúng tôi,cung cấp hỗ trợ cho mức độ nén và độ sâu màu khác nhau bao gồm:Grayscale, Indexed Color, TrueColor, và các kênh alpha. xử lý không ngừng metadata XMP,cho phép quản lý metadata toàn diện của hình ảnh, trong khi dễ dàng tải các bức ảnh PNG,thực hiện các thao tác khác nhau, áp dụng các bộ lọc, và chuyển đổi hình ảnh sang các tệp khácđịnh dạng cho sự đa dạng và tùy chỉnh tối ưu.

[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

Thành viên thừa kế

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

Ví dụ này cho thấy làm thế nào để tải một hình ảnh PNG từ một tệp.

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)

Bắt đầu một đối tượng mới của lớp Aspose.Imaging.FileFormats.Png. PngImage bằng cách cung cấpthông số chiều rộng và chiều cao. nhà xây dựng này đơn giản hóa việc tạo ra PNGhình ảnh bằng cách cho phép các nhà phát triển xác định các kích thước trực tiếp, tạo điều kiệnQuản lý hiệu quả dữ liệu hình ảnh PNG trong các ứng dụng của họ.

public PngImage(int width, int height)

Parameters

width int

Chiều rộng .

height int

Độ cao .

Examples

Ví dụ này cho thấy làm thế nào để tạo một hình ảnh PNG của kích thước cụ thể, lấp đầy nó với một màu sắc vững chắc và lưu nó vào một tệp.

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(String)

Xây dựng một trường hợp mới của lớp Aspose.Imaging.FileFormats.Png.pngImage bằng cách sử dụng con đườngparameter để chỉ định vị trí của tập tin hình ảnh để tải.cho phép các nhà phát triển dễ dàng tạo hình ảnh PNG bằng cách tải chúng từ một tệp,đơn giản hóa quá trình làm việc với hình ảnh PNG trong các ứng dụng của họ.

public PngImage(string path)

Parameters

path string

Con đường để tải một hình ảnh

Examples

Ví dụ này cho thấy làm thế nào để tải một hình ảnh PNG từ một tệp.

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)

Tạo một trường hợp mới của lớp Aspose.Imaging.FileFormats.Png.pngImage bằng cách cung cấp một rasterhình ảnh như một thông số. nhà xây dựng này cho phép các nhà phát triển trực tiếp bắt đầu mộtHình ảnh PNG sử dụng một hình ảnh raster hiện có, làm cho quá trìnhlàm việc với hình ảnh PNG trong ứng dụng của họ.

public PngImage(RasterImage rasterImage)

Parameters

rasterImage RasterImage

Hình ảnh Raster

Examples

Ví dụ này cho thấy làm thế nào để tải ảnh PNG từ một hình ảnh BMP.

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(Nhãn hiệu: PngColorType)

Bắt đầu một trường hợp mới của lớp Aspose.Imaging.FileFormats.Png. PngImage bằng cách xác địnhđường đến tệp hình ảnh và loại màu.Constructor này cho phép thuận tiệntạo hình ảnh PNG từ các tệp với các loại màu khác nhau, cung cấplinh hoạt trong việc xử lý các định dạng hình ảnh khác nhau.

public PngImage(string path, PngColorType colorType)

Parameters

path string

Con đường để tải một hình ảnh

colorType PngColorType

Loại màu sắc

Examples

Ví dụ này cho thấy làm thế nào để tải một hình ảnh PNG từ một tệp với loại màu cụ thể.

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(Hình ảnh, PngColorType)

Tạo một ví dụ mới của lớp Aspose.Imaging.FileFormats.Png. PngImage bằng cách xác định mộtraster hình ảnh và một loại màu. nhà xây dựng này cho phép các nhà phát triển để trực tiếpChuyển đổi hình ảnh raster thành định dạng PNG trong khi xác định loại màu mong muốn,Cung cấp sự linh hoạt trong thể hiện màu sắc.

public PngImage(RasterImage rasterImage, PngColorType colorType)

Parameters

rasterImage RasterImage

Hình ảnh Raster

colorType PngColorType

Loại màu sắc

Examples

Ví dụ này cho thấy làm thế nào để tải ảnh PNG từ một hình ảnh BMP với loại màu cụ thể.

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)

Tạo một trường hợp mới của lớp Aspose.Imaging.FileFormats.Png. PngImage bằng cách khởi động nóvới một dòng. nhà xây dựng này cho phép các nhà phát triển tải hình ảnh PNG trực tiếptừ một dòng, cung cấp tính linh hoạt trong thu hồi hình ảnh từ các nguồn khác nhau.

public PngImage(Stream stream)

Parameters

stream Stream

dòng để tải một hình ảnh.

Examples

Ví dụ này cho thấy làm thế nào để tải lên một hình ảnh PNG từ một tệp hoặc dòng file.

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)

Tạo một ví dụ mới của lớp Aspose.Imaging.FileFormats.Png.pngImage, xác địnhchiều rộng, chiều cao, và các thông số loại màu mong muốn. nhà xây dựng này cho phéptạo nhanh các hình ảnh PNG với kích thước và cấu hình màu tùy chỉnh,tạo ra hình ảnh nhanh chóng cho các ứng dụng và dòng công việc khác nhau.

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

Parameters

width int

Chiều rộng .

height int

Độ cao .

colorType PngColorType

Loại màu sắc

Examples

Ví dụ này cho thấy làm thế nào để tạo một hình ảnh PNG của kích thước cụ thể với loại màu được chỉ định, lấp đầy nó với một màu sắc vững chắc và lưu nó vào một tệp.

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(Tùy chọn: int, int)

Bắt đầu một trường hợp mới của lớp Aspose.Imaging.FileFormats.Png. PngImage, bao gồmCác tùy chọn PNG bên cạnh các thông số chiều rộng và chiều cao. nhà xây dựng này có khả năngcác nhà phát triển để tạo hình ảnh PNG với cài đặt và kích thước tùy chỉnh,cung cấp tính linh hoạt trong tạo hình ảnh cho các trường hợp sử dụng khác nhau.

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

Parameters

pngOptions PngOptions

Các tùy chọn PNG

width int

Chiều rộng .

height int

Độ cao .

Examples

Ví dụ này cho thấy làm thế nào để tạo một hình ảnh PNG với các tùy chọn được chỉ định, lấp đầy nó với một màu gradient linear và lưu nó vào một tệp.

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

Quay lại màu nền của hình ảnh, nếu một được chỉ định.hữu ích cho các ứng dụng cần xác định và tiềm năng thao túngMàu nền của một hình ảnh.

public override Color BackgroundColor { get; set; }

Giá trị bất động sản

Color

Examples

Ví dụ sau đây cho thấy cách thiết lập màu sắc hoàn toàn minh bạch cho một phần của hình ảnh TrueColor PNG không hỗ trợ kênh alpha.

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

Khôi phục các bit/pixel giá trị cho hình ảnh. thuộc tính này cung cấp quan trọngthông tin về độ sâu màu của hình ảnh, cho phép các nhà phát triểnhiểu mức độ chi tiết và độ chính xác màu sắc hiện diện trong dữ liệu hình ảnh.

public override int BitsPerPixel { get; }

Giá trị bất động sản

int

FileFormat

Quay lại định dạng của tệp liên quan đến mẫu hình ảnh.tài sản cung cấp thông tin cần thiết về loại tệp, cho phépQuản lý và xử lý hiệu quả dựa trên các yêu cầu định dạng cụ thể.

public override FileFormat FileFormat { get; }

Giá trị bất động sản

FileFormat

HasAlpha

Trả lại một giá trị boolean cho biết liệu hình ảnh có một kênh alpha hay không,xác định tính minh bạch của nó. tài sản này hữu ích cho các ứng dụngcần phải xử lý minh bạch, cho phép các nhà phát triển xác định nếuViệc xử lý bổ sung là cần thiết để đối phó với các khu vực minh bạch trong hình ảnh.

public override bool HasAlpha { get; }

Giá trị bất động sản

bool

Examples

Ví dụ sau đây cho thấy cách kiểm tra xem hình ảnh PNG có hỗ trợ kênh alpha hay không.

// 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

Nó rút lại một giá trị boolean cho thấy liệu hình ảnh có màu nền hay không.Tài sản này hữu ích cho các ứng dụng cần xác định nếu một hình ảnhbao gồm một màu nền, có thể quan trọng cho các xử lý khác nhauCác nhiệm vụ như biên soạn, trình bày hoặc xuất khẩu.

public override bool HasBackgroundColor { get; set; }

Giá trị bất động sản

bool

Examples

Ví dụ sau đây cho thấy cách thiết lập màu sắc hoàn toàn minh bạch cho một phần của hình ảnh TrueColor PNG không hỗ trợ kênh alpha.

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

Nó cung cấp một giá trị boolean cho thấy liệu hình ảnh có chứa mộtMàu sắc. tài sản này là rất quan trọng cho các ứng dụng cần phải xử lýminh bạch, cho phép các nhà phát triển xác định liệu việc xử lý bổ sung cócần phải xử lý các khu vực minh bạch trong hình ảnh.

public override bool HasTransparentColor { get; set; }

Giá trị bất động sản

bool

Examples

Ví dụ sau đây cho thấy cách thiết lập màu sắc hoàn toàn minh bạch cho một phần của hình ảnh TrueColor PNG không hỗ trợ kênh alpha.

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

Có được chiều cao của hình ảnh. tài sản này trả về kích thước dọc củahình ảnh, cho phép các nhà phát triển để xác định kích thước của nó trong pixels dọc theoVòng axis.

public override int Height { get; }

Giá trị bất động sản

int

HorizontalResolution

Xác định hoặc sửa đổi độ phân giải ngang của hình ảnh. tài sản nàyđại diện cho số lượng pixel mỗi inch dọc theo ax horizontal củaĐiều chỉnh độ phân giải này có thể ảnh hưởng đến kích thước vật lý của hình ảnh khiin hoặc hiển thị.

public override double HorizontalResolution { get; set; }

Giá trị bất động sản

double

Examples

Ví dụ sau đây cho thấy làm thế nào để thiết lập độ phân giải ngang / dọc của một hình ảnh 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

Nó thu hồi một giá trị boolean cho thấy liệu Aspose.Imaging.FileFormats.Png.pngImage làinterlaced, mà xác định liệu dữ liệu hình ảnh được lưu trữ trong mộtcách để tải nhanh hơn hoặc truyền tải.

public bool Interlaced { get; }

Giá trị bất động sản

bool

IsInterlaced

Quay lại một giá trị boolean cho thấy nếu ví dụ hình ảnh được liên kết.tài sản là rất quan trọng để tối ưu hóa các chiến lược tải và đảm bảo hiệu quảhiệu suất trong quá trình xử lý hình ảnh hoặc công việc hiển thị.

public bool IsInterlaced { get; }

Giá trị bất động sản

bool

RawDataFormat

Truy cập vào định dạng dữ liệu thô của hình ảnh. tài sản này cung cấp sự hiểu biết vềlàm thế nào dữ liệu hình ảnh được cấu trúc nội bộ, có thể hữu ích cho nâng caoNhiệm vụ xử lý hình ảnh hoặc chuyển đổi định dạng.

public override PixelDataFormat RawDataFormat { get; }

Giá trị bất động sản

PixelDataFormat

Examples

Ví dụ sau đây tải hình ảnh PNG và in thông tin về định dạng dữ liệu thô và kênh alpha.

// 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

Quay lại màu sắc minh bạch của hình ảnh, nếu nó tồn tại.giá trị cho các ứng dụng đòi hỏi phải xử lý chính xác các khu vực minh bạchtrong các hình ảnh, cho phép các nhà phát triển truy cập và thao túng cácMàu sắc thông minh được sử dụng.

public override Color TransparentColor { get; set; }

Giá trị bất động sản

Color

Examples

Ví dụ sau đây cho thấy cách thiết lập màu sắc hoàn toàn minh bạch cho một phần của hình ảnh TrueColor PNG không hỗ trợ kênh alpha.

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

Cung cấp quyền truy cập vào độ phân giải dọc của hình ảnh. nhà phát triển có thể sử dụngtài sản này để thu hồi hoặc sửa đổi thiết lập giải quyết, cho thấySố pixel mỗi inch (PPI) dọc theo ax vuông của hình ảnh.

public override double VerticalResolution { get; set; }

Giá trị bất động sản

double

Examples

Ví dụ sau đây cho thấy làm thế nào để thiết lập độ phân giải ngang / dọc của một hình ảnh 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

Cho phép thu thập chiều rộng của hình ảnh, cung cấp thông tin cần thiếtvề kích thước của nó. tài sản này thường được sử dụng bởi các nhà phát triển đểxác định chiều rộng của hình ảnh, cho phép họ thực hiện các hoạt động khác nhau dựa trêntrên kích thước của nó

public override int Width { get; }

Giá trị bất động sản

int

XmpData

Truy cập hoặc sửa đổi các Metadata Platform Extensible (XMP) liên quantài sản này tạo điều kiện cho việc khai thác, sửa đổi, hoặcthêm metadata, cho phép quản lý toàn diện thông tin liên quan đến hình ảnh.

public override XmpPacketWrapper XmpData { get; set; }

Giá trị bất động sản

XmpPacketWrapper

Methods

GetDefaultOptions(đối tượng[])

Nhận các tùy chọn mặc định.

public override ImageOptionsBase GetDefaultOptions(object[] args)

Parameters

args object [ ]

Các Arguments .

Returns

ImageOptionsBase

Lựa chọn mặc định

GetModifyDate(Bool)

Quay lại thời gian cho thấy sự thay đổi gần đây nhất của tài nguyênphương pháp này cung cấp quyền truy cập vào các metadata quan trọng, cho phép các ứng dụngxác định khi hình ảnh được thay đổi lần cuối, tạo điều kiện theo dõi phiên bản vàQuản lý nội dung.

public override DateTime GetModifyDate(bool useDefault)

Parameters

useDefault bool

nếu được thiết lập để ’truyền’ sử dụng thông tin từ FileInfo như là giá trị mặc định.

Returns

DateTime

Ngày và thời gian hình ảnh nguồn được sửa đổi lần cuối.

GetOriginalOptions()

Nhận các tùy chọn dựa trên cài đặt tệp ban đầu.Điều này có thể hữu ích để giữ độ sâu bit và các thông số khác của hình ảnh ban đầu không thay đổi.Ví dụ, nếu chúng tôi tải một hình ảnh PNG màu đen và trắng với 1 bit mỗi pixel và sau đó lưu nó bằng cách sử dụngAspose.Imaging.DataStreamSupporter.Save(System.String) phương pháp, hình ảnh PNG output với 8 bit mỗi pixel sẽ được tạo ra.Để tránh nó và tiết kiệm hình ảnh PNG với 1 bit mỗi pixel, sử dụng phương pháp này để có được các tùy chọn tiết kiệm tương ứng và thông qua chúngđến phương pháp Aspose.Imaging.Image.Save(System.String,_W L17.ImageOptionsBase) như là thông số thứ hai.

public override ImageOptionsBase GetOriginalOptions()

Returns

ImageOptionsBase

Các tùy chọn dựa trên cài đặt tệp ban đầu.

OnPaletteChanged(Đồ họa: IColorPalette)

gọi khi palette được thay đổi.

protected override void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

Cảnh cổ xưa

newPalette IColorPalette

Palette mới

SaveData(Stream)

tiết kiệm dữ liệu.

protected override void SaveData(Stream stream)

Parameters

stream Stream

dòng chảy

UpdateDimensions(int, int)

Độ phân giải update.

protected override void UpdateDimensions(int newWidth, int newHeight)

Parameters

newWidth int

Chiều rộng mới

newHeight int

Độ cao mới

UpdateMetadata()

Cập nhật hình ảnh ngày và thời gian sửa đổi cuối cùng.

protected override void UpdateMetadata()
 Tiếng Việt