Class PngImage
Pôvodný názov: Aspose.Imaging.FileFormats.Png Zhromaždenie: Aspose.Imaging.dll (25.4.0)
Manipulovať Portable Network Graphics (PNG) raster obrázky s našou všestrannou API,poskytuje podporu pre úrovne kompresie a rôzne farebné hĺbky vrátaneGrayscale, indexované farby, TrueColor a alfa kanály. bezchybne spracúvať metadata XMP,umožňujú komplexné riadenie metaúdajov obrazu, zatiaľ čo ľahko nahrajú PNG obrazy,vykonávanie rôznych manipulácií, aplikácia filtrov a konverzia obrázkov do iných súborovFormáty pre optimálnu všestrannosť a prispôsobenie.
[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
Z dedičných členov
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
Tento príklad ukazuje, ako nahrať obrázok PNG z súboru.
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(a int, int)
Initializujte nový objekt triedy Aspose.Imaging.FileFormats.Png. PngImage tým, že poskytnetešírka a výška parametrov. Tento konštruktor zjednodušuje vytvorenie PNGsnímky umožňujúc vývojárom priamo určiť rozmery, uľahčujúceEfektívne riadenie PNG image údajov v rámci ich aplikácií.
public PngImage(int width, int height)
Parameters
width
int
Na šírku .
height
int
na výšku .
Examples
Tento príklad ukazuje, ako vytvoriť obrázok PNG špecifikovanej veľkosti, vyplniť ho pevnou farbou a uložiť ho do súboru.
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(Stretnutie)
Vytvára novú inštanciu triedy Aspose.Imaging.FileFormats.Png. PngImage pomocou trasyparameter na určenie umiestnenia obrázkového súboru na stiahnutie. tento konštruktorumožňuje vývojárom pohodlne vytvárať PNG obrázky tým, že ich stiahne z súboru,Zjednodušenie procesu práce s PNG obrázkami v ich aplikáciách.
public PngImage(string path)
Parameters
path
string
Cesta na nahrávanie obrazu.
Examples
Tento príklad ukazuje, ako nahrať obrázok PNG z súboru.
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)
Vytvára novú inštanciu triedy Aspose.Imaging.FileFormats.Png. PngImage tým, že poskytuje rasterobrázok ako parameter. Tento konštruktor umožňuje vývojárom priamo iniciovaťObjekt snímky PNG pomocou existujúceho rasterového obrazu, ktorý zjednodušuje procesPráca s PNG obrázkami v ich aplikáciách.
public PngImage(RasterImage rasterImage)
Parameters
rasterImage
RasterImage
Obrázok z rastu.
Examples
Tento príklad ukazuje, ako nahrať obrázok PNG z obrázka 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(struny, PngColorType)
Initalizuje novú inštanciu triedy Aspose.Imaging.FileFormats.Png. PngImage tým, že špecifikujecesta k obrázkovému súboru a typu farby.Tento konštruktor umožňuje pohodlnévytvorenie PNG obrázkov z súborov s rôznymi farebnými typmi, ktoré poskytujúflexibilita pri spracovaní rôznych formátov obrazu.
public PngImage(string path, PngColorType colorType)
Parameters
path
string
Cesta na nahrávanie obrazu.
colorType
PngColorType
Typ farby je.
Examples
Tento príklad ukazuje, ako nahrať obrázok PNG z súboru s špecifikovaným typom farby.
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
PngImage(Tabuľka, PngColorType)
Vytvára novú inštanciu triedy Aspose.Imaging.FileFormats.Png. PngImage špecifikáciouraster obrázok a farebný typ. Tento konštruktor umožňuje vývojárom priamoKonvertovať obrázky rastu do formátu PNG a zároveň určiť požadovaný typ farby,Ponúkame flexibilitu v farebnej reprezentácii.
public PngImage(RasterImage rasterImage, PngColorType colorType)
Parameters
rasterImage
RasterImage
Obrázok z rastu.
colorType
PngColorType
Typ farby je.
Examples
Tento príklad ukazuje, ako nahrať obrázok PNG z obrázka BMP so špecifikovaným typom farby.
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)
Vytvára novú inštanciu triedy Aspose.Imaging.FileFormats.Png. PngImage tým, že ju iniciujeTento konštruktor umožňuje vývojárom nahrať PNG obrázky priamoz prúdu, ktorý poskytuje flexibilitu pri prijímaní obrazu z rôznych zdrojov.
public PngImage(Stream stream)
Parameters
stream
Stream
Stream na nahrávanie obrazu.
Examples
Tento príklad ukazuje, ako nahrať obrázok PNG z súboru alebo toku.
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)
Inštantujte novú inštanciu triedy Aspose.Imaging.FileFormats.Png. PngImage, ktorá špecifikujepožadovaná šírka, výška a farebný typ parametrov. Tento konštruktor umožňujerýchle vytvorenie PNG obrázkov s prispôsobenými rozmermi a farebnými konfiguráciami,Uľahčovanie streamlovanej generácie obrazu pre rôzne aplikácie a pracovné toky.
public PngImage(int width, int height, PngColorType colorType)
Parameters
width
int
Na šírku .
height
int
na výšku .
colorType
PngColorType
Typ farby je.
Examples
Tento príklad ukazuje, ako vytvoriť obrázok PNG špecifickej veľkosti s špecifikovaným typom farby, vyplniť ho pevnou farbou a uložiť ho do súboru.
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)
Inštalujte novú inštanciu triedy Aspose.Imaging.FileFormats.Png. PngImage, ktorá obsahujePNG možnosti vedľa šírky a výšky parametrov. Tento konštruktor umožňujevývojári vytvoriť PNG obrázky s prispôsobiteľnými nastavením a rozmermi,poskytuje flexibilitu v generácii obrazu pre rôzne prípady použitia.
public PngImage(PngOptions pngOptions, int width, int height)
Parameters
pngOptions
PngOptions
Možnosti pre png.
width
int
Na šírku .
height
int
na výšku .
Examples
Tento príklad ukazuje, ako vytvoriť obrázok PNG s uvedenými možnosťami, vyplniť ho lineárnou gradientovou farbou a uložiť ho do súboru.
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
Vráti farbu pozadia obrazu, ak je jeden špecifikovaný.je užitočná pre aplikácie, ktoré potrebujú identifikovať a potenciálne manipulovaťfarba pozadia obrazu.
public override Color BackgroundColor { get; set; }
Hodnota nehnuteľnosti
Examples
Nasledujúci príklad ukazuje, ako nastaviť plne transparentné farby pre časť obrazu TrueColor PNG, ktorá nepodporuje alfa kanál.
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
Obnoviť bity na pixel hodnoty pre obrázok. Táto vlastnosť poskytuje kľúčovéinformácie o farebnej hĺbke obrazu, ktoré umožňujú vývojárompochopenie úrovne detailov a farebnej presnosti prítomnej v údajoch o obraze.
public override int BitsPerPixel { get; }
Hodnota nehnuteľnosti
FileFormat
Vráti formát súboru spojený s obrázkom príklad.majetok poskytuje základné informácie týkajúce sa typu súboru, umožňujúceefektívna manipulácia a spracovanie na základe špecifických požiadaviek formátu.
public override FileFormat FileFormat { get; }
Hodnota nehnuteľnosti
HasAlpha
Vráti booleánovú hodnotu, ktorá naznačuje, či má obrázok alfa kanál,ktoré určuje jeho transparentnosť. Táto vlastnosť je užitočná pre aplikácieje potrebné riešiť transparentnosť, čo umožňuje vývojárom určiť, čiDodatočné spracovanie je potrebné na zaobchádzanie s transparentnými oblasťami obrazu.
public override bool HasAlpha { get; }
Hodnota nehnuteľnosti
Examples
Nasledujúci príklad ukazuje, ako skontrolovať, či obrázok PNG podporuje alfa kanál.
// 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
Vráti booleánovú hodnotu, ktorá naznačuje, či má obrázok farbu pozadia.Táto vlastnosť je užitočná pre aplikácie, ktoré potrebujú určiť, či je obrazobsahuje farbu pozadia, ktorá môže byť dôležitá pre rôzne spracovanieúloh, ako je kompozícia, renderovanie alebo exportovanie.
public override bool HasBackgroundColor { get; set; }
Hodnota nehnuteľnosti
Examples
Nasledujúci príklad ukazuje, ako nastaviť plne transparentné farby pre časť obrazu TrueColor PNG, ktorá nepodporuje alfa kanál.
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
Poskytuje booleánovú hodnotu, ktorá naznačuje, či obrázok obsahuje transparentnýfarba. táto vlastnosť je kľúčová pre aplikácie, ktoré potrebujú zvládnuťtransparentnosť, ktorá umožňuje vývojárom určiť, či je dodatočné spracovanieje potrebné zaobchádzať s transparentnými oblasťami v obraze.
public override bool HasTransparentColor { get; set; }
Hodnota nehnuteľnosti
Examples
Nasledujúci príklad ukazuje, ako nastaviť plne transparentné farby pre časť obrazu TrueColor PNG, ktorá nepodporuje alfa kanál.
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
Získajte výšku obrazu. Táto vlastnosť vráti vertikálnu dimenziuobrázok, ktorý umožňuje vývojárom určiť jeho veľkosť v pixeloch pozdĺžvertikálny okraj.
public override int Height { get; }
Hodnota nehnuteľnosti
HorizontalResolution
Obnoviť alebo zmeniť horizontálne rozlíšenie obrazu.predstavuje počet pixelov na palec pozdĺž horizontálnej osiPrispôsobenie tejto rozlíšenia môže ovplyvniť fyzickú veľkosť obrazu, keďTlačené alebo zobrazené.
public override double HorizontalResolution { get; set; }
Hodnota nehnuteľnosti
Examples
Nasledujúci príklad ukazuje, ako nastaviť horizontálne/vertikálne rozlíšenie obrazu 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
Vráti booleánovú hodnotu, ktorá ukazuje, či je Aspose.Imaging.FileFormats.Png. PngImageinterlaced, ktorý určuje, či sa údaje o obraze ukladajú v progresívnejspôsob rýchlejšieho nabíjania alebo prenosu.
public bool Interlaced { get; }
Hodnota nehnuteľnosti
IsInterlaced
Vráti booleánovú hodnotu, ktorá naznačuje, či je obrázkový príklad prepojený.vlastnosť je kľúčová pre optimalizáciu stratégií zaťaženia a zaistenie efektívnostivýkon počas spracovania obrázkov alebo zobrazenia úloh.
public bool IsInterlaced { get; }
Hodnota nehnuteľnosti
RawDataFormat
Prístup k formátu surových údajov obrazu.Táto vlastnosť poskytuje vnímanieako sú údaje o obraze vnútorne štruktúrované, čo môže byť užitočné pre pokročiléObrázok spracovania úloh alebo formát konverzie.
public override PixelDataFormat RawDataFormat { get; }
Hodnota nehnuteľnosti
Examples
Nasledujúci príklad nahrá PNG obrázky a tlačí informácie o formáte surových údajov a alfa kanál.
// 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
Vráti transparentnú farbu obrazu, ak existuje.cenný pre aplikácie, ktoré vyžadujú presné zaobchádzanie s transparentnými oblasťamiv obrazoch, ktoré umožňujú vývojárom prístup a manipuláciu s konkrétnymTransparentná farba použitá.
public override Color TransparentColor { get; set; }
Hodnota nehnuteľnosti
Examples
Nasledujúci príklad ukazuje, ako nastaviť plne transparentné farby pre časť obrazu TrueColor PNG, ktorá nepodporuje alfa kanál.
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
Poskytuje prístup k vertikálnej rezolucii obrazu. vývojári môžu použiťtento majetok získať alebo zmeniť nastavenie uznesenia, ktoré naznačuje, žePočet pixelov na palec (PPI) pozdĺž vertikálnej osi obrazu.
public override double VerticalResolution { get; set; }
Hodnota nehnuteľnosti
Examples
Nasledujúci príklad ukazuje, ako nastaviť horizontálne/vertikálne rozlíšenie obrazu 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
Umožňuje získavanie šírky obrazu, poskytuje základné informácieo jeho rozmeroch. táto nehnuteľnosť je často používaná vývojármi naurčiť šírku obrazu, čo im umožňuje vykonávať rôzne operácie založené naNa jej veľkosti
public override int Width { get; }
Hodnota nehnuteľnosti
XmpData
Prístup alebo úprava rozšírených metadata platformy (XMP) súvisiacich metadatTento majetok uľahčuje extrakciu, modifikáciu, alebododanie metadata, ktoré umožňujú komplexné riadenie informácií týkajúcich sa obrazu.
public override XmpPacketWrapper XmpData { get; set; }
Hodnota nehnuteľnosti
Methods
GetDefaultOptions(objekty[])
Získajte predvolené možnosti.
public override ImageOptionsBase GetDefaultOptions(object[] args)
Parameters
args
object
[]
Sú to argumenty.
Returns
Predvolené možnosti
GetModifyDate(bool)
Vráti časový štandard, ktorý naznačuje najnovšiu modifikáciu zdrojaTáto metóda poskytuje prístup k životne dôležitým metadata, čo umožňuje aplikácie nazistiť, kedy bol obrázok naposledy upravený, uľahčujúce sledovanie verzie aRiadenie obsahu .
public override DateTime GetModifyDate(bool useDefault)
Parameters
useDefault
bool
Ak je nastavený na “skutočný”, použite informácie z programu FileInfo ako predvolenú hodnotu.
Returns
Dátum a čas, kedy bol obrázok zdroja naposledy upravený.
GetOriginalOptions()
Získajte možnosti založené na pôvodných nastaveniach súboru.To môže byť užitočné udržať bitovú hĺbku a ďalšie parametre pôvodného obrazu nezmenené.Napríklad, ak nahrávame čiernobiely PNG obrázok s 1 bitom na pixel a potom ho uložíme pomocouAspose.Imaging.DataStreamSupporter.Save(System.String) metóda, bude produkovaný výstupný PNG obrázok s 8-bitom na pixel.Aby ste sa tomu vyhli a ušetrili PNG obrázok s 1 bitom na pixel, použite túto metódu, aby ste získali príslušné možnosti ušetrenia a prešli ichna metódu Aspose.Imaging.Image.Save(System.String,_Wl17.ImageOptionsBase) ako druhý parameter.
public override ImageOptionsBase GetOriginalOptions()
Returns
Možnosti založené na pôvodných nastaveniach súboru.
OnPaletteChanged(Spoločnosť IColorPalette)
Volá sa, keď sa paleta mení.
protected override void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)
Parameters
oldPalette
IColorPalette
Stará paleta
newPalette
IColorPalette
a novú paletu.
SaveData(Stream)
Ušetriť údaje .
protected override void SaveData(Stream stream)
Parameters
stream
Stream
a prúdu .
UpdateDimensions(a int, int)
Aktualizácia rozmerov.
protected override void UpdateDimensions(int newWidth, int newHeight)
Parameters
newWidth
int
a novú šírku.
newHeight
int
a novú výšku.
UpdateMetadata()
Aktualizuje dátum a čas poslednej úpravy obrazu.
protected override void UpdateMetadata()