Class Image

Class Image

ja nimityö: Aspose.Imaging Kokoelma: Aspose.Imaging.dll (25.4.0)

Kuva on kaikenlaisten kuvien perusluokka.

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

Inheritance

object DisposableObject DataStreamSupporter Image

Derived

RasterImage , VectorImage

Implements

IDisposable , IObjectWithBounds

Perintöjäsenet

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

Määritä, käytetäänkö paletta kuvaa.

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

Muokkaa kuvaa käyttämällä erityistä Resize-tyyppiä.

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");
                                                   }

Tämä esimerkki luo uuden kuvan tiedoston jossakin levyn sijainnissa, kuten on määritelty BmpOptions -tuotteen lähdeominaisuudesta. useita ominaisuuksia Bmoptions-tuotannolle asetetaan ennen todellisen kuvien luomista. Erityisesti Lähteominaisuus, joka viittaa tässä tapauksessa todelliseen levän sijaintiin.

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

Aloitetaan uusi esimerkki Aspose.Imaging.Image luokka.

[JsonConstructor]
protected Image()

Image(ICOLORPALETTI)

Aloitetaan uusi esimerkki Aspose.Imaging.Image luokka.

protected Image(IColorPalette colorPalette)

Parameters

colorPalette IColorPalette

Ja väri paletti.

Properties

AutoAdjustPalette

Saat tai asettaa arvon, joka osoittaa, onko automaattisesti säädetty paletti.

public bool AutoAdjustPalette { get; set; }

Omistuksen arvo

bool

BackgroundColor

Saat tai asettaa arvo taustan värille.

public virtual Color BackgroundColor { get; set; }

Omistuksen arvo

Color

BitsPerPixel

Saa kuvan bittit pixel-laskenta kohden.

public abstract int BitsPerPixel { get; }

Omistuksen arvo

int

Bounds

Saa kuvan rajat.

public Rectangle Bounds { get; }

Omistuksen arvo

Rectangle

BufferSizeHint

Saa tai asettaa bufferin koon merkki, joka määritellään max sallitun koon kaikille sisäisille buffereille.

public int BufferSizeHint { get; set; }

Omistuksen arvo

int

Container

Valitse Aspose.Imaging.Imaalin säiliö.

public Image Container { get; }

Omistuksen arvo

Image

Remarks

Jos tämä omaisuus ei ole nolla, se osoittaa, että kuva on toisen kuvan sisällä.

FileFormat

Saat arvon tiedostomuodossa

public virtual FileFormat FileFormat { get; }

Omistuksen arvo

FileFormat

HasBackgroundColor

Saat tai asetat arvon, joka osoittaa, onko kuvalla taustaväri.

public virtual bool HasBackgroundColor { get; set; }

Omistuksen arvo

bool

Height

Se saa kuvan korkeuden.

public abstract int Height { get; }

Omistuksen arvo

int

InterruptMonitor

Ota tai aseta katkaistu monitorin.

public InterruptMonitor InterruptMonitor { get; set; }

Omistuksen arvo

InterruptMonitor

Palette

Väripalettia ei käytetä, kun pikselejä esitetään suoraan.

public IColorPalette Palette { get; set; }

Omistuksen arvo

IColorPalette

Size

Saa kuvan koon.

public Size Size { get; }

Omistuksen arvo

Size

Examples

Tämä esimerkki näyttää, miten ladata DJVU-kuva tiedoston virtauksesta ja tulostaa tietoja sivuista.

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

Saat arvon, joka osoittaa, käytetäänkö kuvan paletta.

public virtual bool UsePalette { get; }

Omistuksen arvo

bool

Examples

Määritä, käytetäänkö paletta kuvaa.

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

Width

Saa kuvan leveys.

public abstract int Width { get; }

Omistuksen arvo

int

Methods

CanLoad(String)

Määrittää, voidaanko kuvaa ladata määritellystä tiedoston reitistä.

public static bool CanLoad(string filePath)

Parameters

filePath string

Ja tiedoston reitti.

Returns

bool

’todellinen’ jos kuvaa voidaan ladata määritellystä tiedostosta; muuten ’ väärennös'.

Examples

Tämä esimerkki määrittää, voidaanko kuvaa ladata tiedostosta.

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

CanLoad(LoadOptions ja LoadOptions)

Määrittää, voidaanko kuvaa ladata määritellystä tiedostomenetelmästä ja valinnaisesti käyttämällä määritettyjä avoimia vaihtoehtoja.

public static bool CanLoad(string filePath, LoadOptions loadOptions)

Parameters

filePath string

Ja tiedoston reitti.

loadOptions LoadOptions

kuormitusvaihtoehtoja varten.

Returns

bool

’todellinen’ jos kuvaa voidaan ladata määritellystä tiedostosta; muuten ’ väärennös'.

CanLoad(Stream)

Määrittää, voidaanko kuvaa ladata määritellystä virtauksesta.

public static bool CanLoad(Stream stream)

Parameters

stream Stream

virta lasketaan pois.

Returns

bool

’todellinen’ jos kuvaa voidaan ladata määritellystä virtauksesta; muuten ’väärä’.

Examples

Tämä esimerkki määrittää, voidaanko kuvaa ladata tiedoston virtauksesta.

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(Liikenne, LoadOptions)

Määrittää, voidaanko kuvaa ladata määritellystä virtauksesta ja valinnaisesti käyttämällä määriteltyä loadOptions'.

public static bool CanLoad(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

virta lasketaan pois.

loadOptions LoadOptions

kuormitusvaihtoehtoja varten.

Returns

bool

’todellinen’ jos kuvaa voidaan ladata määritellystä virtauksesta; muuten ’väärä’.

CanSave(ImageOptionsBase)

Määrittää, voidaanko kuvaa tallentaa määriteltyyn tiedostomuotoon, jota edustavat menneet tallennusvaihtoehdot.

public bool CanSave(ImageOptionsBase options)

Parameters

options ImageOptionsBase

säästää vaihtoehtoja käytettäväksi.

Returns

bool

’todellinen’ jos kuvaa voidaan tallentaa tiedostomuotoon, jota edustaa aikaisemmat tallennusvaihtoehdot; muuten ’ väärennös'.

Examples

Tämä esimerkki osoittaa, miten voidaan määrittää, voidaanko kuvaa tallentaa tiedostomuotoon, jota edustaa aikaisempien tallennusvaihtoehtojen avulla.

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(Ilmoittautuminen, int, int)

Luo uusi kuva käyttämällä määritettyjä luomavaihtoehtoja.

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

Parameters

imageOptions ImageOptionsBase

Kuvien vaihtoehtoja varten.

width int

Ja sen leveys.

height int

ja korkeuden.

Returns

Image

Uudelleen luotu kuva.

Examples

Tämä esimerkki luo uuden kuvan tiedoston jossakin levyn sijainnissa, kuten on määritelty BmpOptions -tuotteen lähdeominaisuudesta. useita ominaisuuksia Bmoptions-tuotannolle asetetaan ennen todellisen kuvien luomista. Erityisesti Lähteominaisuus, joka viittaa tässä tapauksessa todelliseen levän sijaintiin.

//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[])

Luo uusi kuva käyttämällä määriteltyjä kuvia sivuina

public static Image Create(Image[] images)

Parameters

images Image []

ja kuvia .

Returns

Image

Kuva kuin ImultipageImage

Create(MultipageCreateOptions)

Luo määritelty monivuotinen luo vaihtoehtoja.

public static Image Create(MultipageCreateOptions multipageCreateOptions)

Parameters

multipageCreateOptions MultipageCreateOptions

Moni sivusto luo vaihtoehtoja.

Returns

Image

Monipuolinen kuva

Create(String[], ja bool)

Luo usean sivun kuvan, joka sisältää määritellyt tiedostot.

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

Parameters

files string []

ja tiedostoja.

throwExceptionOnLoadError bool

Jos asetat ’totu’ [hävitä poikkeus kuormitusvirheelle].

Returns

Image

Monipuolinen kuva

Create(String[])

Luo usean sivun kuvan, joka sisältää määritellyt tiedostot.

public static Image Create(string[] files)

Parameters

files string []

ja tiedostoja.

Returns

Image

Monipuolinen kuva

Create(Image[], ja bool)

Luo uusi kuva määritellyn kuvan sivuina.

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

Parameters

images Image []

ja kuvia .

disposeImages bool

Jos asetat ”todelliseksi” [tarkoita kuvia].

Returns

Image

Kuva kuin ImultipageImage

Crop(Rectangle)

Valitse määritelty reaktio.

public virtual void Crop(Rectangle rectangle)

Parameters

rectangle Rectangle

Se on oikea.

Examples

Seuraava esimerkki tuottaa raster-kuvan. viljelyalue on määritelty 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(Inti, Inti, Inti ja Inti)

Kasvi kuvaa muutoksilla.

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

Parameters

leftShift int

Vasemmisto muuttuu.

rightShift int

Oikea muutos on.

topShift int

Korkeimman vaihdon mukaan.

bottomShift int

Alhainen muutos on.

Examples

Seuraava esimerkki kasvaa rasterin kuvan. kasvialue on määritelty vasemman, ylä, oikean, alhaisen marginaalin kautta.

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)

Se ei voi tallentaa viestiä.

protected virtual string GetCanNotSaveMessage(ImageOptionsBase optionsBase)

Parameters

optionsBase ImageOptionsBase

Kuvien vaihtoehtoja varten.

Returns

string

Se ei voi tallentaa viestiä.

GetDefaultOptions(Objekti[])

Saat default vaihtoehtoja.

public virtual ImageOptionsBase GetDefaultOptions(object[] args)

Parameters

args object []

ja argumentit .

Returns

ImageOptionsBase

Oletusvaihtoehtoja

GetFileFormat(String)

Saat tiedoston muodon.

public static FileFormat GetFileFormat(string filePath)

Parameters

filePath string

Ja tiedoston reitti.

Returns

FileFormat

Määritetty tiedostomuoto.

Examples

Tämä esimerkki osoittaa, miten määrittää kuvan muodon lataamatta koko kuvaa tiedostosta.

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

Määritetty tiedostomuoto ei tarkoita, että määritettyä kuvaa voidaan ladata.Käytä yhden CanLoadin menetelmän ylitykseen määrittääkseen, voidaanko tiedosto ladata.

GetFileFormat(Stream)

Saat tiedoston muodon.

public static FileFormat GetFileFormat(Stream stream)

Parameters

stream Stream

ja virtauksen.

Returns

FileFormat

Määritetty tiedostomuoto.

Examples

Tämä esimerkki näyttää, miten määrittää kuvan muodon lataamatta koko kuvaa tiedoston virtauksesta.

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

Määritetty tiedostomuoto ei tarkoita, että määritettyä kuvaa voidaan ladata.Käytä yksi CanLoadin menetelmä ylittää määrittääksesi, voidaanko virtaa ladata.

GetFitRectangle(Rectangle)

Se saa oikea kulma, joka vastaa nykyistä kuvaa.

protected Rectangle GetFitRectangle(Rectangle rectangle)

Parameters

rectangle Rectangle

rektangulille sopivan rektangulin saamiseksi.

Returns

Rectangle

oikea oikea oikea oikea

GetFitRectangle(Säätiö, int[])

Saat oikea kulma, joka sopii nykyiseen bitmap ottaen huomioon kuluneet pikselit. kuluneet pikselit rajan lukumäärä pitäisi olla sama kuin sopiva oikea kulma koko.

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

Parameters

rectangle Rectangle

rektangulille sopivan rektangulin saamiseksi.

pixels int []

32-bittinen ARGB-pikseli on käytössä.

Returns

Rectangle

Sopii oikeaan reikiin.

GetFittingRectangle(Säätiö, int, int)

Se saa oikea kulma, joka vastaa nykyistä kuvaa.

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

Parameters

rectangle Rectangle

rektangulille sopivan rektangulin saamiseksi.

width int

Kohde on leveä.

height int

Kohde on korkeus.

Returns

Rectangle

Sopeutuva oikea kulma tai poikkeus, jos ei löydy sopivaa oikea kulmaa.

GetFittingRectangle(Säätiö, int[], ja int, int)

Se saa oikea kulma, joka vastaa nykyistä kuvaa.

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

Parameters

rectangle Rectangle

rektangulille sopivan rektangulin saamiseksi.

pixels int []

32-bittiset ARGB-pikselit

width int

Kohde on leveä.

height int

Kohde on korkeus.

Returns

Rectangle

Sopeutuva oikea kulma tai poikkeus, jos ei löydy sopivaa oikea kulmaa.

GetImage2Export(ImageOptionsBase, Rectangle ja IImageExporter)

Se saa kuvan vientiin.

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

Parameters

optionsBase ImageOptionsBase

Kuva vaihtoehtoja perusta.

boundsRectangle Rectangle

Rajoitukset ovat reaktiivisia.

exporter IImageExporter

ja vientiä varten.

Returns

Image

Kuvia vientiin

GetOriginalOptions()

Saat vaihtoehtoja alkuperäisten tiedoston asetusten perusteella.Tämä voi olla hyödyllistä pitää bit-syvyys ja muut parametrit alkuperäisen kuvan muuttumaton.Esimerkiksi, jos lataamme mustavalkoisen PNG-kuvan 1 bitilla pikseliä kohden ja tallennamme sen käyttämälläAspose.Imaging.DataStreamSupporter.Save(System.String) -menetelmä, tuotanto PNG-kuva 8-bittisellä pixelillä.Sen välttämiseksi ja PNG-kuvan tallentamiseksi 1 bittillä pikseliä kohden, käytä tätä menetelmää saadaksesi vastaavat tallennusvaihtoehdot ja siirtäksesi neAspose.Imaging.Image.Save(System.String,_Wl17.ImagineOptionsBase) -menetelmä on toinen parametri.

public virtual ImageOptionsBase GetOriginalOptions()

Returns

ImageOptionsBase

Vaihtoehdot perustuvat alkuperäisiin tiedoston asetuksiin.

GetProportionalHeight(Inti, Inti ja Inti)

Se saa suhteellisen korkeuden.

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

Parameters

width int

Ja sen leveys.

height int

ja korkeuden.

newWidth int

Ja uusi leveys.

Returns

int

ja suhteellisen korkeuden.

GetProportionalWidth(Inti, Inti ja Inti)

Se on suhteellinen leveys.

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

Parameters

width int

Ja sen leveys.

height int

ja korkeuden.

newHeight int

Ja uusi korkeus.

Returns

int

ja suhteellisen leveyden.

GetSerializedStream(ImageOptionsBase, Rectangle, ulos int)

Siirretään APS:een

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

Parameters

imageOptions ImageOptionsBase

Kuvien vaihtoehtoja varten.

clippingRectangle Rectangle

Kynttilän oikea kulma.

pageNumber int

Sivun numero on.

Returns

Stream

Serioitu virtaus

Load(LoadOptions ja LoadOptions)

Jos filePath’ on tiedostomuoto, menetelmä vain avaa tiedoston.Jos file Path on URL, metodi ladata tiedosto, tallentaa sen väliaikaisena ja avata sen.

public static Image Load(string filePath, LoadOptions loadOptions)

Parameters

filePath string

Tiedoston reitti tai URL kuvan lataamiseen.

loadOptions LoadOptions

kuormitusvaihtoehtoja varten.

Returns

Image

Ladattu kuva on.

Load(String)

Jos filePath’ on tiedostomuoto, menetelmä vain avaa tiedoston.Jos file Path on URL, metodi ladata tiedosto, tallentaa sen väliaikaisena ja avata sen.

public static Image Load(string filePath)

Parameters

filePath string

Tiedoston reitti tai URL kuvan lataamiseen.

Returns

Image

Ladattu kuva on.

Examples

Tämä esimerkki osoittaa olemassa olevan kuvan tiedoston lataamisen tapaukseen Aspose.Imaging.kuva tietyn tiedostomuodon avulla

//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(Liikenne, LoadOptions)

Lataa uusi kuva määritellystä virtauksesta.

public static Image Load(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

Virta ladata kuvan pois.

loadOptions LoadOptions

kuormitusvaihtoehtoja varten.

Returns

Image

Ladattu kuva on.

Load(Stream)

Lataa uusi kuva määritellystä virtauksesta.

public static Image Load(Stream stream)

Parameters

stream Stream

Virta ladata kuvan pois.

Returns

Image

Ladattu kuva on.

Examples

Tämä esimerkki osoittaa System.IO.Stream-objektien käytön olemassa olevan kuvan tiedoston lataamiseen

//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(Lähde: IColorPalette, IColorPalette)

Puhutaan, kun paletti muuttuu.

protected virtual void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

Vanha paletti on.

newPalette IColorPalette

Ja uusi paletti.

OnPaletteChanging(Lähde: IColorPalette, IColorPalette)

Puhutaan, kun paletti muuttuu.

protected virtual void OnPaletteChanging(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

Vanha paletti on.

newPalette IColorPalette

Ja uusi paletti.

ReleaseManagedResources()

Varmista, että hallitsemattomia resursseja ei ole vapautettu täällä, koska ne saattavat olla jo vapautettu.

protected override void ReleaseManagedResources()

RemoveMetadata()

Poistaa metatiedot.

public virtual void RemoveMetadata()

Resize(Sisä, sisä)

Käytetään oletusarvoa Aspose.Imaging.ResizeType.NearestNeighbourResample.

public void Resize(int newWidth, int newHeight)

Parameters

newWidth int

Ja uusi leveys.

newHeight int

Ja uusi korkeus.

Examples

Seuraava esimerkki osoittaa, miten metafyylin (WMF ja EMF) kierrätys.

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);
                                                                                  }
                                                                              }

Seuraava esimerkki näyttää, miten kierrättää SVG-kuva ja säästää se PNG:ään.

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, resizeTyppi)

ja kuvasta uudelleen.

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

Parameters

newWidth int

Ja uusi leveys.

newHeight int

Ja uusi korkeus.

resizeType ResizeType

Tyyppinen reissu.

Examples

Muokkaa EPS-kuva ja viedä se PNG-muodossa.

// 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());
                                                        }

Muokkaa kuvaa käyttämällä erityistä Resize-tyyppiä.

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");
                                                   }

Tämä esimerkki laittaa WMF-kuvan ja uudistaa sen käyttämällä erilaisia uudistusmenetelmiä.

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);
                                                                                        }

Tämä esimerkki kuvaa kuvan ja uudistaa sen käyttämällä erilaisia uudistamismenetelmiä.

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");
                                                                                     }

Tämä esimerkki laittaa rasterin kuvan ja uudistaa sen käyttämällä erilaisia uudistusmenetelmiä.

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");
                                                                                           }

Tämä esimerkki ladata monivuotisen ODG-kuvan ja resisoi sen käyttämällä erilaisia resisausmenetelmiä.

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());
                                                                                                   }

Segmenttimaski nopeuttaa segmentointiprosessia

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

ja kuvasta uudelleen.

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

Parameters

newWidth int

Ja uusi leveys.

newHeight int

Ja uusi korkeus.

settings ImageResizeSettings

Siirretään uudelleen asetukset.

Examples

Muokkaa kuvaa käyttämällä erityistä Resize-tyyppiä.

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");
                                                   }

EPS-kuvan palauttaminen edistyneiden asetusten avulla.

// 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());
                                                    }

Tämä esimerkki ladata kuvan ja uudistaa sen käyttämällä erilaisia uudelleen asetuksia.

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(Sisältää)

Käytetään oletusarvoa Aspose.Imaging.ResizeType.NearestNeighbourResample.

public void ResizeHeightProportionally(int newHeight)

Parameters

newHeight int

Ja uusi korkeus.

ResizeHeightProportionally(Tyyppi, ResizeTyppi)

Vähennä korkeutta suhteellisesti.

public virtual void ResizeHeightProportionally(int newHeight, ResizeType resizeType)

Parameters

newHeight int

Ja uusi korkeus.

resizeType ResizeType

Tyyppinen reissu.

Examples

Tämä esimerkki kuvaa ja uudistaa sen suhteellisesti eri uudistamismenetelmien avulla. Vain korkeus määritetään, leveys lasketaan automaattisesti.

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");
                                                                                                                                                                         }

Segmenttimaski nopeuttaa segmentointiprosessia

// 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(Ilmoittautuminen, ImageResizeSettings)

Vähennä korkeutta suhteellisesti.

public virtual void ResizeHeightProportionally(int newHeight, ImageResizeSettings settings)

Parameters

newHeight int

Ja uusi korkeus.

settings ImageResizeSettings

Kuvassa uudistetaan asetuksia.

ResizeWidthProportionally(Sisältää)

Käytetään oletusarvoa Aspose.Imaging.ResizeType.NearestNeighbourResample.

public void ResizeWidthProportionally(int newWidth)

Parameters

newWidth int

Ja uusi leveys.

ResizeWidthProportionally(Tyyppi, ResizeTyppi)

Vähennä leveyttä suhteellisesti.

public virtual void ResizeWidthProportionally(int newWidth, ResizeType resizeType)

Parameters

newWidth int

Ja uusi leveys.

resizeType ResizeType

Tyyppinen reissu.

Examples

Tämä esimerkki kuvaa ja uudistaa sen suhteellisesti eri uudistamismenetelmien avulla. Vain leveys määritetään, korkeus lasketaan automaattisesti.

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(Ilmoittautuminen, ImageResizeSettings)

Vähennä leveyttä suhteellisesti.

public virtual void ResizeWidthProportionally(int newWidth, ImageResizeSettings settings)

Parameters

newWidth int

Ja uusi leveys.

settings ImageResizeSettings

Kuvassa uudistetaan asetuksia.

Rotate(Flottaa)

Kuvia kierrätetään keskustan ympärillä.

public virtual void Rotate(float angle)

Parameters

angle float

Kiertävä kulma asteina. Positiiviset arvot kiertävät kelloa.

RotateFlip(RotateFlipType)

Pyöri, flips, tai pyöri ja flips kuvan.

public abstract void RotateFlip(RotateFlipType rotateFlipType)

Parameters

rotateFlipType RotateFlipType

Tyyppi pyöristetty flip.

Examples

Esimerkki ladata olemassa olevan kuvan tiedoston jostakin levyn sijainnista ja suorittaa Rotate-operaation kuvalla 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();
                                                                                                                                                                                                                                                       }

Tämä esimerkki ladata kuvan, pyörittää sen 90 astetta kelloa ja valinnaisesti flips kuvaa horisontaalisesti ja/tai pystysuoraan.

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");
                                                                                                                                              }
                                                                                                                                          }

Tämä esimerkki kuvaa ODG-kuvaa, kääntää sen 90 astetta kelloa ja valinnaisesti ohjaa kuvan horisontaalisesti ja/tai pystysuoraan.

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

Tallentaa kuvan tiedot pohjavirtaukseen.

public override sealed void Save()

Examples

Seuraava esimerkki näyttää, miten tallentaa kokonainen BMP-kuva tai osa siitä tiedostoon tai virtaukseen.

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

Tallenna kuvan määritellylle tiedoston sijainnille.

public override void Save(string filePath)

Parameters

filePath string

Tiedoston reitti tallentaa kuvan.

Save(Vinkki, ImageOptionsBase)

Tallenna kohteen tiedot määritellyn tiedoston sijaintiin määritellyssä tiedostomuodossa tallennusvaihtoehtojen mukaisesti.

public virtual void Save(string filePath, ImageOptionsBase options)

Parameters

filePath string

Ja tiedoston reitti.

options ImageOptionsBase

ja vaihtoehtoja.

Examples

Seuraava esimerkki ladata BMP-kuvan tiedostosta, sitten tallentaa kuvan PNG-tiedostoon.

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);
                                                                                                   }

Tämä esimerkki näyttää yksinkertaiset askeleet Kuvan tallentamiseen.Tämän toiminnan osoittamiseksi ladataan olemassa oleva tiedosto jostakin levyn sijainnista, suoritetaan kuvan kierrätysoperaatio ja tallennetaan kuva PSD-muodossa File Pathin avulla.

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());
                                                                                                                                                                                                                                         }

Seuraava esimerkki näyttää, miten tallentaa kokonainen BMP-kuva tai osa siitä tiedostoon tai virtaukseen.

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(valot, ImageOptionsBase, Rectangle)

Tallenna kohteen tiedot määritellyn tiedoston sijaintiin määritellyssä tiedostomuodossa tallennusvaihtoehtojen mukaisesti.

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

Parameters

filePath string

Ja tiedoston reitti.

options ImageOptionsBase

ja vaihtoehtoja.

boundsRectangle Rectangle

Kohde-kuva rajoittaa oikea kulma. Aseta tyhjä oikea kulma käyttää lähde rajoja.

Examples

Seuraava esimerkki ladata BMP-kuvan tiedostosta, sitten tallentaa oikea osa kuvaa PNG-tiedostoon.

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);
                                                                                                                         }

Seuraava esimerkki näyttää, miten tallentaa kokonainen BMP-kuva tai osa siitä tiedostoon tai virtaukseen.

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

Vaihtoehtoja

ImageSaveException

Kuvien säästö epäonnistui.

Save(Liikenne, ImageOptionsBase)

Tallenna kuvan tiedot määritellylle virtaukselle määritellyssä tiedostomuodossa tallennusvaihtoehtojen mukaisesti.

public void Save(Stream stream, ImageOptionsBase optionsBase)

Parameters

stream Stream

Virta tallentaa kuvan tiedot.

optionsBase ImageOptionsBase

säästämisvaihtoehtoja.

Examples

Seuraava esimerkki ladata kuvan tiedostosta ja tallentaa sen sitten PNG-tiedoston virtaukseen.

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);
                                                                                                           }
                                                                                                       }

Tässä esimerkissä näytetään kuvan tallentamisen prosessi MemoryStreamille.Tämän toiminnan osoittamiseksi esimerkiksi ladataan olemassa oleva tiedosto jostakin levyn sijainnista, suoritetaan kuvaan kiertävä toiminta ja tallennetaan kuvaa PSD-muodossa.

//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());
                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                            }

Seuraava esimerkki näyttää, miten tallentaa kokonainen BMP-kuva tai osa siitä tiedostoon tai virtaukseen.

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

vaihtoehtoja

ArgumentException

Määritettyä muotoa ei voi tallentaa, koska sitä ei tällä hetkellä tueta; vaihtoehtojaBase

ImageSaveException

Kuvien vienti epäonnistui.

Save(Virtaa, ImageOptionsBase, Rectangle)

Tallenna kuvan tiedot määritellylle virtaukselle määritellyssä tiedostomuodossa tallennusvaihtoehtojen mukaisesti.

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

Parameters

stream Stream

Virta tallentaa kuvan tiedot.

optionsBase ImageOptionsBase

säästämisvaihtoehtoja.

boundsRectangle Rectangle

Kohde-kuva rajoittaa oikea kulma. Aseta tyhjä oikea kulma käyttämään lähde rajoja.

Examples

Seuraava esimerkki ladata kuvan tiedostosta, sitten tallentaa oikea osa kuvaa PNG-tiedoston virtaan.

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);
                                                                                                                                 }
                                                                                                                             }

Seuraava esimerkki näyttää, miten tallentaa kokonainen BMP-kuva tai osa siitä tiedostoon tai virtaukseen.

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

vaihtoehtoja

ArgumentException

Määritettyä muotoa ei voi tallentaa, koska sitä ei tällä hetkellä tueta; vaihtoehtojaBase

ImageSaveException

Kuvien vienti epäonnistui.

SetPalette(IkolorPalette ja Bool)

Aseta kuvan paletti.

public abstract void SetPalette(IColorPalette palette, bool updateColors)

Parameters

palette IColorPalette

Paletti on asetettu.

updateColors bool

jos “todellinen” väri päivitetään uuden paletin mukaan; muuten väriindeksit pysyvät muuttumattomina. Huomaa, että muuttumattomat indeksit voivat rikkoa kuvan latauksessa, jos joillakin indeksit eivät ole vastaavia paletin tuloksia.

UpdateContainer(Image)

Päivitetään säiliö.

protected void UpdateContainer(Image container)

Parameters

container Image

Se on konteineria.

Katso myös

DataStreamSupporter , IObjectWithBounds

 Suomi