Class PngImage
Název místa: Aspose.Imaging.FileFormats.Png Shromáždění: Aspose.Imaging.dll (25.4.0)
Manipulace Portable Network Graphics (PNG) raster obrázky s naším všestranným API,podporuje úrovně komprese a různé barevné hloubky, včetněGrayscale, indexované barvy, TrueColor a alfa kanály. bezproblémové zpracování metadata XMP,umožňující komplexní správu metadata snímků a zároveň snadné načítání snímků PNG,provádění různých manipulací, aplikace filtrů a konverze obrázků do jiných souborůFormáty pro optimální všestrannost a přizpůsoben.
[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
Dědiční č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 příklad ukazuje, jak nahrát PNG obrázek z souboru.
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)
Začněte novým objektem třídy Aspose.Imaging.FileFormats.Png.PngImage tím, žešířka a výška parametrů. Tento konstruktor zjednodušuje tvorbu PNGsnímky umožňující vývojářům přímo specifikovat rozměry, usnadňujícíEfektivní řízení PNG image dat v rámci jejich aplikac.
public PngImage(int width, int height)
Parameters
width
int
A šířka.
height
int
na výšku.
Examples
Tento příklad ukazuje, jak vytvořit PNG obrázek uvedené velikosti, vyplnit ji pevnou barvou a uložit ji do souboru.
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(Stringová)
Vytvoří nový příklad třídy Aspose.Imaging.FileFormats.Png.PngImage pomocí trasyparametr pro určení umístění obrázkového souboru ke stažení.umožňuje vývojářům pohodlně vytvářet PNG obrazy tím, že je načítá z souboru,zjednodušení procesu práce s PNG obrázky v jejich aplikacích.
public PngImage(string path)
Parameters
path
string
Cesta k nabití obrazu.
Examples
Tento příklad ukazuje, jak nahrát PNG obrázek z souboru.
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áří nový příklad třídy Aspose.Imaging.FileFormats.Png.PngImage tím, že poskytuje rastuobrázek jako parametr. Tento konstruktor umožňuje vývojářům přímo zahájitObjekt obrazu PNG pomocí stávajícího rasterového obrazu, který zjednodušuje procesPráce s PNG obrázky ve svých aplikacích.
public PngImage(RasterImage rasterImage)
Parameters
rasterImage
RasterImage
Snímek z rastu.
Examples
Tento příklad ukazuje, jak načítat obrázek PNG z obrázku 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(Třída, PngColorType)
Začíná nový příklad třídy Aspose.Imaging.FileFormats.Png.PngImage tím, že specifikujecesta k obrázkovému souboru a typu barvy.Tento konstruktor umožňuje pohodlnévytváření PNG snímků z souborů s různými typy barev, které poskytujíflexibilita při zpracování různých formátů obrazu.
public PngImage(string path, PngColorType colorType)
Parameters
path
string
Cesta k nabití obrazu.
colorType
PngColorType
Tyto typy barev.
Examples
Tento příklad ukazuje, jak nahrát PNG obrázek z souboru s uvedeným typem barvy.
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(Rozměry, PngColorType)
Vytváří nový příklad třídy Aspose.Imaging.FileFormats.Png.PngImage tím, že specifikujeraster obrázek a typ barvy. Tento konstruktor umožňuje vývojářům přímoPřevod rasterových obrázků do formátu PNG při určování požadovaného typu barvy,Flexibilita v barevném zobrazen.
public PngImage(RasterImage rasterImage, PngColorType colorType)
Parameters
rasterImage
RasterImage
Snímek z rastu.
colorType
PngColorType
Tyto typy barev.
Examples
Tento příklad ukazuje, jak načítat obrázek PNG z obrázku BMP s specifikovaným typem barvy.
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áří nový příklad třídy Aspose.Imaging.FileFormats.Png.PngImage tím, že ji iniciujeTento konstruktor umožňuje vývojářům nahrát PNG obrázky přímoz jednoho toku, který poskytuje flexibilitu v image retrieval z různých zdroj.
public PngImage(Stream stream)
Parameters
stream
Stream
Příliv pro nahrávání obrázku.
Examples
Tento příklad ukazuje, jak nahrát PNG obrázek z souboru nebo souborového 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)
Instantujte nový příklad třídy Aspose.Imaging.FileFormats.Png.PngImage, specifikujícípožadovaná šířka, výška a barevný typ parametrů.Tento konstruktor umožňujerychlé vytváření PNG obrázků s přizpůsobenými rozměry a barevnými konfiguracemi,Umožňuje zjednodušenou generaci obrazu pro různé aplikace a pracovní toky.
public PngImage(int width, int height, PngColorType colorType)
Parameters
width
int
A šířka.
height
int
na výšku.
colorType
PngColorType
Tyto typy barev.
Examples
Tento příklad ukazuje, jak vytvořit PNG obrázek specifikované velikosti s specifikovaným typem barvy, vyplnit ji pevnou barvou a uložit ji do souboru.
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)
Začněte novou příkladovou třídou Aspose.Imaging.FileFormats.Png.PngImage, která obsahujePNG možnosti vedle šířky a výšky parametrů. Tento konstruktor umožňujevývojáři vytvořit PNG obrazy s přizpůsobitelnými nastaveními a rozměry,Nabízí flexibilitu v generaci obrazu pro různé případy použit.
public PngImage(PngOptions pngOptions, int width, int height)
Parameters
pngOptions
PngOptions
Možnosti png.
width
int
A šířka.
height
int
na výšku.
Examples
Tento příklad ukazuje, jak vytvořit PNG obrázek s uvedenými možnostmi, vyplnit ji lineární gradientní barvy a uložit ji do souboru.
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
Odstraňuje barvu pozadí obrazu, pokud je uvedeno jedno.je užitečný pro aplikace, které potřebují identifikovat a potenciálně manipulovatbarva pozadí obrazu.
public override Color BackgroundColor { get; set; }
Hodnota nemovitosti
Examples
Následující příklad ukazuje, jak nastavit plně transparentní barvy pro část obrazu TrueColor PNG, která 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
Obnovte bity na pixel hodnoty obrazu.Tato vlastnost poskytuje klíčovéinformace o barevné hloubce obrazu, které umožňují vývojářůmpochopit úroveň detailů a přesnosti barev přítomných v údajích o obraze.
public override int BitsPerPixel { get; }
Hodnota nemovitosti
FileFormat
Obrací formát souboru spojený s obrázkem.majetek poskytuje důležité informace týkající se typu souboru, umožňujícíefektivní zpracování a zpracování na základě specifických požadavků na formát.
public override FileFormat FileFormat { get; }
Hodnota nemovitosti
HasAlpha
Vrátí booleánovou hodnotu, která naznačuje, zda obrázek má alfa kanál,která určuje její transparentnost.Tento majetek je užitečný pro aplikaceje nutné řešit transparentnost, umožňující vývojářům určit, zdaDalší zpracování je zapotřebí pro zacházení s transparentními oblastmi obrazu.
public override bool HasAlpha { get; }
Hodnota nemovitosti
Examples
Následující příklad ukazuje, jak zkontrolovat, zda PNG obraz 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
Odstraní booleánovou hodnotu, která naznačuje, zda obrázek má barvu pozad.Tato vlastnost je užitečná pro aplikace, které potřebují určit, zda je obrazobsahuje barvu pozadí, která může být důležitá pro různé zpracováníkoly, jako je kompozice, renderování nebo exportován.
public override bool HasBackgroundColor { get; set; }
Hodnota nemovitosti
Examples
Následující příklad ukazuje, jak nastavit plně transparentní barvy pro část obrazu TrueColor PNG, která 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ánovou hodnotu, která naznačuje, zda obrázek obsahuje transparentníbarva. tato vlastnost je důležitá pro aplikace, které potřebují zvládnouttransparentnost, která umožňuje vývojářům zjistit, zda je dodatečná zpracováníje nutné zacházet s transparentními oblastmi v obrazu.
public override bool HasTransparentColor { get; set; }
Hodnota nemovitosti
Examples
Následující příklad ukazuje, jak nastavit plně transparentní barvy pro část obrazu TrueColor PNG, která 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ískejte výšku obrazu.Tato vlastnost vrací vertikální rozměr obrazuobrázek, který umožňuje vývojářům určit jeho velikost v pixelů v průběhuVertikální os.
public override int Height { get; }
Hodnota nemovitosti
HorizontalResolution
Obnovit nebo změnit horizontální rozlišení obrazu.představuje počet pixelů za palec po horizontálním okruhuPřizpůsobení této rozlišení může ovlivnit fyzickou velikost obrazu, kdyžTisková nebo zobrazen.
public override double HorizontalResolution { get; set; }
Hodnota nemovitosti
Examples
Následující příklad ukazuje, jak nastavit horizontální/vertikální rozlišení 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
Obdrží boolean hodnotu, která naznačuje, zda je Aspose.Imaging.FileFormats.Png.PngImageinterlaced, který určuje, zda jsou údaje snímku uloženy v progresivnímzpůsoby pro rychlejší nabíjení nebo přenos.
public bool Interlaced { get; }
Hodnota nemovitosti
IsInterlaced
Vrátí booleánovou hodnotu, která naznačuje, zda je obrázkový příklad propojen.Vlastnictví je nezbytné pro optimalizaci strategií nabíjení a zajištění účinnostiVýkon při zpracování obrazu nebo zobrazení úkol.
public bool IsInterlaced { get; }
Hodnota nemovitosti
RawDataFormat
Přístup k surovému datovému formátu obrazu.Tato vlastnost poskytuje vhled dojak je obrazová data strukturována interně, což může být užitečné pro pokročilézpracování obrazových úkolů nebo konverze formátu.
public override PixelDataFormat RawDataFormat { get; }
Hodnota nemovitosti
Examples
Následující příklad nahrává obrázky PNG a vytiskne informace o formátu surových dat a alfa kanálu.
// 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
Odstraňuje transparentní barvu obrazu, pokud existuje.cenné pro aplikace vyžadující přesné zacházení s transparentními oblastmiv rámci obrázků, které umožňují vývojářům přístup a manipulaci s konkrétnímiPoužívá se transparentní barva.
public override Color TransparentColor { get; set; }
Hodnota nemovitosti
Examples
Následující příklad ukazuje, jak nastavit plně transparentní barvy pro část obrazu TrueColor PNG, která 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 přístup k vertikálnímu rozlišení obrazu. vývojáři mohou použíttoto vlastnictví k získání nebo změně nastavení řešení, které naznačuje, žePočet pixelů na palec (PPI) podél vertikální osi obrazu.
public override double VerticalResolution { get; set; }
Hodnota nemovitosti
Examples
Následující příklad ukazuje, jak nastavit horizontální/vertikální rozlišení 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 zotavení šířky obrazu, poskytuje důležité informaceTato vlastnost je často používána vývojáři prourčení šířky obrazu, které jim umožní provádět různé operace založené naNa jeho velikost
public override int Width { get; }
Hodnota nemovitosti
XmpData
Přistupuje nebo mění související metadata Extensible Metadata Platform (XMP)Tento majetek usnadňuje extrahování, modifikace nebopřidání metadata, které umožňují komplexní správu informací souvisejících s obrazem.
public override XmpPacketWrapper XmpData { get; set; }
Hodnota nemovitosti
Methods
GetDefaultOptions(Objekt[])
Získejte standardní možnosti.
public override ImageOptionsBase GetDefaultOptions(object[] args)
Parameters
args
object
[]a[]
a argumenty.
Returns
Defaultní možnosti
GetModifyDate(Bolíček)
Odstraní časového pásma naznačující nejnovější změnu zdrojeTato metoda poskytuje přístup k životně důležitým metadata, což umožňuje aplikacezjistit, kdy byl obrázek naposledy změněn, usnadnit sledování verze azení obsahu.
public override DateTime GetModifyDate(bool useDefault)
Parameters
useDefault
bool
Pokud je nastaven na “pravdivý”, použijte informace z FileInfo jako výchozí hodnotu.
Returns
Datum a čas, kdy byl obrázek zdrojů naposledy změněn.
GetOriginalOptions()
Získáte možnosti na základě původních nastavení souboru.To může být užitečné pro udržení bitové hloubky a dalších parametrů původního obrazu nezměněných.Například, pokud nahráváme černobílý PNG obrázek s 1 bitem na pixel a pak ho uložíme pomocíMetoda Aspose.Imaging.DataStreamSupporter.Save(System.String) bude produkována výstupní PNG s 8-bitovým obrazem na pixel.Chcete-li se tomu vyhnout a ušetřit PNG obrázek s 1 bitem na pixel, použijte tuto metodu, abyste získali odpovídající možnosti ušetření a projít jedo metody Aspose.Imaging.Image.Save(System.String,Aspose.Imaging.ImageOptionsBase) jako druhý parametr.
public override ImageOptionsBase GetOriginalOptions()
Returns
Možnosti založené na původních nastavení soubor.
OnPaletteChanged(Červená paleta, IColorPalette)
Volá se, když se paleta měn.
protected override void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)
Parameters
oldPalette
IColorPalette
A stará paleta.
newPalette
IColorPalette
A nová paleta.
SaveData(Stream)
Shromažďování dat.
protected override void SaveData(Stream stream)
Parameters
stream
Stream
To je proud.
UpdateDimensions(a int, int)
aktualizace rozměr.
protected override void UpdateDimensions(int newWidth, int newHeight)
Parameters
newWidth
int
A nová šířka.
newHeight
int
A nová výška.
UpdateMetadata()
Aktualizuje datum a čas poslední modifikace obrazu.
protected override void UpdateMetadata()