Class Image

Class Image

Pôvodný názov: Aspose.Imaging Zhromaždenie: Aspose.Imaging.dll (25.5.0)

Obrázok je základnou triedou pre všetky typy obrázkov.

[JsonObject(MemberSerialization.OptIn)]
public abstract class Image : DataStreamSupporter, IDisposable, IObjectWithBounds

Inheritance

object DisposableObject DataStreamSupporter Image

Derived

RasterImage , VectorImage

Implements

IDisposable , IObjectWithBounds

Z dedičných členov

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

Určte, či je paleta použitá obrazom.

using (var image = Image.Load(folder + "Sample.bmp"))
                                                         {
                                                             if (image.UsePalette)
                                                             {
                                                                 Console.WriteLine("The palette is used by the image");
                                                             }
                                                         }

Resize obrázok pomocou špecifického typu resize.

using (var image = Image.Load("Photo.jpg"))
                                                   {
                                                       image.Resize(640, 480, ResizeType.CatmullRom);
                                                       image.Save("ResizedPhoto.jpg");

                                                       image.Resize(1024, 768, ResizeType.CubicConvolution);
                                                       image.Save("ResizedPhoto2.jpg");

                                                       var resizeSettings = new ImageResizeSettings
                                                       {
                                                           Mode = ResizeType.CubicBSpline,
                                                           FilterType = ImageFilterType.SmallRectangular
                                                       };

                                                       image.Resize(800, 800, resizeSettings);
                                                       image.Save("ResizedPhoto3.jpg");
                                                   }

Tento príklad vytvára nový súbor s obrázkom v niektorom umiestnení disku, ako je uvedené zdrojovou vlastnosťou príkladu BmpOptions. Niektoré vlastnosti pre príklady bmpoptions sú nastavené pred vytvorením skutočného obrazu.

//Create an instance of BmpOptions and set its various properties
                                                                                                                                                                                                                                                                                                             Aspose.Imaging.ImageOptions.BmpOptions bmpOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
                                                                                                                                                                                                                                                                                                             bmpOptions.BitsPerPixel = 24;

                                                                                                                                                                                                                                                                                                             //Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
                                                                                                                                                                                                                                                                                                             //Second Boolean parameter determines if the file to be created IsTemporal or not
                                                                                                                                                                                                                                                                                                             bmpOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"C:\temp\output.bmp", false);

                                                                                                                                                                                                                                                                                                             //Create an instance of Image and initialize it with instance of BmpOptions by calling Create method
                                                                                                                                                                                                                                                                                                             using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(bmpOptions, 500, 500))
                                                                                                                                                                                                                                                                                                             {
                                                                                                                                                                                                                                                                                                                 //do some image processing

                                                                                                                                                                                                                                                                                                                 // save all changes
                                                                                                                                                                                                                                                                                                                 image.Save();
                                                                                                                                                                                                                                                                                                             }

Constructors

Image()

Initalizuje novú inštanciu Aspose.Imaging.Image triedy.

[JsonConstructor]
protected Image()

Image(farebná paleta)

Initalizuje novú inštanciu Aspose.Imaging.Image triedy.

protected Image(IColorPalette colorPalette)

Parameters

colorPalette IColorPalette

Farebná paleta .

Properties

AutoAdjustPalette

Získava alebo nastaví hodnotu, ktorá naznačuje, či automaticky upravuje paletu.

public bool AutoAdjustPalette { get; set; }

Hodnota nehnuteľnosti

bool

BackgroundColor

Získa alebo nastaví hodnotu pre farbu pozadia.

public virtual Color BackgroundColor { get; set; }

Hodnota nehnuteľnosti

Color

BitsPerPixel

Získava obrázok bitov na pixel počítanie.

public abstract int BitsPerPixel { get; }

Hodnota nehnuteľnosti

int

Bounds

Získajte obrázkové hranice.

public Rectangle Bounds { get; }

Hodnota nehnuteľnosti

Rectangle

BufferSizeHint

Získať alebo nastaviť náznak veľkosti buffer, ktorý je definovaný maximálna povolená veľkosť pre všetky vnútorné buffery.

public int BufferSizeHint { get; set; }

Hodnota nehnuteľnosti

int

Container

Získajte Aspose.Imaging.Image kontajner.

public Image Container { get; }

Hodnota nehnuteľnosti

Image

Remarks

Ak táto vlastnosť nie je nulová, označuje, že obrázok je obsiahnutý v inom obraze.

FileFormat

Získava hodnotu formátu súborov

public virtual FileFormat FileFormat { get; }

Hodnota nehnuteľnosti

FileFormat

HasBackgroundColor

Získa alebo nastaví hodnotu, ktorá ukazuje, či má obrázok farbu pozadia.

public virtual bool HasBackgroundColor { get; set; }

Hodnota nehnuteľnosti

bool

Height

Získava výšku obrazu.

public abstract int Height { get; }

Hodnota nehnuteľnosti

int

InterruptMonitor

Získajte alebo nastavíte prerušený monitor.

public InterruptMonitor InterruptMonitor { get; set; }

Hodnota nehnuteľnosti

InterruptMonitor

Palette

Získajte alebo nastavíte farebnú paletu. farebná paleta sa nepoužíva, keď sú pixely priamo reprezentované.

public IColorPalette Palette { get; set; }

Hodnota nehnuteľnosti

IColorPalette

Size

Získava veľkosť obrazu.

public Size Size { get; }

Hodnota nehnuteľnosti

Size

Examples

Tento príklad ukazuje, ako nahrať obrázok DJVU z toku súborov a vytlačiť informácie o stránkach.

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

                                                                                                                // Load a DJVU image from a file stream.
                                                                                                                using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.djvu"))
                                                                                                                {
                                                                                                                    using (Aspose.Imaging.FileFormats.Djvu.DjvuImage djvuImage = new Aspose.Imaging.FileFormats.Djvu.DjvuImage(stream))
                                                                                                                    {
                                                                                                                        System.Console.WriteLine("The total number of pages: {0}", djvuImage.Pages.Length);
                                                                                                                        System.Console.WriteLine("The active page number:    {0}", djvuImage.ActivePage.PageNumber);
                                                                                                                        System.Console.WriteLine("The first page number:     {0}", djvuImage.FirstPage.PageNumber);
                                                                                                                        System.Console.WriteLine("The last page number:      {0}", djvuImage.LastPage.PageNumber);

                                                                                                                        foreach (Aspose.Imaging.FileFormats.Djvu.DjvuPage djvuPage in djvuImage.Pages)
                                                                                                                        {
                                                                                                                            System.Console.WriteLine("--------------------------------------------------");
                                                                                                                            System.Console.WriteLine("Page number:     {0}", djvuPage.PageNumber);
                                                                                                                            System.Console.WriteLine("Page size:       {0}", djvuPage.Size);
                                                                                                                            System.Console.WriteLine("Page raw format: {0}", djvuPage.RawDataFormat);
                                                                                                                        }
                                                                                                                    }
                                                                                                                }

                                                                                                                //The output may look like this:
                                                                                                                //The total number of pages: 2
                                                                                                                //The active page number:    1
                                                                                                                //The first page number:     1
                                                                                                                //The last page number:      2
                                                                                                                //--------------------------------------------------
                                                                                                                //Page number:     1
                                                                                                                //Page size:       { Width = 2481, Height = 3508}
                                                                                                                //Page raw format: RgbIndexed1Bpp, used channels: 1
                                                                                                                //--------------------------------------------------
                                                                                                                //Page number:     2
                                                                                                                //Page size:       { Width = 2481, Height = 3508}
                                                                                                                //Page raw format: RgbIndexed1Bpp, used channels: 1

UsePalette

Získava hodnotu, ktorá ukazuje, či je použitá obrazová paleta.

public virtual bool UsePalette { get; }

Hodnota nehnuteľnosti

bool

Examples

Určte, či je paleta použitá obrazom.

using (var image = Image.Load(folder + "Sample.bmp"))
                                                         {
                                                             if (image.UsePalette)
                                                             {
                                                                 Console.WriteLine("The palette is used by the image");
                                                             }
                                                         }

Width

Získajte šírku obrazu.

public abstract int Width { get; }

Hodnota nehnuteľnosti

int

Methods

CanLoad(Stretnutie)

Určuje, či sa obraz môže nahrať z špecifikovanej súborovej trasy.

public static bool CanLoad(string filePath)

Parameters

filePath string

Pôvodná cesta súboru.

Returns

bool

“skutočný” ak sa obraz môže nahrať z uvedeného súboru; inak, “falšovaný”.

Examples

Tento príklad určuje, či sa obraz môže stiahnuť z súboru.

// Use an absolute path to the file
                                                                           bool canLoad = Aspose.Imaging.Image.CanLoad(@"c:\temp\sample.gif");

CanLoad(striekačky, LoadOptions)

Určuje, či sa obrázok môže nahrať z špecifikovanej cesty súboru a opcionálne pomocou špecifikovaných otvorených možností.

public static bool CanLoad(string filePath, LoadOptions loadOptions)

Parameters

filePath string

Pôvodná cesta súboru.

loadOptions LoadOptions

Možnosti zaťaženia .

Returns

bool

“skutočný” ak sa obraz môže nahrať z uvedeného súboru; inak, “falšovaný”.

CanLoad(Stream)

Určuje, či sa obraz môže nahrať z určeného prúdu.

public static bool CanLoad(Stream stream)

Parameters

stream Stream

Prúd na nabitie od.

Returns

bool

“skutočný” ak sa obraz môže nahrať z uvedeného prúdu; inak, “falšovaný”.

Examples

Tento príklad určuje, či je možné nahrať obrázok z prúdu súborov.

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

                                                                                  bool canLoad;

                                                                                  // Use a file stream
                                                                                  using (System.IO.FileStream stream = System.IO.File.OpenRead(dir + "sample.bmp"))
                                                                                  {
                                                                                      canLoad = Aspose.Imaging.Image.CanLoad(stream);
                                                                                  }

                                                                                  // The following data is not a valid image stream, so CanLoad returns false.
                                                                                  byte[] imageData = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
                                                                                  using (System.IO.MemoryStream stream = new System.IO.MemoryStream(imageData))
                                                                                  {
                                                                                      canLoad = Aspose.Imaging.Image.CanLoad(stream);
                                                                                  }

CanLoad(Príslušenstvo, LoadOptions)

Určuje, či sa obrázok môže nahrať zo špecifikovaného prúdu a opcionálne používa špecifikované loadOptions'.

public static bool CanLoad(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

Prúd na nabitie od.

loadOptions LoadOptions

Možnosti zaťaženia .

Returns

bool

“skutočný” ak sa obraz môže nahrať z uvedeného prúdu; inak, “falšovaný”.

CanSave(ImageOptionsBase)

Určuje, či sa obraz môže uložiť do špecifikovaného formátu súboru, ktorý je reprezentovaný predchádzajúcimi možnosťami ukladania.

public bool CanSave(ImageOptionsBase options)

Parameters

options ImageOptionsBase

Možnosti úspory na použitie.

Returns

bool

“skutočný” ak sa obraz môže uložiť do špecifikovaného formátu súboru, ktorý je reprezentovaný predchádzajúcimi možnosťami ukladania; inak, “falšovaný”.

Examples

Tento príklad ukazuje, ako určiť, či sa obraz môže uložiť do špecifikovaného formátu súboru, ktorý je reprezentovaný predchádzajúcimi možnosťami ukladania.

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

                                                                                                                                              using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                                                                              {
                                                                                                                                                  Aspose.Imaging.ImageOptions.JpegOptions saveOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
                                                                                                                                                  saveOptions.Quality = 50;

                                                                                                                                                  // Determine whether the image can be saved to Jpeg
                                                                                                                                                  bool canSave = image.CanSave(saveOptions);
                                                                                                                                              }

Create(ImageOptionsBase, int, int)

Vytvorte nový obrázok pomocou špecifikovaných možností vytvorenia.

public static Image Create(ImageOptionsBase imageOptions, int width, int height)

Parameters

imageOptions ImageOptionsBase

Možnosti snímok .

width int

Na šírku .

height int

na výšku .

Returns

Image

Novoko vytvorený obraz.

Examples

Tento príklad vytvára nový súbor s obrázkom v niektorom umiestnení disku, ako je uvedené zdrojovou vlastnosťou príkladu BmpOptions. Niektoré vlastnosti pre príklady bmpoptions sú nastavené pred vytvorením skutočného obrazu.

//Create an instance of BmpOptions and set its various properties
                                                                                                                                                                                                                                                                                                             Aspose.Imaging.ImageOptions.BmpOptions bmpOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
                                                                                                                                                                                                                                                                                                             bmpOptions.BitsPerPixel = 24;

                                                                                                                                                                                                                                                                                                             //Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
                                                                                                                                                                                                                                                                                                             //Second Boolean parameter determines if the file to be created IsTemporal or not
                                                                                                                                                                                                                                                                                                             bmpOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"C:\temp\output.bmp", false);

                                                                                                                                                                                                                                                                                                             //Create an instance of Image and initialize it with instance of BmpOptions by calling Create method
                                                                                                                                                                                                                                                                                                             using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(bmpOptions, 500, 500))
                                                                                                                                                                                                                                                                                                             {
                                                                                                                                                                                                                                                                                                                 //do some image processing

                                                                                                                                                                                                                                                                                                                 // save all changes
                                                                                                                                                                                                                                                                                                                 image.Save();
                                                                                                                                                                                                                                                                                                             }

Create(Image[])

Vytvára nový obrázok pomocou špecifikovaných obrázkov ako stránok

public static Image Create(Image[] images)

Parameters

images Image []

Tie obrázky .

Returns

Image

Obrázok ako ImultipageImage

Create(MultipageCreateOptions)

Vytvára špecifikovaný multi-stránok vytvára možnosti.

public static Image Create(MultipageCreateOptions multipageCreateOptions)

Parameters

multipageCreateOptions MultipageCreateOptions

Viacstránka vytvára možnosti.

Returns

Image

viacstránkový obrázok

Create(Stretnutie[], a bool)

Vytvára viacstránkový obrázok, ktorý obsahuje špecifikované súbory.

public static Image Create(string[] files, bool throwExceptionOnLoadError)

Parameters

files string []

a súbory .

throwExceptionOnLoadError bool

Ak je nastavený na “skutočný” [odstrániť výnimku na chybu zaťaženia].

Returns

Image

viacstránkový obrázok

Create(Stretnutie[])

Vytvára viacstránkový obrázok, ktorý obsahuje špecifikované súbory.

public static Image Create(string[] files)

Parameters

files string []

a súbory .

Returns

Image

viacstránkový obrázok

Create(Image[], a bool)

Vytvára nový obrázok špecifikované obrázky ako stránky.

public static Image Create(Image[] images, bool disposeImages)

Parameters

images Image []

Tie obrázky .

disposeImages bool

Ak je nastavený na „skutočný“ [dostup obrázkov].

Returns

Image

Obrázok ako ImultipageImage

Crop(Rectangle)

Vyriešte špecifikovaný rektangul.

public virtual void Crop(Rectangle rectangle)

Parameters

rectangle Rectangle

v pravom rohu.

Examples

Nasledujúci príklad zväčšuje rasterový obrázok. Oblasť pestovania sa určuje prostredníctvom Aspose.Imaging.Rectangle.

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

                                                                                                                      using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
                                                                                                                      {
                                                                                                                          // Crop the image. The cropping area is the rectangular central area of the image.
                                                                                                                          Aspose.Imaging.Rectangle area = new Aspose.Imaging.Rectangle(rasterImage.Width / 4, rasterImage.Height / 4, rasterImage.Width / 2, rasterImage.Height / 2);
                                                                                                                          image.Crop(area);

                                                                                                                          // Save the cropped image to PNG
                                                                                                                          image.Save(dir + "sample.Crop.png");
                                                                                                                      }

Crop(int, int, int, int, int)

Obrázok rastliny so zmenami.

public virtual void Crop(int leftShift, int rightShift, int topShift, int bottomShift)

Parameters

leftShift int

Vľavo sa mení.

rightShift int

Príslušná zmena .

topShift int

Najvyššia výmena.

bottomShift int

V dolnej posune.

Examples

Nasledujúci príklad pestuje obrázok rastu. plocha pestovania je špecifikovaná cez ľavé, horné, pravé a dolné hranice.

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

                                                                                                                           using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
                                                                                                                           {
                                                                                                                               // Crop again. Set a margin of 10% of the image size.
                                                                                                                               int horizontalMargin = rasterImage.Width / 10;
                                                                                                                               int verticalMargin = rasterImage.Height / 10;
                                                                                                                               image.Crop(horizontalMargin, horizontalMargin, verticalMargin, verticalMargin);

                                                                                                                               // Save the cropped image to PNG.
                                                                                                                               image.Save(dir + "sample.Crop.png");
                                                                                                                           }

~Image()

protected ~Image()

GetCanNotSaveMessage(ImageOptionsBase)

Získať nemôže uložiť správu.

protected virtual string GetCanNotSaveMessage(ImageOptionsBase optionsBase)

Parameters

optionsBase ImageOptionsBase

Možnosti snímok .

Returns

string

Nie je možné zachrániť správu.

GetDefaultOptions(objekty[])

Získajte predvolené možnosti.

public virtual ImageOptionsBase GetDefaultOptions(object[] args)

Parameters

args object []

Sú to argumenty.

Returns

ImageOptionsBase

Predvolené možnosti

GetFileFormat(Stretnutie)

Získajte formát súboru.

public static FileFormat GetFileFormat(string filePath)

Parameters

filePath string

Pôvodná cesta súboru.

Returns

FileFormat

Určený formát súboru.

Examples

Tento príklad ukazuje, ako určiť formát obrázka bez načítania celého obrazu z súboru.

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

                                                                                                             // Use an absolute path to the file
                                                                                                             Aspose.Imaging.FileFormat format = Aspose.Imaging.Image.GetFileFormat(dir + "sample.gif");
                                                                                                             System.Console.WriteLine("The file format is {0}", format);

Remarks

Určený formát súboru neznamená, že špecifikovaný obrázok môže byť naložený. Použite jednu z metódy CanLoad preťaženie určiť, či súbor môže byť naložený.

GetFileFormat(Stream)

Získajte formát súboru.

public static FileFormat GetFileFormat(Stream stream)

Parameters

stream Stream

a prúdu .

Returns

FileFormat

Určený formát súboru.

Examples

Tento príklad ukazuje, ako určiť formát obrázka bez načítania celého obrazu z prúdu súborov.

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

                                                                                                                    // Use a file stream
                                                                                                                    using (System.IO.FileStream stream = System.IO.File.OpenRead(dir + "sample.bmp"))
                                                                                                                    {
                                                                                                                        Aspose.Imaging.FileFormat format = Aspose.Imaging.Image.GetFileFormat(stream);
                                                                                                                        System.Console.WriteLine("The file format is {0}", format);
                                                                                                                    }

                                                                                                                    // The following data is not a valid image stream, so GetFileFormat returns FileFormat.Undefined.
                                                                                                                    byte[] imageData = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
                                                                                                                    using (System.IO.MemoryStream stream = new System.IO.MemoryStream(imageData))
                                                                                                                    {
                                                                                                                        Aspose.Imaging.FileFormat format = Aspose.Imaging.Image.GetFileFormat(stream);
                                                                                                                        System.Console.WriteLine("The file format is {0}", format);
                                                                                                                    }

Remarks

Určený formát súboru neznamená, že špecifikovaný obrázok môže byť naložený. Použite jednu z metódy CanLoad preťaženie určiť, či môže byť prúd naložený.

GetFitRectangle(Rectangle)

Dostane rektangul, ktorý sa hodí k aktuálnemu obrazu.

protected Rectangle GetFitRectangle(Rectangle rectangle)

Parameters

rectangle Rectangle

Rektangul dostane vhodný rektangul pre.

Returns

Rectangle

Vhodný rektangul

GetFitRectangle(rektangul, int[])

Získajte rektangul, ktorý sa hodí k aktuálnemu bitmapu s prihliadnutím na prešiel pixel. Prešiel pixel rozsah počítanie by malo byť rovnaké ako vhodnú rektangul veľkosti.

protected Rectangle GetFitRectangle(Rectangle rectangle, int[] pixels)

Parameters

rectangle Rectangle

Rektangul dostane vhodný rektangul pre.

pixels int []

32-bitové ARGB pixelové rozhranie.

Returns

Rectangle

Vhodný rektangul.

GetFittingRectangle(Rektangle, int, int)

Dostane rektangul, ktorý sa hodí k aktuálnemu obrazu.

public static Rectangle GetFittingRectangle(Rectangle rectangle, int width, int height)

Parameters

rectangle Rectangle

Rektangul dostane vhodný rektangul pre.

width int

Objektová šírka.

height int

Výška objektu.

Returns

Rectangle

Príslušný pravokotok alebo výnimka, ak nie je možné nájsť žiadne príslušné pravokotok.

GetFittingRectangle(rektangul, int[], int , int)

Dostane rektangul, ktorý sa hodí k aktuálnemu obrazu.

public static Rectangle GetFittingRectangle(Rectangle rectangle, int[] pixels, int width, int height)

Parameters

rectangle Rectangle

Rektangul dostane vhodný rektangul pre.

pixels int []

32 bitový ARGB pixel.

width int

Objektová šírka.

height int

Výška objektu.

Returns

Rectangle

Príslušný pravokotok alebo výnimka, ak nie je možné nájsť žiadne príslušné pravokotok.

GetImage2Export(ImageOptionsBase, Rectangle, IImageExporter)

Získajte obrázok na export.

[Obsolete("Will be changed by method with other signature")]
protected virtual Image GetImage2Export(ImageOptionsBase optionsBase, Rectangle boundsRectangle, IImageExporter exporter)

Parameters

optionsBase ImageOptionsBase

Základné možnosti obrázkov.

boundsRectangle Rectangle

Sú hranice rektangulárne.

exporter IImageExporter

na vývozcu .

Returns

Image

Obrázok na export

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,Aspose-Imacking. ImageOptionsBase) ako druhý parameter.

public virtual ImageOptionsBase GetOriginalOptions()

Returns

ImageOptionsBase

Možnosti založené na pôvodných nastaveniach súboru.

GetProportionalHeight(int, int, int)

Dostanete primeranú výšku.

public static int GetProportionalHeight(int width, int height, int newWidth)

Parameters

width int

Na šírku .

height int

na výšku .

newWidth int

a novú šírku.

Returns

int

Prirodzená výška .

GetProportionalWidth(int, int, int)

Dostanete primeranú šírku.

public static int GetProportionalWidth(int width, int height, int newHeight)

Parameters

width int

Na šírku .

height int

na výšku .

newHeight int

a novú výšku.

Returns

int

Prirodzená šírka

GetSerializedStream(ImageOptionsBase, Rectangle, out int)

Konvertovať na APS.

public virtual Stream GetSerializedStream(ImageOptionsBase imageOptions, Rectangle clippingRectangle, out int pageNumber)

Parameters

imageOptions ImageOptionsBase

Možnosti snímok .

clippingRectangle Rectangle

Kľúčový rektangul.

pageNumber int

Číslo stránky .

Returns

Stream

Serializovaný prúd

Load(striekačky, LoadOptions)

Stiahne nový obrázok z špecifikovanej súborovej trasy alebo URL.Ak je filePath’ súbory, metóda sa len otvorí na súbore.Ako jefilPate’ URL, metoda stiahne súpravu, ukladá ju ako dočasnú a otvára ju.

public static Image Load(string filePath, LoadOptions loadOptions)

Parameters

filePath string

Stránka súboru alebo URL na nahrávanie obrazu z.

loadOptions LoadOptions

Možnosti zaťaženia .

Returns

Image

nahrávaný obrázok .

Load(Stretnutie)

Stiahne nový obrázok z špecifikovanej súborovej trasy alebo URL.Ak je filePath’ súbory, metóda sa len otvorí na súbore.Ako jefilPate’ URL, metoda stiahne súpravu, ukladá ju ako dočasnú a otvára ju.

public static Image Load(string filePath)

Parameters

filePath string

Stránka súboru alebo URL na nahrávanie obrazu z.

Returns

Image

nahrávaný obrázok .

Examples

Tento príklad ukazuje načítanie existujúceho obrázkového súboru do príkladu Aspose.Imaging.Zobrazenie pomocou špecifikovanej metódy

//Create Image instance and initialize it with an existing image file from disk location
                                                                                                                                             using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"C:\temp\sample.bmp"))
                                                                                                                                             {
                                                                                                                                                 //do some image processing
                                                                                                                                             }

Load(Príslušenstvo, LoadOptions)

Nahráva nový obrázok z špecifikovaného prúdu.

public static Image Load(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

Stream na nahrávanie obrazu z.

loadOptions LoadOptions

Možnosti zaťaženia .

Returns

Image

nahrávaný obrázok .

Load(Stream)

Nahráva nový obrázok z špecifikovaného prúdu.

public static Image Load(Stream stream)

Parameters

stream Stream

Stream na nahrávanie obrazu z.

Returns

Image

nahrávaný obrázok .

Examples

Tento príklad ukazuje použitie objektov System.IO.Stream na načítanie existujúceho súboru s obrázkom

//Create an instance of FileStream
                                                                                                       using (System.IO.FileStream stream = new System.IO.FileStream(@"C:\temp\sample.bmp", System.IO.FileMode.Open))
                                                                                                       {
                                                                                                           //Create an instance of Image class and load an existing file through FileStream object by calling Load method
                                                                                                           using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(stream))
                                                                                                           {
                                                                                                               //do some image processing.
                                                                                                           }
                                                                                                       }

OnPaletteChanged(Spoločnosť IColorPalette)

Volá sa, keď sa paleta mení.

protected virtual void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

Stará paleta

newPalette IColorPalette

a novú paletu.

OnPaletteChanging(Spoločnosť IColorPalette)

Volá sa, keď sa paleta mení.

protected virtual void OnPaletteChanging(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

Stará paleta

newPalette IColorPalette

a novú paletu.

ReleaseManagedResources()

Uvoľní spravované zdroje. uistite sa, že tu nie sú spravované zdroje uvoľnené, pretože možno už boli uvoľnené.

protected override void ReleaseManagedResources()

RemoveMetadata()

Odstrániť metadata.

public virtual void RemoveMetadata()

Resize(a int, int)

Používa sa predvolený Aspose.Imaging.ResizeType.NearestNeighbourResample.

public void Resize(int newWidth, int newHeight)

Parameters

newWidth int

a novú šírku.

newHeight int

a novú výšku.

Examples

Nasledujúci príklad ukazuje, ako zhodnotiť metafil (WMF a EMF).

string dir = "c:\\aspose.imaging\\issues\\net\\3280\\";
                                                                              string[] fileNames = new[] { "image3.emf", "image4.wmf" };
                                                                              foreach (string fileName in fileNames)
                                                                              {
                                                                                  string inputFilePath = dir + fileName;
                                                                                  string outputFilePath = dir + "Downscale_" + fileName;

                                                                                  using (Aspose.Imaging.FileFormats.Emf.MetaImage image = (Aspose.Imaging.FileFormats.Emf.MetaImage)Aspose.Imaging.Image.Load(inputFilePath))
                                                                                  {
                                                                                      image.Resize(image.Width / 4, image.Height / 4);
                                                                                      image.Save(outputFilePath);
                                                                                  }
                                                                              }

Nasledujúci príklad ukazuje, ako obnoviť obrázok SVG a uložiť ho na PNG.

string dir = "c:\\aspose.imaging\\net\\issues\\3549";
                                                                                  string[] fileNames = new string[]
                                                                                  {
                                                                                      "Logotype.svg",
                                                                                      "sample_car.svg",
                                                                                      "rg1024_green_grapes.svg",
                                                                                      "MidMarkerFigure.svg",
                                                                                      "embeddedFonts.svg"
                                                                                  };

                                                                                  Aspose.Imaging.PointF[] scales = new Aspose.Imaging.PointF[]
                                                                                  {
                                                                                      new Aspose.Imaging.PointF(0.5f, 0.5f),
                                                                                      new Aspose.Imaging.PointF(1f, 1f),
                                                                                      new Aspose.Imaging.PointF(2f, 2f),
                                                                                      new Aspose.Imaging.PointF(3.5f, 9.2f),
                                                                                  };

                                                                                  foreach (string inputFile in fileNames)
                                                                                  {
                                                                                      foreach (Aspose.Imaging.PointF scale in scales)
                                                                                      {
                                                                                          string outputFile = string.Format("{0}_{1}_{2}.png", inputFile, scale.X.ToString(System.Globalization.CultureInfo.InvariantCulture), scale.Y.ToString(System.Globalization.CultureInfo.InvariantCulture));
                                                                                          using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(System.IO.Path.Combine(dir, inputFile)))
                                                                                          {
                                                                                              image.Resize((int)(image.Width * scale.X), (int)(image.Height * scale.Y));
                                                                                              image.Save(System.IO.Path.Combine(dir, outputFile), new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                          }
                                                                                      }
                                                                                  }

Resize(int, int, resizeType)

Obnoviť obrázok.

public virtual void Resize(int newWidth, int newHeight, ResizeType resizeType)

Parameters

newWidth int

a novú šírku.

newHeight int

a novú výšku.

resizeType ResizeType

To je reza typ.

Examples

Obnoviť EPS obrázok a exportovať ho do formátu PNG.

// Load EPS image
                                                        using (var image = Image.Load("AstrixObelix.eps"))
                                                        {
                                                            // Resize the image using the Mitchell cubic interpolation method
                                                            image.Resize(400, 400, ResizeType.Mitchell);

                                                            // Export image to PNG format
                                                            image.Save("ExportResult.png", new PngOptions());
                                                        }

Resize obrázok pomocou špecifického typu resize.

using (var image = Image.Load("Photo.jpg"))
                                                   {
                                                       image.Resize(640, 480, ResizeType.CatmullRom);
                                                       image.Save("ResizedPhoto.jpg");

                                                       image.Resize(1024, 768, ResizeType.CubicConvolution);
                                                       image.Save("ResizedPhoto2.jpg");

                                                       var resizeSettings = new ImageResizeSettings
                                                       {
                                                           Mode = ResizeType.CubicBSpline,
                                                           FilterType = ImageFilterType.SmallRectangular
                                                       };

                                                       image.Resize(800, 800, resizeSettings);
                                                       image.Save("ResizedPhoto3.jpg");
                                                   }

Tento príklad nahráva obrázok WMF a recenzuje ho pomocou rôznych metód recenzií.

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

                                                                                        using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.wmf"))
                                                                                        {
                                                                                            // Scale up by 2 times using Nearest Neighbour resampling.
                                                                                            image.Resize(image.Width * 2, image.Height * 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
                                                                                        }

                                                                                        using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.wmf"))
                                                                                        {
                                                                                            // Scale down by 2 times using Nearest Neighbour resampling.
                                                                                            image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
                                                                                        }

                                                                                        using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.wmf"))
                                                                                        {
                                                                                            // Scale up by 2 times using Bilinear resampling.
                                                                                            image.Resize(image.Width * 2, image.Height * 2, Aspose.Imaging.ResizeType.BilinearResample);
                                                                                        }

                                                                                        using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.wmf"))
                                                                                        {
                                                                                            // Scale down by 2 times using Bilinear resampling.
                                                                                            image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.BilinearResample);
                                                                                        }

Tento príklad nahráva obrázok a resizuje ho pomocou rôznych metód resingu.

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

                                                                                     using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                     {
                                                                                         // Scale up by 2 times using Nearest Neighbour resampling.
                                                                                         image.Resize(image.Width* 2, image.Height* 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
                                                                                         image.Save(dir + "upsample.nearestneighbour.gif");
                                                                                     }

                                                                                     using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                     {
                                                                                         // Scale down by 2 times using Nearest Neighbour resampling.
                                                                                         image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
                                                                                         image.Save(dir + "downsample.nearestneighbour.gif");
                                                                                     }

                                                                                     using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                     {
                                                                                         // Scale up by 2 times using Bilinear resampling.
                                                                                         image.Resize(image.Width* 2, image.Height* 2, Aspose.Imaging.ResizeType.BilinearResample);
                                                                                         image.Save(dir + "upsample.bilinear.gif");
                                                                                     }

                                                                                     using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                     {
                                                                                         // Scale down by 2 times using Bilinear resampling.
                                                                                         image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.BilinearResample);
                                                                                         image.Save(dir + "downsample.bilinear.gif");
                                                                                     }

Tento príklad nahráva rasterový obrázok a resizuje ho pomocou rôznych metód resingu.

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

                                                                                           using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                           {
                                                                                               // Scale up by 2 times using Nearest Neighbour resampling.
                                                                                               image.Resize(image.Width * 2, image.Height * 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
                                                                                               image.Save(dir + "upsample.nearestneighbour.gif");
                                                                                           }

                                                                                           using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                           {
                                                                                               // Scale down by 2 times using Nearest Neighbour resampling.
                                                                                               image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
                                                                                               image.Save(dir + "downsample.nearestneighbour.gif");
                                                                                           }

                                                                                           using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                           {
                                                                                               // Scale up by 2 times using Bilinear resampling.
                                                                                               image.Resize(image.Width * 2, image.Height * 2, Aspose.Imaging.ResizeType.BilinearResample);
                                                                                               image.Save(dir + "upsample.bilinear.gif");
                                                                                           }

                                                                                           using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                           {
                                                                                               // Scale down by 2 times using Bilinear resampling.
                                                                                               image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.BilinearResample);
                                                                                               image.Save(dir + "downsample.bilinear.gif");
                                                                                           }

Tento príklad nahráva viacstránkový obrázok ODG a resizuje ho pomocou rôznych metód resingu.

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

                                                                                                   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.odg"))
                                                                                                   {
                                                                                                       // Scale up by 2 times using Nearest Neighbour resampling.
                                                                                                       image.Resize(image.Width* 2, image.Height* 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);

                                                                                                       // Save to PNG with default options.
                                                                                                       image.Save(dir + "upsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                   }

                                                                                                   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.odg"))
                                                                                                   {
                                                                                                       // Scale down by 2 times using Nearest Neighbour resampling.
                                                                                                       image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);

                                                                                                       // Save to PNG with default options.
                                                                                                       image.Save(dir + "downsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                   }

                                                                                                   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.odg"))
                                                                                                   {
                                                                                                       // Scale up by 2 times using Bilinear resampling.
                                                                                                       image.Resize(image.Width* 2, image.Height* 2, Aspose.Imaging.ResizeType.BilinearResample);

                                                                                                       // Save to PNG with default options.
                                                                                                       image.Save(dir + "upsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                   }

                                                                                                   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.odg"))
                                                                                                   {
                                                                                                       // Scale down by 2 times using Bilinear resampling.
                                                                                                       image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.BilinearResample);

                                                                                                       // Save to PNG with default options.
                                                                                                       image.Save(dir + "downsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                   }

Použitie segmentovej masky na urýchlenie segmentácie

// Masking export options
                                                                    Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                    exportOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
                                                                    exportOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());

                                                                    Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions();

                                                                    // Use GraphCut clustering.
                                                                    maskingOptions.Method = Masking.Options.SegmentationMethod.GraphCut;
                                                                    maskingOptions.Decompose = false;
                                                                    maskingOptions.Args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();

                                                                    // The backgroung color will be transparent.
                                                                    maskingOptions.BackgroundReplacementColor = Aspose.Imaging.Color.Transparent;
                                                                    maskingOptions.ExportOptions = exportOptions;

                                                                    string dir = "c:\\temp\\";
                                                                    using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "BigImage.jpg"))
                                                                    {
                                                                        Aspose.Imaging.Size imageSize = image.Size;

                                                                        // Reducing image size to speed up the segmentation process
                                                                        image.ResizeHeightProportionally(600, Aspose.Imaging.ResizeType.HighQualityResample);

                                                                        // Create an instance of the ImageMasking class.
                                                                        Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);

                                                                        // Divide the source image into several clusters (segments).
                                                                        using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = masking.Decompose(maskingOptions))
                                                                        {
                                                                            // Getting the foreground mask
                                                                            using (Aspose.Imaging.RasterImage foregroundMask = maskingResult[1].GetMask()) 
                                                                            {
                                                                                // Increase the size of the mask to the size of the original image
                                                                                foregroundMask.Resize(imageSize.Width, imageSize.Height, Aspose.Imaging.ResizeType.NearestNeighbourResample);

                                                                                // Applying the mask to the original image to obtain a foreground segment
                                                                                using (Aspose.Imaging.RasterImage originImage = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "BigImage.jpg"))
                                                                                {
                                                                                    Aspose.Imaging.Masking.ImageMasking.ApplyMask(originImage, foregroundMask, maskingOptions);
                                                                                    originImage.Save(dir + "BigImage_foreground.png", exportOptions);
                                                                                }
                                                                            }
                                                                        }
                                                                    }

Resize(int, int, ImageResizeSettings)

Obnoviť obrázok.

public abstract void Resize(int newWidth, int newHeight, ImageResizeSettings settings)

Parameters

newWidth int

a novú šírku.

newHeight int

a novú výšku.

settings ImageResizeSettings

Odstránené nastavenia .

Examples

Resize obrázok pomocou špecifického typu resize.

using (var image = Image.Load("Photo.jpg"))
                                                   {
                                                       image.Resize(640, 480, ResizeType.CatmullRom);
                                                       image.Save("ResizedPhoto.jpg");

                                                       image.Resize(1024, 768, ResizeType.CubicConvolution);
                                                       image.Save("ResizedPhoto2.jpg");

                                                       var resizeSettings = new ImageResizeSettings
                                                       {
                                                           Mode = ResizeType.CubicBSpline,
                                                           FilterType = ImageFilterType.SmallRectangular
                                                       };

                                                       image.Resize(800, 800, resizeSettings);
                                                       image.Save("ResizedPhoto3.jpg");
                                                   }

Obnoviť EPS obrázok pomocou pokročilých nastavení.

// Load EPS image
                                                    using (var image = Image.Load("AstrixObelix.eps"))
                                                    {
                                                        // Resize the image using advanced resize settings
                                                        image.Resize(400, 400, new ImageResizeSettings
                                                        {
                                                            // Set the interpolation mode
                                                            Mode = ResizeType.LanczosResample,

                                                            // Set the type of the filter
                                                            FilterType = ImageFilterType.SmallRectangular,

                                                            // Sets the color compare method
                                                            ColorCompareMethod = ColorCompareMethod.Euclidian,

                                                            // Set the color quantization method
                                                            ColorQuantizationMethod = ColorQuantizationMethod.Popularity
                                                        });

                                                        // Export image to PNG format
                                                        image.Save("ExportResult.png", new PngOptions());
                                                    }

Tento príklad nahráva obrázok a resizuje ho pomocou rôznych rezingových nastavení.

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

                                                                                      Aspose.Imaging.ImageResizeSettings resizeSettings = new Aspose.Imaging.ImageResizeSettings();

                                                                                      // The adaptive algorithm based on weighted and blended rational function and lanczos3 interpolation.
                                                                                      resizeSettings.Mode = Aspose.Imaging.ResizeType.AdaptiveResample;

                                                                                      // The small rectangular filter
                                                                                      resizeSettings.FilterType = Aspose.Imaging.ImageFilterType.SmallRectangular;

                                                                                      // The number of colors in the palette.
                                                                                      resizeSettings.EntriesCount = 256;

                                                                                      // The color quantization is not used
                                                                                      resizeSettings.ColorQuantizationMethod = ColorQuantizationMethod.None;

                                                                                      // The euclidian method
                                                                                      resizeSettings.ColorCompareMethod = ColorCompareMethod.Euclidian;

                                                                                      using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                      {
                                                                                          // Scale down by 2 times using adaptive resampling.
                                                                                          image.Resize(image.Width / 2, image.Height / 2, resizeSettings);
                                                                                          image.Save(dir + "downsample.adaptive.gif");
                                                                                      }

ResizeHeightProportionally(int)

Používa sa predvolený Aspose.Imaging.ResizeType.NearestNeighbourResample.

public void ResizeHeightProportionally(int newHeight)

Parameters

newHeight int

a novú výšku.

ResizeHeightProportionally(Inštalácia, ResizeType)

Zvyšuje výšku pomerne.

public virtual void ResizeHeightProportionally(int newHeight, ResizeType resizeType)

Parameters

newHeight int

a novú výšku.

resizeType ResizeType

Druh revízie .

Examples

Tento príklad nahráva obrázok a resizuje ho primerane pomocou rôznych resizačných metód. Len výška je určená, šírka sa automaticky vypočíta.

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

                                                                                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                                                                                                         {
                                                                                                                                                                             // Scale up by 2 times using Nearest Neighbour resampling.
                                                                                                                                                                             image.ResizeHeightProportionally(image.Height* 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
                                                                                                                                                                             image.Save(dir + "upsample.nearestneighbour.gif");
                                                                                                                                                                         }

                                                                                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                                                                                                         {
                                                                                                                                                                             // Scale down by 2 times using Nearest Neighbour resampling.
                                                                                                                                                                             image.ResizeHeightProportionally(image.Height / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
                                                                                                                                                                             image.Save(dir + "upsample.nearestneighbour.gif");
                                                                                                                                                                         }

                                                                                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                                                                                                         {
                                                                                                                                                                             // Scale up by 2 times using Bilinear resampling.
                                                                                                                                                                             image.ResizeHeightProportionally(image.Height* 2, Aspose.Imaging.ResizeType.BilinearResample);
                                                                                                                                                                             image.Save(dir + "upsample.bilinear.gif");
                                                                                                                                                                         }

                                                                                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                                                                                                         {
                                                                                                                                                                             // Scale down by 2 times using Bilinear resampling.
                                                                                                                                                                             image.ResizeHeightProportionally(image.Height / 2, Aspose.Imaging.ResizeType.BilinearResample);
                                                                                                                                                                             image.Save(dir + "downsample.bilinear.gif");
                                                                                                                                                                         }

Použitie segmentovej masky na urýchlenie segmentácie

// Masking export options
                                                                    Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                    exportOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
                                                                    exportOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());

                                                                    Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions();

                                                                    // Use GraphCut clustering.
                                                                    maskingOptions.Method = Masking.Options.SegmentationMethod.GraphCut;
                                                                    maskingOptions.Decompose = false;
                                                                    maskingOptions.Args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();

                                                                    // The backgroung color will be transparent.
                                                                    maskingOptions.BackgroundReplacementColor = Aspose.Imaging.Color.Transparent;
                                                                    maskingOptions.ExportOptions = exportOptions;

                                                                    string dir = "c:\\temp\\";
                                                                    using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "BigImage.jpg"))
                                                                    {
                                                                        Aspose.Imaging.Size imageSize = image.Size;

                                                                        // Reducing image size to speed up the segmentation process
                                                                        image.ResizeHeightProportionally(600, Aspose.Imaging.ResizeType.HighQualityResample);

                                                                        // Create an instance of the ImageMasking class.
                                                                        Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);

                                                                        // Divide the source image into several clusters (segments).
                                                                        using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = masking.Decompose(maskingOptions))
                                                                        {
                                                                            // Getting the foreground mask
                                                                            using (Aspose.Imaging.RasterImage foregroundMask = maskingResult[1].GetMask()) 
                                                                            {
                                                                                // Increase the size of the mask to the size of the original image
                                                                                foregroundMask.Resize(imageSize.Width, imageSize.Height, Aspose.Imaging.ResizeType.NearestNeighbourResample);

                                                                                // Applying the mask to the original image to obtain a foreground segment
                                                                                using (Aspose.Imaging.RasterImage originImage = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "BigImage.jpg"))
                                                                                {
                                                                                    Aspose.Imaging.Masking.ImageMasking.ApplyMask(originImage, foregroundMask, maskingOptions);
                                                                                    originImage.Save(dir + "BigImage_foreground.png", exportOptions);
                                                                                }
                                                                            }
                                                                        }
                                                                    }

ResizeHeightProportionally(snímky, ImageResizeSettings)

Zvyšuje výšku pomerne.

public virtual void ResizeHeightProportionally(int newHeight, ImageResizeSettings settings)

Parameters

newHeight int

a novú výšku.

settings ImageResizeSettings

Obrázok zobrazuje nastavenia.

ResizeWidthProportionally(int)

Používa sa predvolený Aspose.Imaging.ResizeType.NearestNeighbourResample.

public void ResizeWidthProportionally(int newWidth)

Parameters

newWidth int

a novú šírku.

ResizeWidthProportionally(Inštalácia, ResizeType)

Odstráňte šírku pomerne.

public virtual void ResizeWidthProportionally(int newWidth, ResizeType resizeType)

Parameters

newWidth int

a novú šírku.

resizeType ResizeType

Druh revízie .

Examples

Tento príklad nahráva obrázok a resizuje ho primerane pomocou rôznych resizačných metód. Len šírka je určená, výška sa automaticky vypočíta.

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

                                                                                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                                                                                                         {
                                                                                                                                                                             // Scale up by 2 times using Nearest Neighbour resampling.
                                                                                                                                                                             image.ResizeWidthProportionally(image.Width* 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
                                                                                                                                                                             image.Save(dir + "upsample.nearestneighbour.gif");
                                                                                                                                                                         }

                                                                                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                                                                                                         {
                                                                                                                                                                             // Scale down by 2 times using Nearest Neighbour resampling.
                                                                                                                                                                             image.ResizeWidthProportionally(image.Width / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
                                                                                                                                                                             image.Save(dir + "downsample.nearestneighbour.gif");
                                                                                                                                                                         }

                                                                                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                                                                                                         {
                                                                                                                                                                             // Scale up by 2 times using Bilinear resampling.
                                                                                                                                                                             image.ResizeWidthProportionally(image.Width* 2, Aspose.Imaging.ResizeType.BilinearResample);
                                                                                                                                                                             image.Save(dir + "upsample.bilinear.gif");
                                                                                                                                                                         }

                                                                                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                                                                                                         {
                                                                                                                                                                             // Scale down by 2 times using Bilinear resampling.
                                                                                                                                                                             image.ResizeWidthProportionally(image.Width / 2, Aspose.Imaging.ResizeType.BilinearResample);
                                                                                                                                                                             image.Save(dir + "downsample.bilinear.gif");
                                                                                                                                                                         }

ResizeWidthProportionally(snímky, ImageResizeSettings)

Odstráňte šírku pomerne.

public virtual void ResizeWidthProportionally(int newWidth, ImageResizeSettings settings)

Parameters

newWidth int

a novú šírku.

settings ImageResizeSettings

Obrázok zobrazuje nastavenia.

Rotate(flotila)

Obrázok sa otáča okolo centra.

public virtual void Rotate(float angle)

Parameters

angle float

Zvuk sa otáča v stupňoch. pozitívne hodnoty sa otáčajú hodinovo.

RotateFlip(RotateFlipType)

Rotuje, flips, alebo rotuje a flips obrázok.

public abstract void RotateFlip(RotateFlipType rotateFlipType)

Parameters

rotateFlipType RotateFlipType

Typ rotujúceho flipu.

Examples

Tento príklad preukazuje použitie operácie Rotate na obrázku. Príklad nahráva existujúci obrázkový súbor z nejakého umiestnenia disku a vykonáva operáciu rotacie na obraze podľa hodnoty Enum Aspose.Imaging.RotateFlipType

//Create an instance of image class and initialize it with an existing image file through File path
                                                                                                                                                                                                                                                       using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"C:\temp\sample.bmp"))
                                                                                                                                                                                                                                                       {
                                                                                                                                                                                                                                                           //Rotate the image at 180 degree about X axis
                                                                                                                                                                                                                                                           image.RotateFlip(Aspose.Imaging.RotateFlipType.Rotate180FlipX);

                                                                                                                                                                                                                                                           // save all changes.
                                                                                                                                                                                                                                                           image.Save();
                                                                                                                                                                                                                                                       }

Tento príklad nahrádza obrázok, otáča ho o 90 stupňov a voliteľne flips obraz horizontálne a/alebo vertikálne.

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

                                                                                                                                          Aspose.Imaging.RotateFlipType[] rotateFlipTypes = new Aspose.Imaging.RotateFlipType[]
                                                                                                                                          {
                                                                                                                                              Aspose.Imaging.RotateFlipType.Rotate90FlipNone,
                                                                                                                                              Aspose.Imaging.RotateFlipType.Rotate90FlipX,
                                                                                                                                              Aspose.Imaging.RotateFlipType.Rotate90FlipXY,
                                                                                                                                              Aspose.Imaging.RotateFlipType.Rotate90FlipY,
                                                                                                                                          };

                                                                                                                                          foreach (Aspose.Imaging.RotateFlipType rotateFlipType in rotateFlipTypes)
                                                                                                                                          {
                                                                                                                                              // Rotate, flip and save to the output file.
                                                                                                                                              using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                                                              {
                                                                                                                                                  image.RotateFlip(rotateFlipType);
                                                                                                                                                  image.Save(dir + "sample." + rotateFlipType + ".bmp");
                                                                                                                                              }
                                                                                                                                          }

Tento príklad nahrádza obrázok ODG, otáča ho o 90 stupňov na hodinky a voliteľne flips obrázku horizontálne a/alebo vertikálne.

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

                                                                                                                                             Aspose.Imaging.RotateFlipType[] rotateFlipTypes = new Aspose.Imaging.RotateFlipType[]
                                                                                                                                             {
                                                                                                                                                 Aspose.Imaging.RotateFlipType.Rotate90FlipNone,
                                                                                                                                                 Aspose.Imaging.RotateFlipType.Rotate90FlipX,
                                                                                                                                                 Aspose.Imaging.RotateFlipType.Rotate90FlipXY,
                                                                                                                                                 Aspose.Imaging.RotateFlipType.Rotate90FlipY,
                                                                                                                                             };

                                                                                                                                             foreach (Aspose.Imaging.Image rotateFlipType in rotateFlipTypes)
                                                                                                                                             {
                                                                                                                                                 // Rotate, flip and save to the output file.
                                                                                                                                                 using (Aspose.Imaging.Image image = (Aspose.Imaging.FileFormats.OpenDocument.OdImage)Aspose.Imaging.Image.Load(dir + "sample.odg"))
                                                                                                                                                 {
                                                                                                                                                     image.RotateFlip(rotateFlipType);
                                                                                                                                                     image.Save(dir + "sample." + rotateFlipType + ".png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                                 }
                                                                                                                                             }

Save()

Uloží údaje o obraze do podkladového prúdu.

public override sealed void Save()

Examples

Nasledujúci príklad ukazuje, ako uložiť kompletný BMP obrázok alebo jeho časť do súboru alebo toku.

string dir = "c:\\temp\\";
                                                                                                          using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                          {
                                                                                                              Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;

                                                                                                              // Convert to a black-white image
                                                                                                              bmpImage.BinarizeOtsu();

                                                                                                              // Save to the same location with default options.
                                                                                                              image.Save();

                                                                                                              Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions();

                                                                                                              // A palette contains only two colors: Black and White in this case.
                                                                                                              saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.CreateMonochrome();

                                                                                                              // For all monochrome images (including black-white ones) it is enough to allocate 1 bit per pixel.
                                                                                                              saveOptions.BitsPerPixel = 1;

                                                                                                              // Save to another location with the specified options.
                                                                                                              image.Save(dir + "sample.bw.palettized.bmp", saveOptions);

                                                                                                              // Save only the central part of the image.
                                                                                                              Aspose.Imaging.Rectangle bounds = new Aspose.Imaging.Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
                                                                                                              image.Save(dir + "sample.bw.palettized.part.bmp", saveOptions, bounds);

                                                                                                              // Save the entire image to a memory stream
                                                                                                              using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                              {
                                                                                                                  image.Save(stream, saveOptions);
                                                                                                                  System.Console.WriteLine("The size of the whole image in bytes: {0}", stream.Length);
                                                                                                              }

                                                                                                              // Save the central part of the image to a memory stream
                                                                                                              using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                              {
                                                                                                                  image.Save(stream, saveOptions, bounds);
                                                                                                                  System.Console.WriteLine("The size of the central part of the image in bytes: {0}", stream.Length);
                                                                                                              }
                                                                                                          }
                                                                                                          //The output may look like this:
                                                                                                          //The size of the whole image in bytes: 24062
                                                                                                          //The size of the central part of the image in bytes: 6046

Save(Stretnutie)

Uloží obrázok do špecifikovaného umiestnenia súboru.

public override void Save(string filePath)

Parameters

filePath string

Stránka na uloženie obrazu.

Save(String, ImageOptionsBase)

Uloží údaje objektu na špecifikované umiestnenie súboru v špecifikovanom formáte súboru podľa možností uloženia.

public virtual void Save(string filePath, ImageOptionsBase options)

Parameters

filePath string

Pôvodná cesta súboru.

options ImageOptionsBase

a možnosťami .

Examples

Nasledujúci príklad nahráva BMP snímku z súboru, potom uloží obrázok do súbory PNG.

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

                                                                                                   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                   {
                                                                                                       // Save the entire image to a PNG file.
                                                                                                       Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                                       image.Save(dir + "output.png", saveOptions);
                                                                                                   }

Tento príklad ukazuje jednoduché kroky na uloženie obrazu.Ak chcete preukázať túto funkciu, naložíme existujúci súbor z nejakého umiestnenia disku, vykonáme operáciu Rotate na obraze a uložíte obrázok vo formáte PSD pomocou Path File

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

                                                                                                                                                                                                                                         //Create an instance of image class and initialize it with an existing file through File path
                                                                                                                                                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                                                                                                                                                         {
                                                                                                                                                                                                                                             //Rotate the image at 180 degree about X axis
                                                                                                                                                                                                                                             image.RotateFlip(Aspose.Imaging.RotateFlipType.Rotate180FlipX);

                                                                                                                                                                                                                                             //Save the Image as PSD to File Path with default PsdOptions settings
                                                                                                                                                                                                                                             image.Save(dir + "output.psd", new Aspose.Imaging.ImageOptions.PsdOptions());
                                                                                                                                                                                                                                         }

Nasledujúci príklad ukazuje, ako uložiť kompletný BMP obrázok alebo jeho časť do súboru alebo toku.

string dir = "c:\\temp\\";
                                                                                                          using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                          {
                                                                                                              Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;

                                                                                                              // Convert to a black-white image
                                                                                                              bmpImage.BinarizeOtsu();

                                                                                                              // Save to the same location with default options.
                                                                                                              image.Save();

                                                                                                              Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions();

                                                                                                              // A palette contains only two colors: Black and White in this case.
                                                                                                              saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.CreateMonochrome();

                                                                                                              // For all monochrome images (including black-white ones) it is enough to allocate 1 bit per pixel.
                                                                                                              saveOptions.BitsPerPixel = 1;

                                                                                                              // Save to another location with the specified options.
                                                                                                              image.Save(dir + "sample.bw.palettized.bmp", saveOptions);

                                                                                                              // Save only the central part of the image.
                                                                                                              Aspose.Imaging.Rectangle bounds = new Aspose.Imaging.Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
                                                                                                              image.Save(dir + "sample.bw.palettized.part.bmp", saveOptions, bounds);

                                                                                                              // Save the entire image to a memory stream
                                                                                                              using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                              {
                                                                                                                  image.Save(stream, saveOptions);
                                                                                                                  System.Console.WriteLine("The size of the whole image in bytes: {0}", stream.Length);
                                                                                                              }

                                                                                                              // Save the central part of the image to a memory stream
                                                                                                              using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                              {
                                                                                                                  image.Save(stream, saveOptions, bounds);
                                                                                                                  System.Console.WriteLine("The size of the central part of the image in bytes: {0}", stream.Length);
                                                                                                              }
                                                                                                          }
                                                                                                          //The output may look like this:
                                                                                                          //The size of the whole image in bytes: 24062
                                                                                                          //The size of the central part of the image in bytes: 6046

Save(reťazec, ImageOptionsBase, Rectangle)

Uloží údaje objektu na špecifikované umiestnenie súboru v špecifikovanom formáte súboru podľa možností uloženia.

public virtual void Save(string filePath, ImageOptionsBase options, Rectangle boundsRectangle)

Parameters

filePath string

Pôvodná cesta súboru.

options ImageOptionsBase

a možnosťami .

boundsRectangle Rectangle

Destinácia obrázok obmedzuje rektangul. Nastaviť prázdny rektangul pre použitie zdrojových hraníc.

Examples

Nasledujúci príklad nahráva obrázok BMP z súboru, potom uloží rektangulárnu časť obrazu do súbory PNG.

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

                                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                                         {
                                                                                                                             // Save the upper half of the image to a PNG file.
                                                                                                                             Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                                                             Aspose.Imaging.Rectangle bounds = new Aspose.Imaging.Rectangle(0, 0, image.Width, image.Height / 2);
                                                                                                                             image.Save(dir + "output.png", saveOptions, bounds);
                                                                                                                         }

Nasledujúci príklad ukazuje, ako uložiť kompletný BMP obrázok alebo jeho časť do súboru alebo toku.

string dir = "c:\\temp\\";
                                                                                                          using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                          {
                                                                                                              Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;

                                                                                                              // Convert to a black-white image
                                                                                                              bmpImage.BinarizeOtsu();

                                                                                                              // Save to the same location with default options.
                                                                                                              image.Save();

                                                                                                              Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions();

                                                                                                              // A palette contains only two colors: Black and White in this case.
                                                                                                              saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.CreateMonochrome();

                                                                                                              // For all monochrome images (including black-white ones) it is enough to allocate 1 bit per pixel.
                                                                                                              saveOptions.BitsPerPixel = 1;

                                                                                                              // Save to another location with the specified options.
                                                                                                              image.Save(dir + "sample.bw.palettized.bmp", saveOptions);

                                                                                                              // Save only the central part of the image.
                                                                                                              Aspose.Imaging.Rectangle bounds = new Aspose.Imaging.Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
                                                                                                              image.Save(dir + "sample.bw.palettized.part.bmp", saveOptions, bounds);

                                                                                                              // Save the entire image to a memory stream
                                                                                                              using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                              {
                                                                                                                  image.Save(stream, saveOptions);
                                                                                                                  System.Console.WriteLine("The size of the whole image in bytes: {0}", stream.Length);
                                                                                                              }

                                                                                                              // Save the central part of the image to a memory stream
                                                                                                              using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                              {
                                                                                                                  image.Save(stream, saveOptions, bounds);
                                                                                                                  System.Console.WriteLine("The size of the central part of the image in bytes: {0}", stream.Length);
                                                                                                              }
                                                                                                          }
                                                                                                          //The output may look like this:
                                                                                                          //The size of the whole image in bytes: 24062
                                                                                                          //The size of the central part of the image in bytes: 6046

Exceptions

ArgumentNullException

Možnosti

ImageSaveException

Zdrojová úspora sa zlyhala.

Save(Stream, ImageOptionsBase)

Uloží údaje obrazu do špecifikovaného prúdu v špecifikovanom formáte súboru podľa možností uloženia.

public void Save(Stream stream, ImageOptionsBase optionsBase)

Parameters

stream Stream

Stream na ukladanie údajov obrazu na.

optionsBase ImageOptionsBase

Možnosti na úsporu.

Examples

Nasledujúci príklad nahráva obrázok z súboru, potom ukladá obraz do prúdu PNG.

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

                                                                                                       using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                       {
                                                                                                           Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                                           using (System.IO.Stream outputStream = System.IO.File.Open(dir + "output.png", System.IO.FileMode.Create))
                                                                                                           {
                                                                                                               // Save the entire image to a file stream.
                                                                                                               image.Save(outputStream, saveOptions);
                                                                                                           }
                                                                                                       }

Tento príklad ukazuje proces Ušetriť obrázok do MemoryStream. Ak chcete preukázať túto operáciu, napríklad nahrádza existujúci súbor z nejakého umiestnenia disku, vykonáva funkciu Rotate na obrázku a uloží obraz vo formáte PSD

//Create an instance of MemoryStream
                                                                                                                                                                                                                                            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                //Create an instance of image class and initialize it with an existing file through File path
                                                                                                                                                                                                                                                using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"C:\temp\sample.bmp"))
                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                    //Rotate the image at 180 degree about X axis
                                                                                                                                                                                                                                                    image.RotateFlip(Aspose.Imaging.RotateFlipType.Rotate180FlipX);

                                                                                                                                                                                                                                                    //Save the Image as PSD to MemoryStream with default PsdOptions settings
                                                                                                                                                                                                                                                    image.Save(stream, new Aspose.Imaging.ImageOptions.PsdOptions());
                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                            }

Nasledujúci príklad ukazuje, ako uložiť kompletný BMP obrázok alebo jeho časť do súboru alebo toku.

string dir = "c:\\temp\\";
                                                                                                          using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                          {
                                                                                                              Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;

                                                                                                              // Convert to a black-white image
                                                                                                              bmpImage.BinarizeOtsu();

                                                                                                              // Save to the same location with default options.
                                                                                                              image.Save();

                                                                                                              Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions();

                                                                                                              // A palette contains only two colors: Black and White in this case.
                                                                                                              saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.CreateMonochrome();

                                                                                                              // For all monochrome images (including black-white ones) it is enough to allocate 1 bit per pixel.
                                                                                                              saveOptions.BitsPerPixel = 1;

                                                                                                              // Save to another location with the specified options.
                                                                                                              image.Save(dir + "sample.bw.palettized.bmp", saveOptions);

                                                                                                              // Save only the central part of the image.
                                                                                                              Aspose.Imaging.Rectangle bounds = new Aspose.Imaging.Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
                                                                                                              image.Save(dir + "sample.bw.palettized.part.bmp", saveOptions, bounds);

                                                                                                              // Save the entire image to a memory stream
                                                                                                              using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                              {
                                                                                                                  image.Save(stream, saveOptions);
                                                                                                                  System.Console.WriteLine("The size of the whole image in bytes: {0}", stream.Length);
                                                                                                              }

                                                                                                              // Save the central part of the image to a memory stream
                                                                                                              using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                              {
                                                                                                                  image.Save(stream, saveOptions, bounds);
                                                                                                                  System.Console.WriteLine("The size of the central part of the image in bytes: {0}", stream.Length);
                                                                                                              }
                                                                                                          }
                                                                                                          //The output may look like this:
                                                                                                          //The size of the whole image in bytes: 24062
                                                                                                          //The size of the central part of the image in bytes: 6046

Exceptions

ArgumentNullException

MožnostiBase

ArgumentException

Nie je možné uložiť do špecifikovaného formátu, pretože v súčasnosti nie je podporovaný; možnostiBase

ImageSaveException

Vývoz obrazu sa zlyhal.

Save(Stream, ImageOptionsBase, Rectangle)

Uloží údaje obrazu do špecifikovaného prúdu v špecifikovanom formáte súboru podľa možností uloženia.

public virtual void Save(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)

Parameters

stream Stream

Stream na ukladanie údajov obrazu na.

optionsBase ImageOptionsBase

Možnosti na úsporu.

boundsRectangle Rectangle

Obrázok určenia obmedzuje rektangul. Nastaviť prázdny rektangul pre použitie zdrojových hraníc.

Examples

Nasledujúci príklad nahráva obrázok z súboru, potom uloží rektangulárnu časť obrazu do prúdu PNG.

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

                                                                                                                             using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                                             {
                                                                                                                                 Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                                                                 Aspose.Imaging.Rectangle bounds = new Aspose.Imaging.Rectangle(0, 0, image.Width, image.Height / 2);
                                                                                                                                 using (System.IO.Stream outputStream = System.IO.File.Open(dir + "sample.output.png", System.IO.FileMode.Create))
                                                                                                                                 {
                                                                                                                                     // Save the upper half of the image to a file stream.
                                                                                                                                     image.Save(outputStream, saveOptions, bounds);
                                                                                                                                 }
                                                                                                                             }

Nasledujúci príklad ukazuje, ako uložiť kompletný BMP obrázok alebo jeho časť do súboru alebo toku.

string dir = "c:\\temp\\";
                                                                                                          using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                          {
                                                                                                              Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;

                                                                                                              // Convert to a black-white image
                                                                                                              bmpImage.BinarizeOtsu();

                                                                                                              // Save to the same location with default options.
                                                                                                              image.Save();

                                                                                                              Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions();

                                                                                                              // A palette contains only two colors: Black and White in this case.
                                                                                                              saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.CreateMonochrome();

                                                                                                              // For all monochrome images (including black-white ones) it is enough to allocate 1 bit per pixel.
                                                                                                              saveOptions.BitsPerPixel = 1;

                                                                                                              // Save to another location with the specified options.
                                                                                                              image.Save(dir + "sample.bw.palettized.bmp", saveOptions);

                                                                                                              // Save only the central part of the image.
                                                                                                              Aspose.Imaging.Rectangle bounds = new Aspose.Imaging.Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
                                                                                                              image.Save(dir + "sample.bw.palettized.part.bmp", saveOptions, bounds);

                                                                                                              // Save the entire image to a memory stream
                                                                                                              using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                              {
                                                                                                                  image.Save(stream, saveOptions);
                                                                                                                  System.Console.WriteLine("The size of the whole image in bytes: {0}", stream.Length);
                                                                                                              }

                                                                                                              // Save the central part of the image to a memory stream
                                                                                                              using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                              {
                                                                                                                  image.Save(stream, saveOptions, bounds);
                                                                                                                  System.Console.WriteLine("The size of the central part of the image in bytes: {0}", stream.Length);
                                                                                                              }
                                                                                                          }
                                                                                                          //The output may look like this:
                                                                                                          //The size of the whole image in bytes: 24062
                                                                                                          //The size of the central part of the image in bytes: 6046

Exceptions

ArgumentNullException

MožnostiBase

ArgumentException

Nie je možné uložiť do špecifikovaného formátu, pretože v súčasnosti nie je podporovaný; možnostiBase

ImageSaveException

Vývoz obrazu sa zlyhal.

SetPalette(IkolorPalette, Boolová)

Vytvorte obrazovú paletu.

public abstract void SetPalette(IColorPalette palette, bool updateColors)

Parameters

palette IColorPalette

Paleta na nastavenie.

updateColors bool

Ak je nastavený na “skutočné” farby budú aktualizované podľa novej palety; inak farebné indexy zostanú nezmenené.

UpdateContainer(Image)

Aktualizácia kontajnera.

protected void UpdateContainer(Image container)

Parameters

container Image

v kontajneroch .

Pozri tiež

DataStreamSupporter , IObjectWithBounds

 Slovenčina