Class Image

Class Image

Το όνομα: Aspose.Imaging Συγκέντρωση: Aspose.Imaging.dll (25.4.0)

Η εικόνα είναι η βασική τάξη για όλους τους τύπους εικόνων.

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

Inheritance

object DisposableObject DataStreamSupporter Image

Derived

RasterImage , VectorImage

Implements

IDisposable , IObjectWithBounds

Κληρονομημένα μέλη

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

Προσδιορίστε αν η παλέτα χρησιμοποιείται από την εικόνα.

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

Ανακαλύψτε την εικόνα χρησιμοποιώντας ένα συγκεκριμένο τύπο ανακαλύψεως.

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

Αυτό το παράδειγμα δημιουργεί ένα νέο αρχείο εικόνας σε κάποια τοποθεσία δίσκου, όπως ορίζεται από την ιδιοκτησία πηγής της παραδείγματος BmpOptions. Πολλές ιδιοκτησίες για την παραδείγματος BmpOptions ρυθμίζονται πριν από τη δημιουργία της πραγματικής εικόνας. Ειδικά η ιδιοκτησία πηγής, η οποία αναφέρεται στην πραγματική τοποθεσία δίσκου σε αυτή την περίπτωση.

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

Αρχίζει μια νέα περίπτωση της κατηγορίας Aspose.Imaging.Image.

[JsonConstructor]
protected Image()

Image(ΙΚΟΛΟΡΦΙΑ)

Αρχίζει μια νέα περίπτωση της κατηγορίας Aspose.Imaging.Image.

protected Image(IColorPalette colorPalette)

Parameters

colorPalette IColorPalette

Το χρώμα της παλέτας.

Properties

AutoAdjustPalette

Αποκτά ή καθορίζει μια τιμή που υποδεικνύει εάν η αυτόματη προσαρμογή παλέτας.

public bool AutoAdjustPalette { get; set; }

Αξία ιδιοκτησίας

bool

BackgroundColor

Αποκτά ή καθορίζει μια τιμή για το χρώμα του φόντου.

public virtual Color BackgroundColor { get; set; }

Αξία ιδιοκτησίας

Color

BitsPerPixel

Αποκτά τα bits της εικόνας ανά αριθμό pixel.

public abstract int BitsPerPixel { get; }

Αξία ιδιοκτησίας

int

Bounds

Πάρτε τα όρια της εικόνας.

public Rectangle Bounds { get; }

Αξία ιδιοκτησίας

Rectangle

BufferSizeHint

Αποκτά ή καθορίζει το μέγεθος μπουφέ που καθορίζεται μέγεθος μέγιστο επιτρεπόμενο για όλα τα εσωτερικά μπουφέ.

public int BufferSizeHint { get; set; }

Αξία ιδιοκτησίας

int

Container

Αποκτήστε το Aspose.Imaging.Image container.

public Image Container { get; }

Αξία ιδιοκτησίας

Image

Remarks

Εάν αυτή η ιδιοκτησία δεν είναι μηδενική, υποδεικνύει ότι η εικόνα περιέχεται μέσα σε άλλη εικόνα.

FileFormat

Αποκτά αξία της μορφής αρχείων

public virtual FileFormat FileFormat { get; }

Αξία ιδιοκτησίας

FileFormat

HasBackgroundColor

Αποκτά ή τοποθετεί μια τιμή που υποδεικνύει εάν η εικόνα έχει χρώμα φόντου.

public virtual bool HasBackgroundColor { get; set; }

Αξία ιδιοκτησίας

bool

Height

Πάρτε το ύψος της εικόνας.

public abstract int Height { get; }

Αξία ιδιοκτησίας

int

InterruptMonitor

Αποκτά ή τοποθετεί τη διακοπή οθόνης.

public InterruptMonitor InterruptMonitor { get; set; }

Αξία ιδιοκτησίας

InterruptMonitor

Palette

Η παλέτα χρώματος δεν χρησιμοποιείται όταν τα pixels αντιπροσωπεύονται απευθείας.

public IColorPalette Palette { get; set; }

Αξία ιδιοκτησίας

IColorPalette

Size

Πάρτε το μέγεθος της εικόνας.

public Size Size { get; }

Αξία ιδιοκτησίας

Size

Examples

Αυτό το παράδειγμα δείχνει πώς να φορτώσετε μια εικόνα DJVU από μια ροή αρχείων και να εκτυπώσετε πληροφορίες σχετικά με τις σελίδες.

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

Αποκτά μια τιμή που υποδεικνύει εάν χρησιμοποιείται η παλέτα εικόνας.

public virtual bool UsePalette { get; }

Αξία ιδιοκτησίας

bool

Examples

Προσδιορίστε αν η παλέτα χρησιμοποιείται από την εικόνα.

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

Width

Πάρτε το πλάτος της εικόνας.

public abstract int Width { get; }

Αξία ιδιοκτησίας

int

Methods

CanLoad(Σύνδεσμος)

Προσδιορίζει αν η εικόνα μπορεί να φορτωθεί από την καθορισμένη διαδρομή αρχείου.

public static bool CanLoad(string filePath)

Parameters

filePath string

Ο δρόμος του αρχείου.

Returns

bool

«πραγματικό» αν η εικόνα μπορεί να φορτωθεί από το καθορισμένο αρχείο, αλλιώς, «ψεύτικο».

Examples

Αυτό το παράδειγμα καθορίζει αν η εικόνα μπορεί να φορτωθεί από ένα αρχείο.

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

CanLoad(Σύνδεσμος, LoadOptions)

Προσδιορίζει αν η εικόνα μπορεί να φορτωθεί από την καθορισμένη διαδρομή αρχείου και προαιρετικά χρησιμοποιώντας τις καθορισμένες ανοικτές επιλογές.

public static bool CanLoad(string filePath, LoadOptions loadOptions)

Parameters

filePath string

Ο δρόμος του αρχείου.

loadOptions LoadOptions

Οι επιλογές φορτίου.

Returns

bool

«πραγματικό» αν η εικόνα μπορεί να φορτωθεί από το καθορισμένο αρχείο, αλλιώς, «ψεύτικο».

CanLoad(Stream)

Προσδιορίζει αν η εικόνα μπορεί να φορτωθεί από την καθορισμένη ροή.

public static bool CanLoad(Stream stream)

Parameters

stream Stream

Το ρεύμα για να φορτίσει.

Returns

bool

«πραγματικό» αν η εικόνα μπορεί να φορτωθεί από την καθορισμένη ροή, αλλιώς, «ψεύτικο».

Examples

Αυτό το παράδειγμα καθορίζει αν η εικόνα μπορεί να φορτωθεί από μια ροή αρχείων.

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(Σύνδεση, LoadOptions)

Προσδιορίζει αν η εικόνα μπορεί να φορτωθεί από το καθορισμένο ρεύμα και προαιρετικά χρησιμοποιώντας το καθορισμένο loadOptions'.

public static bool CanLoad(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

Το ρεύμα για να φορτίσει.

loadOptions LoadOptions

Οι επιλογές φορτίου.

Returns

bool

«πραγματικό» αν η εικόνα μπορεί να φορτωθεί από την καθορισμένη ροή, αλλιώς, «ψεύτικο».

CanSave(ImageOptionsBase)

Προσδιορίζει αν η εικόνα μπορεί να αποθηκευτεί στην καθορισμένη μορφή αρχείου που αντιπροσωπεύεται από τις επιλογές αποθήκευσης που έχουν περάσει.

public bool CanSave(ImageOptionsBase options)

Parameters

options ImageOptionsBase

Οι επιλογές αποθήκευσης για χρήση.

Returns

bool

“πραγματικό” αν η εικόνα μπορεί να αποθηκευτεί στην καθορισμένη μορφή αρχείου που αντιπροσωπεύεται από τις παρελθόντες επιλογές αποθήκευσης.

Examples

Αυτό το παράδειγμα δείχνει πώς να προσδιορίσετε αν η εικόνα μπορεί να αποθηκευτεί στην καθορισμένη μορφή αρχείου που αντιπροσωπεύεται από τις προηγούμενες επιλογές αποθήκευσης.

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(ΦωτογραφίεςBase, int, int)

Δημιουργεί μια νέα εικόνα χρησιμοποιώντας τις επιλογές δημιουργίας που καθορίζονται.

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

Parameters

imageOptions ImageOptionsBase

Οι επιλογές εικόνας.

width int

Το πλάτος .

height int

Το ύψος.

Returns

Image

Η νεοσύστατη εικόνα.

Examples

Αυτό το παράδειγμα δημιουργεί ένα νέο αρχείο εικόνας σε κάποια τοποθεσία δίσκου, όπως ορίζεται από την ιδιοκτησία πηγής της παραδείγματος BmpOptions. Πολλές ιδιοκτησίες για την παραδείγματος BmpOptions ρυθμίζονται πριν από τη δημιουργία της πραγματικής εικόνας. Ειδικά η ιδιοκτησία πηγής, η οποία αναφέρεται στην πραγματική τοποθεσία δίσκου σε αυτή την περίπτωση.

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

Δημιουργεί μια νέα εικόνα χρησιμοποιώντας τις προσδιορισμένες εικόνες ως σελίδες

public static Image Create(Image[] images)

Parameters

images Image [ ]

Οι εικόνες .

Returns

Image

Η εικόνα ως ImultipageImage

Create(MultipageCreateOptions)

Δημιουργεί την καθορισμένη πολλαπλή σελίδα δημιουργώντας επιλογές.

public static Image Create(MultipageCreateOptions multipageCreateOptions)

Parameters

multipageCreateOptions MultipageCreateOptions

Η πολλαπλή σελίδα δημιουργεί επιλογές.

Returns

Image

Η πολλαπλή εικόνα

Create(Σύνδεσμος[ ]Μπόλ)

Δημιουργεί την εικόνα πολλών σελίδων που περιέχει τα καθορισμένα αρχεία.

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

Parameters

files string [ ]

Τα αρχεία .

throwExceptionOnLoadError bool

Εάν ορίσετε το “πραγματικό” [να ρίξετε εξαίρεση στο σφάλμα φόρτωσης].

Returns

Image

Η πολλαπλή εικόνα

Create(Σύνδεσμος[])

Δημιουργεί την εικόνα πολλών σελίδων που περιέχει τα καθορισμένα αρχεία.

public static Image Create(string[] files)

Parameters

files string [ ]

Τα αρχεία .

Returns

Image

Η πολλαπλή εικόνα

Create(Image[ ]Μπόλ)

Δημιουργεί μια νέα εικόνα τις προσδιορισμένες εικόνες ως σελίδες.

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

Parameters

images Image [ ]

Οι εικόνες .

disposeImages bool

Εάν επιλέξετε «αληθινά» [διαθέστε εικόνες].

Returns

Image

Η εικόνα ως ImultipageImage

Crop(Rectangle)

Κρατήστε την καθορισμένη ορθογώνια.

public virtual void Crop(Rectangle rectangle)

Parameters

rectangle Rectangle

Η Ορθόδοξη.

Examples

Το παρακάτω παράδειγμα καλλιεργεί μια εικόνα ράστερ. Η περιοχή καλλιέργειας καθορίζεται μέσω του 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(Ιντ, Ιντ, Ιντ)

Φωτογραφία φυτών με αλλαγές.

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

Parameters

leftShift int

Η αριστερή αλλαγή.

rightShift int

Η σωστή αλλαγή.

topShift int

Η κορυφαία αλλαγή.

bottomShift int

Η κατώτερη αλλαγή.

Examples

Το παρακάτω παράδειγμα καλλιεργεί μια εικόνα ράστερ. Η περιοχή καλλιέργειας καθορίζεται μέσω των αριστερών, ανώτερων, δεξιών, κάτω περιθωρίων.

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)

Το μήνυμα δεν μπορεί να αποθηκευτεί.

protected virtual string GetCanNotSaveMessage(ImageOptionsBase optionsBase)

Parameters

optionsBase ImageOptionsBase

Οι επιλογές εικόνας.

Returns

string

Δεν μπορεί να αποθηκεύσει το μήνυμα.

GetDefaultOptions(αντικείμενο[])

Αποκτήστε τις προεπιλεγμένες επιλογές.

public virtual ImageOptionsBase GetDefaultOptions(object[] args)

Parameters

args object [ ]

Τα επιχειρήματα .

Returns

ImageOptionsBase

Προεπιλεγμένες επιλογές

GetFileFormat(Σύνδεσμος)

Πάρτε τη μορφή αρχείου.

public static FileFormat GetFileFormat(string filePath)

Parameters

filePath string

Ο δρόμος του αρχείου.

Returns

FileFormat

Η συγκεκριμένη μορφή αρχείου.

Examples

Αυτό το παράδειγμα δείχνει πώς να προσδιορίσετε τη μορφή εικόνας χωρίς να φορτώσετε ολόκληρη την εικόνα από ένα αρχείο.

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

Η καθορισμένη μορφή αρχείου δεν σημαίνει ότι η καθορισμένη εικόνα μπορεί να φορτωθεί. Χρησιμοποιήστε μία από τις μεταφορτώσεις μεθόδου CanLoad για να καθορίσετε εάν το αρχείο μπορεί να φορτωθεί.

GetFileFormat(Stream)

Πάρτε τη μορφή αρχείου.

public static FileFormat GetFileFormat(Stream stream)

Parameters

stream Stream

Το ρεύμα.

Returns

FileFormat

Η συγκεκριμένη μορφή αρχείου.

Examples

Αυτό το παράδειγμα δείχνει πώς να προσδιορίσετε τη μορφή εικόνας χωρίς να φορτώσετε ολόκληρη την εικόνα από μια ροή αρχείων.

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

Η καθορισμένη μορφή αρχείου δεν σημαίνει ότι η καθορισμένη εικόνα μπορεί να φορτωθεί. Χρησιμοποιήστε μία από τις μεταφορτώσεις μεθόδου CanLoad για να καθορίσετε εάν η ροή μπορεί να φορτωθεί.

GetFitRectangle(Rectangle)

Έχει μια ορθογώνια που ταιριάζει στην τρέχουσα εικόνα.

protected Rectangle GetFitRectangle(Rectangle rectangle)

Parameters

rectangle Rectangle

Η ορθογώνια για να πάρει κατάλληλη ορθογώνια.

Returns

Rectangle

Η σωστή ορθογώνια

GetFitRectangle(ΠΕΡΙΣΣΣΟΤΕΡΑ, INT[])

Κάντε μια ορθογώνια που ταιριάζει στο τρέχον bitmap λαμβάνοντας υπόψη τα περασμένα pixels. Ο αριθμός των περασμένων pixels θα πρέπει να είναι ίση με το μέγεθος της ορθογώνης που ταιριάζει.

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

Parameters

rectangle Rectangle

Η ορθογώνια για να πάρει κατάλληλη ορθογώνια.

pixels int [ ]

Τα 32-bit ARGB pixels είναι διαθέσιμα.

Returns

Rectangle

Η σωστή ορθογώνια.

GetFittingRectangle(Πλαίσιο, int, int)

Έχει μια ορθογώνια που ταιριάζει στην τρέχουσα εικόνα.

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

Parameters

rectangle Rectangle

Η ορθογώνια για να πάρει κατάλληλη ορθογώνια.

width int

Το πλάτος του αντικειμένου.

height int

Το ύψος του αντικειμένου.

Returns

Rectangle

Η ορθογώνια ή η εξαίρεση εάν δεν υπάρχει ορθογώνιος ορθογώνιος.

GetFittingRectangle(ΠΕΡΙΣΣΣΟΤΕΡΑ, INT[ ]Ιντ, Ιντ)

Έχει μια ορθογώνια που ταιριάζει στην τρέχουσα εικόνα.

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

Parameters

rectangle Rectangle

Η ορθογώνια για να πάρει κατάλληλη ορθογώνια.

pixels int [ ]

Τα 32-bit ARGB pixels

width int

Το πλάτος του αντικειμένου.

height int

Το ύψος του αντικειμένου.

Returns

Rectangle

Η ορθογώνια ή η εξαίρεση εάν δεν υπάρχει ορθογώνιος ορθογώνιος.

GetImage2Export(ImageOptionsBase, Rectangle, IImageΕξαγωγέας)

Πάρτε την εικόνα για εξαγωγή.

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

Parameters

optionsBase ImageOptionsBase

Η βάση των επιλογών εικόνας.

boundsRectangle Rectangle

Τα όρια είναι ορθογώνια.

exporter IImageExporter

Ο εξαγωγέας

Returns

Image

Η εικόνα για την εξαγωγή

GetOriginalOptions()

Αποκτά τις επιλογές με βάση τις αρχικές ρυθμίσεις αρχείου.Αυτό μπορεί να είναι χρήσιμο για τη διατήρηση του βάθους του bit και άλλων παραμέτρων της αρχικής εικόνας αμετάβλητη.Για παράδειγμα, αν φορτώσουμε μια μαύρη-λευκή εικόνα PNG με 1 bit ανά pixel και στη συνέχεια την αποθηκεύουμε χρησιμοποιώντας τοΜε τη μέθοδο Aspose.Imaging.DataStreamSupporter.Save(System.String), θα παράγεται η εικόνα PNG εξόδου με 8 bit ανά pixel.Για να αποφύγετε αυτό και να αποθηκεύσετε την εικόνα PNG με 1 bit ανά pixel, χρησιμοποιήστε αυτή τη μέθοδο για να πάρετε τις αντίστοιχες επιλογές αποθήκευσης και να τις περάσετεΗ μέθοδος Aspose.Imaging.Image.Save (System.String,Aspose.Imaging.ImageOptionsBase) είναι η δεύτερη παράμετρος.

public virtual ImageOptionsBase GetOriginalOptions()

Returns

ImageOptionsBase

Οι επιλογές βασίζονται στις αρχικές ρυθμίσεις αρχείου.

GetProportionalHeight(Ιντ, Ιντ, Ιντ)

Έχει αναλογικό ύψος.

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

Parameters

width int

Το πλάτος .

height int

Το ύψος.

newWidth int

Το νέο πλάτος.

Returns

int

Το αναλογικό ύψος.

GetProportionalWidth(Ιντ, Ιντ, Ιντ)

Έχει αναλογικό πλάτος.

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

Parameters

width int

Το πλάτος .

height int

Το ύψος.

newHeight int

Το νέο ύψος.

Returns

int

Το αναλογικό πλάτος.

GetSerializedStream(ImageOptionsBase, Rectangle, out int)

Μετατρέπονται σε APS.

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

Parameters

imageOptions ImageOptionsBase

Οι επιλογές εικόνας.

clippingRectangle Rectangle

Η ορθογώνια κλίμακα.

pageNumber int

Ο αριθμός της σελίδας.

Returns

Stream

Η Σειριωμένη Ακτινοβολία

Load(Σύνδεσμος, LoadOptions)

Κατεβάζει μια νέα εικόνα από την καθορισμένη διαδρομή αρχείου ή URL.Εάν το filePath’ είναι μια διαδρομή αρχείου, η μέθοδος ανοίγει μόνο το αρχείο.Εάν το filePath’ είναι μια URL, η μέθοδος κατεβάζει το αρχείο, το αποθηκεύει ως προσωρινό και το ανοίγει.

public static Image Load(string filePath, LoadOptions loadOptions)

Parameters

filePath string

Η διαδρομή αρχείου ή το URL για να φορτώσετε την εικόνα από.

loadOptions LoadOptions

Οι επιλογές φορτίου.

Returns

Image

Η φορτισμένη εικόνα.

Load(Σύνδεσμος)

Κατεβάζει μια νέα εικόνα από την καθορισμένη διαδρομή αρχείου ή URL.Εάν το filePath’ είναι μια διαδρομή αρχείου, η μέθοδος ανοίγει μόνο το αρχείο.Εάν το filePath’ είναι μια URL, η μέθοδος κατεβάζει το αρχείο, το αποθηκεύει ως προσωρινό και το ανοίγει.

public static Image Load(string filePath)

Parameters

filePath string

Η διαδρομή αρχείου ή το URL για να φορτώσετε την εικόνα από.

Returns

Image

Η φορτισμένη εικόνα.

Examples

Αυτό το παράδειγμα αποδεικνύει την φόρτωση ενός υπάρχοντος αρχείου εικόνας σε ένα παράδειγμα Aspose.Imaging.Image χρησιμοποιώντας τη διαδρομή αρχείου που καθορίζεται

//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(Σύνδεση, LoadOptions)

Κατεβάστε μια νέα εικόνα από την καθορισμένη ροή.

public static Image Load(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

Η ροή για να φορτίσει την εικόνα από.

loadOptions LoadOptions

Οι επιλογές φορτίου.

Returns

Image

Η φορτισμένη εικόνα.

Load(Stream)

Κατεβάστε μια νέα εικόνα από την καθορισμένη ροή.

public static Image Load(Stream stream)

Parameters

stream Stream

Η ροή για να φορτίσει την εικόνα από.

Returns

Image

Η φορτισμένη εικόνα.

Examples

Αυτό το παράδειγμα αποδεικνύει τη χρήση των αντικειμένων System.IO.Stream για να φορτώσετε ένα υπάρχον αρχείο εικόνας

//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(Ετικέτες IColor, IColorPalette)

Ονομάζεται όταν αλλάζει παλέτα.

protected virtual void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

Η παλιά παλέτα.

newPalette IColorPalette

Η νέα παλέτα.

OnPaletteChanging(Ετικέτες IColor, IColorPalette)

Ονομάζεται όταν αλλάζει παλέτα.

protected virtual void OnPaletteChanging(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

Η παλιά παλέτα.

newPalette IColorPalette

Η νέα παλέτα.

ReleaseManagedResources()

Απελευθερώστε τους διαχειριζόμενους πόρους. Βεβαιωθείτε ότι δεν απελευθερώνονται εδώ μη διαχειριζόμενοι πόροι, καθώς μπορεί να έχουν ήδη απελευθερωθεί.

protected override void ReleaseManagedResources()

RemoveMetadata()

Απομακρύνει τα μεταδεδομένα.

public virtual void RemoveMetadata()

Resize(ΕΝΤ, ΕΝΤ)

Το προεπιλεγμένο Aspose.Imaging.ResizeType.NearestNeighbourResample χρησιμοποιείται.

public void Resize(int newWidth, int newHeight)

Parameters

newWidth int

Το νέο πλάτος.

newHeight int

Το νέο ύψος.

Examples

Το παρακάτω παράδειγμα δείχνει πώς να αναζωογονήσει ένα μεταφίλ (WMF και EMF).

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

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

Το παρακάτω παράδειγμα δείχνει πώς να αναδιαμορφώσετε την εικόνα SVG και να την αποθηκεύσετε στο PNG.

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

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

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

Resize(ΠΕΡΙΣΣΟΤΕΡΑ, ΕΠΙΧΕΙΡΗΣΗ)

Αναζωογονεί την εικόνα.

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

Parameters

newWidth int

Το νέο πλάτος.

newHeight int

Το νέο ύψος.

resizeType ResizeType

Ο τύπος αναζωογόνησης.

Examples

Επαναλάβετε την εικόνα EPS και την εξάγετε σε μορφή PNG.

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

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

Ανακαλύψτε την εικόνα χρησιμοποιώντας ένα συγκεκριμένο τύπο ανακαλύψεως.

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

Αυτό το παράδειγμα φορτώνει μια εικόνα του WMF και την αναζωογονεί χρησιμοποιώντας διάφορες μεθόδους αναζωογόνησης.

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

Αυτό το παράδειγμα φορτώνει μια εικόνα και την αναζωογονεί χρησιμοποιώντας διάφορες μεθόδους αναζωογόνησης.

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

Αυτό το παράδειγμα φορτώνει μια εικόνα ράστερ και την αναζωογονεί χρησιμοποιώντας διάφορες μεθόδους αναζωογόνησης.

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

Αυτό το παράδειγμα φορτώνει μια εικόνα ODG πολλαπλών σελίδων και την αναζωογονεί χρησιμοποιώντας διάφορες μεθόδους αναζωογόνησης.

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

Χρησιμοποιήστε μια μάσκα τμήματος για να επιταχυνθεί η διαδικασία του τμήματος

// 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, ImageResizeΕπεξεργασία)

Αναζωογονεί την εικόνα.

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

Parameters

newWidth int

Το νέο πλάτος.

newHeight int

Το νέο ύψος.

settings ImageResizeSettings

Η αναδιάρθρωση των ρυθμίσεων.

Examples

Ανακαλύψτε την εικόνα χρησιμοποιώντας ένα συγκεκριμένο τύπο ανακαλύψεως.

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 χρησιμοποιώντας προηγμένες ρυθμίσεις.

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

Αυτό το παράδειγμα φορτώνει μια εικόνα και την αναθεωρεί χρησιμοποιώντας διάφορες ρυθμίσεις αναθεώρησης.

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(ΕΝΤ)

Χρησιμοποιείται το προεπιλεγμένο Aspose.Imaging.ResizeType.NearestNeighbourResample.

public void ResizeHeightProportionally(int newHeight)

Parameters

newHeight int

Το νέο ύψος.

ResizeHeightProportionally(ΠΕΡΙΣΣΟΤΕΡΑ, ΑΝΑΚΟΙΝΩΣΗ)

Ανακατέψτε το ύψος αναλογικά.

public virtual void ResizeHeightProportionally(int newHeight, ResizeType resizeType)

Parameters

newHeight int

Το νέο ύψος.

resizeType ResizeType

Τύπος της αναζωογόνησης.

Examples

Αυτό το παράδειγμα φορτώνει μια εικόνα και την αναζωογονεί αναλογικά χρησιμοποιώντας διάφορες μεθόδους αναζωογονόμησης. μόνο το ύψος καθορίζεται, το πλάτος υπολογίζεται αυτόματα.

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

Χρησιμοποιήστε μια μάσκα τμήματος για να επιταχυνθεί η διαδικασία του τμήματος

// 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(Φωτογραφία, ImageResizeSettings)

Ανακατέψτε το ύψος αναλογικά.

public virtual void ResizeHeightProportionally(int newHeight, ImageResizeSettings settings)

Parameters

newHeight int

Το νέο ύψος.

settings ImageResizeSettings

Η εικόνα επαναφέρει τις ρυθμίσεις.

ResizeWidthProportionally(ΕΝΤ)

Χρησιμοποιείται το προεπιλεγμένο Aspose.Imaging.ResizeType.NearestNeighbourResample.

public void ResizeWidthProportionally(int newWidth)

Parameters

newWidth int

Το νέο πλάτος.

ResizeWidthProportionally(ΠΕΡΙΣΣΟΤΕΡΑ, ΑΝΑΚΟΙΝΩΣΗ)

Ανακατέψτε το πλάτος αναλογικά.

public virtual void ResizeWidthProportionally(int newWidth, ResizeType resizeType)

Parameters

newWidth int

Το νέο πλάτος.

resizeType ResizeType

Τύπος της αναζωογόνησης.

Examples

Αυτό το παράδειγμα φορτώνει μια εικόνα και την αναζωογονεί αναλογικά χρησιμοποιώντας διάφορες μεθόδους αναζωογονόμησης. μόνο το πλάτος καθορίζεται, το ύψος υπολογίζεται αυτόματα.

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(Φωτογραφία, ImageResizeSettings)

Ανακατέψτε το πλάτος αναλογικά.

public virtual void ResizeWidthProportionally(int newWidth, ImageResizeSettings settings)

Parameters

newWidth int

Το νέο πλάτος.

settings ImageResizeSettings

Η εικόνα επαναφέρει τις ρυθμίσεις.

Rotate(Πλοία)

Ρυθμίστε την εικόνα γύρω από το κέντρο.

public virtual void Rotate(float angle)

Parameters

angle float

Η γωνία περιστροφής σε βαθμούς. θετικές τιμές θα περιστρέφονται με το ρολόι.

RotateFlip(RotateFlipType)

Γυρίζει, γυρίζει ή γυρίζει και γυρίζει την εικόνα.

public abstract void RotateFlip(RotateFlipType rotateFlipType)

Parameters

rotateFlipType RotateFlipType

Τύπος του περιστρεφόμενου flip.

Examples

Το παράδειγμα φορτώνει ένα υπάρχον αρχείο εικόνας από κάποια θέση δίσκου και εκτελεί τη λειτουργία Rotate στην εικόνα σύμφωνα με την τιμή του 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();
                                                                                                                                                                                                                                                       }

Αυτό το παράδειγμα φορτώνει μια εικόνα, την περιστρέφει κατά 90 μοίρες και προαιρετικά χτυπά την εικόνα οριζόντια και/ή κάθετα.

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

Αυτό το παράδειγμα φορτίζει μια εικόνα ODG, την περιστρέφει κατά 90 μοίρες και προαιρετικά χτυπά την εικόνα οριζόντια και (ή) κάθετα.

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

Αποθηκεύει τα δεδομένα εικόνας στην υποκείμενη ροή.

public override sealed void Save()

Examples

Το παρακάτω παράδειγμα δείχνει πώς να αποθηκεύσετε μια ενσωματωμένη εικόνα BMP ή μέρος της σε ένα αρχείο ή ροή.

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(Σύνδεσμος)

Αποθηκεύει την εικόνα στην καθορισμένη τοποθεσία αρχείου.

public override void Save(string filePath)

Parameters

filePath string

Η διαδρομή αρχείου για να αποθηκεύσετε την εικόνα.

Save(Σύνδεσμος, ImageOptionsBase)

Αποθηκεύει τα δεδομένα του αντικειμένου στην καθορισμένη τοποθεσία αρχείου στην καθορισμένη μορφή αρχείου σύμφωνα με τις επιλογές αποθήκευσης.

public virtual void Save(string filePath, ImageOptionsBase options)

Parameters

filePath string

Ο δρόμος του αρχείου.

options ImageOptionsBase

Οι επιλογές .

Examples

Το παρακάτω παράδειγμα φορτώνει μια εικόνα BMP από ένα αρχείο και στη συνέχεια αποθηκεύει την εικόνα σε ένα αρχείο PNG.

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

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

Αυτό το παράδειγμα δείχνει τα απλά βήματα για να αποθηκεύσετε μια εικόνα.Για να αποδείξετε αυτή τη λειτουργία, φορτώνουμε ένα υπάρχον αρχείο από κάποια τοποθεσία δίσκου, εκτελεί τη λειτουργία Ρυθμίστε την εικόνα και αποθηκεύστε την εικόνα σε μορφή PSD χρησιμοποιώντας το File Path

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

Το παρακάτω παράδειγμα δείχνει πώς να αποθηκεύσετε μια ενσωματωμένη εικόνα BMP ή μέρος της σε ένα αρχείο ή ροή.

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(Σύνδεσμος, ImageOptionsBase, Rectangle)

Αποθηκεύει τα δεδομένα του αντικειμένου στην καθορισμένη τοποθεσία αρχείου στην καθορισμένη μορφή αρχείου σύμφωνα με τις επιλογές αποθήκευσης.

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

Parameters

filePath string

Ο δρόμος του αρχείου.

options ImageOptionsBase

Οι επιλογές .

boundsRectangle Rectangle

Η εικόνα προορισμού περιορίζει την ορθογώνια. Ρυθμίστε την κενή ορθογώνια για τη χρήση των ορίων πηγής.

Examples

Το παρακάτω παράδειγμα φορτώνει μια εικόνα BMP από ένα αρχείο, στη συνέχεια αποθηκεύει ένα ορθογώνιο μέρος της εικόνας σε ένα αρχείο PNG.

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

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

Το παρακάτω παράδειγμα δείχνει πώς να αποθηκεύσετε μια ενσωματωμένη εικόνα BMP ή μέρος της σε ένα αρχείο ή ροή.

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

Επιλογές

ImageSaveException

Η εξοικονόμηση εικόνας αποτύχει.

Save(Σύνδεση, ImageOptionsBase)

Αποθηκεύει τα δεδομένα της εικόνας στην καθορισμένη ροή στην καθορισμένη μορφή αρχείου σύμφωνα με τις επιλογές αποθήκευσης.

public void Save(Stream stream, ImageOptionsBase optionsBase)

Parameters

stream Stream

Η ροή για να αποθηκεύσετε τα δεδομένα της εικόνας σε.

optionsBase ImageOptionsBase

Οι επιλογές αποθήκευσης.

Examples

Το παρακάτω παράδειγμα φορτώνει μια εικόνα από ένα αρχείο και στη συνέχεια αποθηκεύει την εικόνα σε μια ροή αρχείου PNG.

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

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

Αυτό το παράδειγμα δείχνει τη διαδικασία αποθήκευσης μιας εικόνας στο MemoryStream. Για να αποδείξετε αυτή τη λειτουργία, το παράδειγμα φορτώνει ένα υπάρχον αρχείο από κάποια τοποθεσία δίσκου, εκτελεί τη λειτουργία Ρυθμίσεις στην εικόνα και Αποθήκευση της εικόνας σε μορφή PSD

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

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

Το παρακάτω παράδειγμα δείχνει πώς να αποθηκεύσετε μια ενσωματωμένη εικόνα BMP ή μέρος της σε ένα αρχείο ή ροή.

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

ΕΠΙΛΟΓΕΣ

ArgumentException

Δεν μπορείτε να αποθηκεύσετε στην καθορισμένη μορφή, καθώς δεν υποστηρίζεται αυτή τη στιγμή.

ImageSaveException

Η εξαγωγή εικόνας απέτυχε.

Save(Σύνδεση, ImageOptionsBase, Rectangle)

Αποθηκεύει τα δεδομένα της εικόνας στην καθορισμένη ροή στην καθορισμένη μορφή αρχείου σύμφωνα με τις επιλογές αποθήκευσης.

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

Parameters

stream Stream

Η ροή για να αποθηκεύσετε τα δεδομένα της εικόνας σε.

optionsBase ImageOptionsBase

Οι επιλογές αποθήκευσης.

boundsRectangle Rectangle

Η εικόνα προορισμού περιορίζει την ορθογώνια. Ρυθμίστε την κενή ορθογώνια για τη χρήση των ορίων πηγής.

Examples

Το παρακάτω παράδειγμα φορτώνει μια εικόνα από ένα αρχείο, στη συνέχεια αποθηκεύει ένα ορθογώνιο μέρος της εικόνας σε μια ροή αρχείου PNG.

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

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

Το παρακάτω παράδειγμα δείχνει πώς να αποθηκεύσετε μια ενσωματωμένη εικόνα BMP ή μέρος της σε ένα αρχείο ή ροή.

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

ΕΠΙΛΟΓΕΣ

ArgumentException

Δεν μπορείτε να αποθηκεύσετε στην καθορισμένη μορφή, καθώς δεν υποστηρίζεται αυτή τη στιγμή.

ImageSaveException

Η εξαγωγή εικόνας απέτυχε.

SetPalette(Πλατφόρμα, Bool)

Δημιουργήστε την παλέτα εικόνας.

public abstract void SetPalette(IColorPalette palette, bool updateColors)

Parameters

palette IColorPalette

Η παλέτα να καθοριστεί.

updateColors bool

εάν ρυθμιστεί σε “πραγματικά” χρώματα θα ενημερωθεί σύμφωνα με τη νέα παλέτα. διαφορετικά, οι δείκτες χρωμάτων παραμένουν αμετάβλητοι. σημειώστε ότι οι αμετάβλητοι δείκτες μπορεί να σπάσει την εικόνα στο φορτίο εάν ορισμένοι δείκτες δεν έχουν αντίστοιχες εισαγωγές παλέτας.

UpdateContainer(Image)

Ενημέρωση του εμπορευματικού.

protected void UpdateContainer(Image container)

Parameters

container Image

και το εμπορευματικό.

Δείτε επίσης

DataStreamSupporter , IObjectWithBounds

 Ελληνικά