Class Image

Class Image

Tên không gian: Aspose.Imaging Tổng hợp: Aspose.Imaging.dll (25.4.0)

Hình ảnh là lớp cơ bản cho tất cả các loại hình ảnh.

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

Inheritance

object DisposableObject DataStreamSupporter Image

Derived

RasterImage , VectorImage

Implements

IDisposable , IObjectWithBounds

Thành viên thừa kế

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

Quyết định xem liệu palette có được sử dụng bởi hình ảnh hay không.

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

Tạo lại hình ảnh bằng cách sử dụng kiểu Resize cụ thể.

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

Ví dụ này tạo một tệp hình ảnh mới ở một số vị trí đĩa như được xác định bởi tài sản nguồn của ví dụ BmpOptions. Một số tài chính cho ví dạng Bmppoptions được thiết lập trước khi tạo ra bức ảnh thực tế.

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

Bắt đầu một trường hợp mới của lớp Aspose.Imaging.Image.

[JsonConstructor]
protected Image()

Image(Đồ chơi ICOLOR)

Bắt đầu một trường hợp mới của lớp Aspose.Imaging.Image.

protected Image(IColorPalette colorPalette)

Parameters

colorPalette IColorPalette

Màu palet

Properties

AutoAdjustPalette

Nhận hoặc đặt một giá trị cho thấy liệu tự động điều chỉnh pallet.

public bool AutoAdjustPalette { get; set; }

Giá trị bất động sản

bool

BackgroundColor

Nhận hoặc đặt giá trị cho màu nền.

public virtual Color BackgroundColor { get; set; }

Giá trị bất động sản

Color

BitsPerPixel

Nhận bit hình ảnh theo số pixel.

public abstract int BitsPerPixel { get; }

Giá trị bất động sản

int

Bounds

Nhận được giới hạn hình ảnh.

public Rectangle Bounds { get; }

Giá trị bất động sản

Rectangle

BufferSizeHint

Nhận hoặc đặt dấu kích thước buffer mà được xác định kích thước tối đa cho phép cho tất cả các buffer nội bộ.

public int BufferSizeHint { get; set; }

Giá trị bất động sản

int

Container

Nhận Aspose.Imaging.Image container.

public Image Container { get; }

Giá trị bất động sản

Image

Remarks

Nếu tài sản này không có giá trị, nó chỉ ra rằng hình ảnh được chứa trong một hình ảnh khác.

FileFormat

Nhận giá trị của định dạng tệp

public virtual FileFormat FileFormat { get; }

Giá trị bất động sản

FileFormat

HasBackgroundColor

Nhận hoặc đặt một giá trị cho thấy liệu hình ảnh có màu nền hay không.

public virtual bool HasBackgroundColor { get; set; }

Giá trị bất động sản

bool

Height

Nhận được độ cao hình ảnh.

public abstract int Height { get; }

Giá trị bất động sản

int

InterruptMonitor

Nhận hoặc đặt màn hình bị gián đoạn.

public InterruptMonitor InterruptMonitor { get; set; }

Giá trị bất động sản

InterruptMonitor

Palette

Nhận hoặc đặt bảng màu. bảng màu không được sử dụng khi các pixel được trình bày trực tiếp.

public IColorPalette Palette { get; set; }

Giá trị bất động sản

IColorPalette

Size

Nhận kích thước hình ảnh.

public Size Size { get; }

Giá trị bất động sản

Size

Examples

Ví dụ này cho thấy cách tải một hình ảnh DJVU từ một dòng tệp và in thông tin về các trang.

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

Nhận được một giá trị cho thấy liệu bảng hình ảnh được sử dụng hay không.

public virtual bool UsePalette { get; }

Giá trị bất động sản

bool

Examples

Quyết định xem liệu palette có được sử dụng bởi hình ảnh hay không.

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

Width

Nhận được chiều rộng hình ảnh

public abstract int Width { get; }

Giá trị bất động sản

int

Methods

CanLoad(String)

Xác định xem hình ảnh có thể được tải từ con đường tệp cụ thể hay không.

public static bool CanLoad(string filePath)

Parameters

filePath string

đường file.

Returns

bool

’truyền’ nếu hình ảnh có thể được tải về từ tệp được chỉ định; nếu không, ’lầm'.

Examples

Ví dụ này xác định xem hình ảnh có thể được tải lên từ một tệp hay không.

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

CanLoad(LoadOptions, LoadOptions)

Nó xác định xem hình ảnh có thể được tải từ con đường tệp cụ thể và tùy chọn sử dụng các tùy chọn mở cụ thể.

public static bool CanLoad(string filePath, LoadOptions loadOptions)

Parameters

filePath string

đường file.

loadOptions LoadOptions

Các tùy chọn tải.

Returns

bool

’truyền’ nếu hình ảnh có thể được tải về từ tệp được chỉ định; nếu không, ’lầm'.

CanLoad(Stream)

Nó xác định xem hình ảnh có thể được tải từ dòng cụ thể hay không.

public static bool CanLoad(Stream stream)

Parameters

stream Stream

dòng chảy để tải từ.

Returns

bool

’truyền’ nếu hình ảnh có thể được tải về từ dòng được chỉ định; nếu không, ’lầm'.

Examples

Ví dụ này xác định xem hình ảnh có thể được tải từ một dòng tệp hay không.

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)

Nó xác định xem hình ảnh có thể được tải từ dòng cụ thể và tùy chọn sử dụng loadOptions".

public static bool CanLoad(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

dòng chảy để tải từ.

loadOptions LoadOptions

Các tùy chọn tải.

Returns

bool

’truyền’ nếu hình ảnh có thể được tải về từ dòng được chỉ định; nếu không, ’lầm'.

CanSave(ImageOptionsBase)

Nó xác định xem hình ảnh có thể được lưu vào định dạng tệp cụ thể được trình bày bởi các tùy chọn lưu trữ đã qua.

public bool CanSave(ImageOptionsBase options)

Parameters

options ImageOptionsBase

Các tùy chọn tiết kiệm để sử dụng.

Returns

bool

’truyền’ nếu hình ảnh có thể được lưu vào định dạng tệp cụ thể được đại diện bởi các tùy chọn lưu trữ đã qua; nếu không, ’lầm'.

Examples

Ví dụ này cho thấy làm thế nào để xác định xem hình ảnh có thể được lưu vào định dạng tệp được trình bày bởi các tùy chọn lưu trữ đã qua.

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

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

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

Create(ImageOptionsBase, int, int)

Tạo một hình ảnh mới bằng cách sử dụng các tùy chọn tạo cụ thể.

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

Parameters

imageOptions ImageOptionsBase

Các tùy chọn hình ảnh.

width int

Chiều rộng .

height int

Độ cao .

Returns

Image

hình ảnh mới tạo ra.

Examples

Ví dụ này tạo một tệp hình ảnh mới ở một số vị trí đĩa như được xác định bởi tài sản nguồn của ví dụ BmpOptions. Một số tài chính cho ví dạng Bmppoptions được thiết lập trước khi tạo ra bức ảnh thực tế.

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

Tạo ảnh mới bằng cách sử dụng các hình ảnh được chỉ định như trang

public static Image Create(Image[] images)

Parameters

images Image [ ]

Những hình ảnh

Returns

Image

Hình ảnh như ImultipageImage

Create(MultipageCreateOptions)

Tạo nhiều trang cụ thể tạo các tùy chọn.

public static Image Create(MultipageCreateOptions multipageCreateOptions)

Parameters

multipageCreateOptions MultipageCreateOptions

Multipage tạo ra các tùy chọn.

Returns

Image

Hình ảnh đa trang

Create(String[ ], bool)

Tạo hình ảnh nhiều trang có chứa các tệp cụ thể.

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

Parameters

files string [ ]

Các file .

throwExceptionOnLoadError bool

Nếu bạn đặt vào ’truyền’ [xóa ngoại lệ trên lỗi tải].

Returns

Image

Hình ảnh đa trang

Create(String[])

Tạo hình ảnh nhiều trang có chứa các tệp cụ thể.

public static Image Create(string[] files)

Parameters

files string [ ]

Các file .

Returns

Image

Hình ảnh đa trang

Create(Image[ ], bool)

Tạo một hình ảnh mới các hình dạng được chỉ định như các trang.

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

Parameters

images Image [ ]

Những hình ảnh

disposeImages bool

Nếu bạn đặt vào ’truyền’ [có hình ảnh].

Returns

Image

Hình ảnh như ImultipageImage

Crop(Rectangle)

Cắt các góc thẳng cụ thể.

public virtual void Crop(Rectangle rectangle)

Parameters

rectangle Rectangle

Vòng thẳng.

Examples

Ví dụ sau đây trồng một hình ảnh raster. khu vực trồng được xác định thông qua Aspose.Imaging.Rectangle.

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

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

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

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

Hình ảnh thực vật với chuyển đổi

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

Parameters

leftShift int

bên trái thay đổi.

rightShift int

Chuyển đổi đúng

topShift int

Thay đổi hàng đầu

bottomShift int

Thay đổi bên dưới.

Examples

Ví dụ sau đây trồng một hình ảnh raster. khu vực trồng được chỉ định thông qua bên trái, phía trên, bên phải, dưới cùng.

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)

Gets người không thể lưu tin nhắn.

protected virtual string GetCanNotSaveMessage(ImageOptionsBase optionsBase)

Parameters

optionsBase ImageOptionsBase

Các tùy chọn hình ảnh.

Returns

string

Nó không thể tiết kiệm tin nhắn.

GetDefaultOptions(đối tượng[])

Nhận các tùy chọn mặc định.

public virtual ImageOptionsBase GetDefaultOptions(object[] args)

Parameters

args object [ ]

Các Arguments .

Returns

ImageOptionsBase

Lựa chọn mặc định

GetFileFormat(String)

Nhận định dạng file.

public static FileFormat GetFileFormat(string filePath)

Parameters

filePath string

đường file.

Returns

FileFormat

Định dạng tệp cụ thể.

Examples

Ví dụ này cho thấy cách xác định định dạng ảnh mà không tải toàn bộ hình ảnh từ một tệp.

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

Định dạng tệp được xác định không có nghĩa là hình ảnh được xác định có thể được tải lên. Sử dụng một trong các phương pháp tải lên CanLoad để xác định xem tệp có thể được tải lên hay không.

GetFileFormat(Stream)

Nhận định dạng file.

public static FileFormat GetFileFormat(Stream stream)

Parameters

stream Stream

dòng chảy

Returns

FileFormat

Định dạng tệp cụ thể.

Examples

Ví dụ này cho thấy cách xác định định dạng ảnh mà không tải toàn bộ hình ảnh từ một dòng tệp.

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

Định dạng tệp được xác định không có nghĩa là hình ảnh được xác định có thể được tải lên. Sử dụng một trong các phương pháp tải lên CanLoad để xác định liệu dòng có thể được tải lên hay không.

GetFitRectangle(Rectangle)

Có một góc thẳng phù hợp với hình ảnh hiện tại.

protected Rectangle GetFitRectangle(Rectangle rectangle)

Parameters

rectangle Rectangle

Ưu điểm để có được phù hợp Ưu điểm.

Returns

Rectangle

Ưu điểm phù hợp

GetFitRectangle(Vị trí, int[])

Gets rectangle that fits the current bitmap taking into account the pixels passed. Số lượng array pixels passed should be equal to the fit rectangle size.

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

Parameters

rectangle Rectangle

Ưu điểm để có được phù hợp Ưu điểm.

pixels int [ ]

Các 32-bit ARGB pixels array.

Returns

Rectangle

Phù hợp trực tiếp.

GetFittingRectangle(Độ bền, int, int)

Có một góc thẳng phù hợp với hình ảnh hiện tại.

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

Parameters

rectangle Rectangle

Ưu điểm để có được phù hợp Ưu điểm.

width int

Áp dụng đối tượng rộng

height int

Độ cao đối tượng.

Returns

Rectangle

Vòng thẳng phù hợp hoặc ngoại lệ nếu không có vòng thẳng phù hợp được tìm thấy.

GetFittingRectangle(Vị trí, int[ ], int , int)

Có một góc thẳng phù hợp với hình ảnh hiện tại.

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

Parameters

rectangle Rectangle

Ưu điểm để có được phù hợp Ưu điểm.

pixels int [ ]

Các 32-bit ARGB pixel.

width int

Áp dụng đối tượng rộng

height int

Độ cao đối tượng.

Returns

Rectangle

Vòng thẳng phù hợp hoặc ngoại lệ nếu không có vòng thẳng phù hợp được tìm thấy.

GetImage2Export(ImageOptionsBase, Rectangle, IImageExporter)

Có hình ảnh để xuất khẩu

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

Parameters

optionsBase ImageOptionsBase

Cơ sở tùy chọn hình ảnh.

boundsRectangle Rectangle

Các giới hạn trực tiếp.

exporter IImageExporter

Nhà xuất khẩu

Returns

Image

Hình ảnh để xuất khẩu

GetOriginalOptions()

Nhận các tùy chọn dựa trên cài đặt tệp ban đầu.Điều này có thể hữu ích để giữ độ sâu bit và các thông số khác của hình ảnh ban đầu không thay đổi.Ví dụ, nếu chúng tôi tải một hình ảnh PNG màu đen và trắng với 1 bit mỗi pixel và sau đó lưu nó bằng cách sử dụngAspose.Imaging.DataStreamSupporter.Save(System.String) phương pháp, hình ảnh PNG output với 8 bit mỗi pixel sẽ được tạo ra.Để tránh nó và tiết kiệm hình ảnh PNG với 1 bit mỗi pixel, sử dụng phương pháp này để có được các tùy chọn tiết kiệm tương ứng và thông qua chúngđến phương pháp Aspose.Imaging.Image.Save(System.String,_W L17.ImageOptionsBase) như là thông số thứ hai.

public virtual ImageOptionsBase GetOriginalOptions()

Returns

ImageOptionsBase

Các tùy chọn dựa trên cài đặt tệp ban đầu.

GetProportionalHeight(int, int, int, int)

Có một chiều cao tương đối.

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

Parameters

width int

Chiều rộng .

height int

Độ cao .

newWidth int

Chiều rộng mới

Returns

int

Độ cao tương đối.

GetProportionalWidth(int, int, int, int)

Có một chiều rộng tương đối.

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

Parameters

width int

Chiều rộng .

height int

Độ cao .

newHeight int

Độ cao mới

Returns

int

Bề rộng tương đối.

GetSerializedStream(ImageOptionsBase, Rectangle, out int)

Chuyển sang APS.

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

Parameters

imageOptions ImageOptionsBase

Các tùy chọn hình ảnh.

clippingRectangle Rectangle

Cliping trực tiếp.

pageNumber int

Số trang .

Returns

Stream

dòng chảy serial

Load(LoadOptions, LoadOptions)

Tải một hình ảnh mới từ con đường tệp cụ thể hoặc URL.If filePath’ is a file path the method just opens the file.It’s an URL, it downloads the files, stores it as a temporary one, and opents it.

public static Image Load(string filePath, LoadOptions loadOptions)

Parameters

filePath string

Hướng dẫn tập tin hoặc URL để tải hình ảnh từ.

loadOptions LoadOptions

Các tùy chọn tải.

Returns

Image

Hình ảnh tải.

Load(String)

Tải một hình ảnh mới từ con đường tệp cụ thể hoặc URL.If filePath’ is a file path the method just opens the file.It’s an URL, it downloads the files, stores it as a temporary one, and opents it.

public static Image Load(string filePath)

Parameters

filePath string

Hướng dẫn tập tin hoặc URL để tải hình ảnh từ.

Returns

Image

Hình ảnh tải.

Examples

Ví dụ này cho thấy việc tải một tệp hình ảnh hiện có vào một ví dụ của Aspose.Imaging.Image bằng cách sử dụng đường file được chỉ định

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

Tải một hình ảnh mới từ dòng cụ thể.

public static Image Load(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

dòng để tải hình ảnh từ.

loadOptions LoadOptions

Các tùy chọn tải.

Returns

Image

Hình ảnh tải.

Load(Stream)

Tải một hình ảnh mới từ dòng cụ thể.

public static Image Load(Stream stream)

Parameters

stream Stream

dòng để tải hình ảnh từ.

Returns

Image

Hình ảnh tải.

Examples

Ví dụ này cho thấy việc sử dụng các đối tượng System.IO.Stream để tải lên một tệp hình ảnh hiện có

//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(Đồ họa: IColorPalette)

gọi khi palette được thay đổi.

protected virtual void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

Cảnh cổ xưa

newPalette IColorPalette

Palette mới

OnPaletteChanging(Đồ họa: IColorPalette)

gọi khi palette đang thay đổi.

protected virtual void OnPaletteChanging(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

Cảnh cổ xưa

newPalette IColorPalette

Palette mới

ReleaseManagedResources()

Hãy chắc chắn rằng không có tài nguyên không được quản lý được phát hành ở đây, vì chúng có thể đã được phát hành.

protected override void ReleaseManagedResources()

RemoveMetadata()

Xóa các metadata

public virtual void RemoveMetadata()

Resize(int, int)

Sử dụng mặc định Aspose.Imaging.ResizeType.NearestNeighbourResample.

public void Resize(int newWidth, int newHeight)

Parameters

newWidth int

Chiều rộng mới

newHeight int

Độ cao mới

Examples

Ví dụ sau đây cho thấy làm thế nào để đánh giá lại một metaphile (WMF và 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);
                                                                                  }
                                                                              }

Ví dụ sau đây cho thấy làm thế nào để quét lại hình ảnh SVG và lưu nó vào PNG.

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

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

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

Resize(int, int, resizeType)

Xóa lại hình ảnh.

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

Parameters

newWidth int

Chiều rộng mới

newHeight int

Độ cao mới

resizeType ResizeType

Loại Resize

Examples

Tải lại hình ảnh EPS và xuất nó sang định dạng 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());
                                                        }

Tạo lại hình ảnh bằng cách sử dụng kiểu Resize cụ thể.

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

Ví dụ này tải một hình ảnh WMF và resize nó bằng cách sử dụng các phương pháp resizing khác nhau.

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

Ví dụ này tải một hình ảnh và resize nó bằng cách sử dụng các phương pháp resizing khác nhau.

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

Ví dụ này tải một hình ảnh raster và resize nó bằng cách sử dụng các phương pháp resizing khác nhau.

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

Ví dụ này tải lên một hình ảnh ODG đa trang và resize nó bằng cách sử dụng các phương pháp resizing khác nhau.

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

Sử dụng một mặt nạ segment để tăng tốc quá trình phân khúc

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

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

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

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

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

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

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

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

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

Resize(int, int, ImageResizeSettings)

Xóa lại hình ảnh.

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

Parameters

newWidth int

Chiều rộng mới

newHeight int

Độ cao mới

settings ImageResizeSettings

Các thiết lập resize.

Examples

Tạo lại hình ảnh bằng cách sử dụng kiểu Resize cụ thể.

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

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

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

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

Tải lại hình ảnh EPS bằng cách sử dụng cài đặt nâng cao.

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

Ví dụ này tải một hình ảnh và resize nó bằng cách sử dụng các cài đặt resizing khác nhau.

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

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

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

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

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

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

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

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

ResizeHeightProportionally(int)

Tăng chiều cao một cách tương đối. mặc định Aspose.Imaging.ResizeType.NearestNeighbourResample được sử dụng.

public void ResizeHeightProportionally(int newHeight)

Parameters

newHeight int

Độ cao mới

ResizeHeightProportionally(Nhãn hiệu: ResizeType)

Giảm chiều cao một cách tương đối.

public virtual void ResizeHeightProportionally(int newHeight, ResizeType resizeType)

Parameters

newHeight int

Độ cao mới

resizeType ResizeType

Loại của resize.

Examples

Ví dụ này tải một hình ảnh và resize nó tương đối bằng cách sử dụng các phương pháp resizing khác nhau. chỉ có chiều cao được chỉ định, chiều rộng được tính toán tự động.

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

Sử dụng một mặt nạ segment để tăng tốc quá trình phân khúc

// 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(Hình ảnh, ImageResizeSettings)

Giảm chiều cao một cách tương đối.

public virtual void ResizeHeightProportionally(int newHeight, ImageResizeSettings settings)

Parameters

newHeight int

Độ cao mới

settings ImageResizeSettings

Hình ảnh khôi phục cài đặt.

ResizeWidthProportionally(int)

Sử dụng mặc định Aspose.Imaging.ResizeType.NearestNeighbourResample.

public void ResizeWidthProportionally(int newWidth)

Parameters

newWidth int

Chiều rộng mới

ResizeWidthProportionally(Nhãn hiệu: ResizeType)

Tăng chiều rộng tương đối.

public virtual void ResizeWidthProportionally(int newWidth, ResizeType resizeType)

Parameters

newWidth int

Chiều rộng mới

resizeType ResizeType

Loại của resize.

Examples

Ví dụ này tải một hình ảnh và resize nó tương đối bằng cách sử dụng các phương pháp resizing khác nhau. chỉ có chiều rộng được chỉ định, chiều cao được tính toán tự động.

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(Hình ảnh, ImageResizeSettings)

Tăng chiều rộng tương đối.

public virtual void ResizeWidthProportionally(int newWidth, ImageResizeSettings settings)

Parameters

newWidth int

Chiều rộng mới

settings ImageResizeSettings

Hình ảnh khôi phục cài đặt.

Rotate(Sông)

Hình ảnh xoay quanh trung tâm.

public virtual void Rotate(float angle)

Parameters

angle float

góc xoay trong độ. giá trị tích cực sẽ xoay theo cách đồng hồ.

RotateFlip(RotateFlipType)

xoay, nhảy, hoặc xoay và nhảy hình ảnh.

public abstract void RotateFlip(RotateFlipType rotateFlipType)

Parameters

rotateFlipType RotateFlipType

Loại của rotat flip.

Examples

Ví dụ này cho thấy việc sử dụng hoạt động Rotate trên một hình ảnh. ví dụ tải một tệp ảnh hiện có từ một số vị trí đĩa và thực hiện hành động Rota trên ảnh theo giá trị của 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();
                                                                                                                                                                                                                                                       }

Ví dụ này tải một hình ảnh, xoay nó bằng 90 độ đồng hồ và tùy chọn nhấp nháy hình dạng ngang và/hoặc dọc.

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

Ví dụ này tải một hình ảnh ODG, xoay nó bằng 90 độ theo chiều đồng hồ và tùy chọn nhấp vào hình dạng ngang và/hoặc dọc.

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

Tiết kiệm dữ liệu hình ảnh đến dòng dưới.

public override sealed void Save()

Examples

Ví dụ sau đây cho thấy làm thế nào để lưu một hình ảnh BMP hoàn chỉnh hoặc một phần của nó vào một tệp hoặc dòng.

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

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

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

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

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

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

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

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

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

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

Save(String)

Lưu hình ảnh đến vị trí tệp cụ thể.

public override void Save(string filePath)

Parameters

filePath string

Hướng dẫn file để lưu hình ảnh đến.

Save(Thẻ, ImageOptionsBase)

Lưu dữ liệu của đối tượng đến vị trí tệp cụ thể trong định dạng tệp cụ thể theo tùy chọn lưu.

public virtual void Save(string filePath, ImageOptionsBase options)

Parameters

filePath string

đường file.

options ImageOptionsBase

Các tùy chọn.

Examples

Ví dụ sau đây tải lên một hình ảnh BMP từ một tệp, sau đó lưu lại bức ảnh vào một tập tin 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);
                                                                                                   }

Ví dụ này cho thấy các bước đơn giản để lưu một hình ảnh. Để chứng minh hoạt động này, chúng tôi tải một tệp hiện có từ một số vị trí đĩa, thực hiện Hoạt động xoay trên bức ảnh và lưu ảnh trong định dạng PSD sử dụng 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());
                                                                                                                                                                                                                                         }

Ví dụ sau đây cho thấy làm thế nào để lưu một hình ảnh BMP hoàn chỉnh hoặc một phần của nó vào một tệp hoặc dòng.

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(Màn hình, ImageOptionsBase, Rectangle)

Lưu dữ liệu của đối tượng đến vị trí tệp cụ thể trong định dạng tệp cụ thể theo tùy chọn lưu.

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

Parameters

filePath string

đường file.

options ImageOptionsBase

Các tùy chọn.

boundsRectangle Rectangle

Mục đích hình ảnh giới hạn trực tiếp. thiết lập trực tiếp trống để sử dụng giới hạn nguồn.

Examples

Ví dụ sau đây tải một hình ảnh BMP từ một tệp, sau đó lưu một phần trực tiếp của ảnh vào một tập tin 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);
                                                                                                                         }

Ví dụ sau đây cho thấy làm thế nào để lưu một hình ảnh BMP hoàn chỉnh hoặc một phần của nó vào một tệp hoặc dòng.

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

Lựa chọn

ImageSaveException

Hình ảnh tiết kiệm thất bại

Save(Hình ảnh, ImageOptionsBase)

Lưu dữ liệu của hình ảnh vào dòng cụ thể trong định dạng tệp cụ thể theo tùy chọn lưu.

public void Save(Stream stream, ImageOptionsBase optionsBase)

Parameters

stream Stream

Stream để lưu dữ liệu của hình ảnh đến.

optionsBase ImageOptionsBase

Các tùy chọn tiết kiệm

Examples

Ví dụ sau đây tải lên một hình ảnh từ một tệp, sau đó lưu lại bức ảnh vào dòng file 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);
                                                                                                           }
                                                                                                       }

Ví dụ này cho thấy quá trình lưu một hình ảnh vào MemoryStream. Để hiển thị hoạt động này, ví dụ tải một tệp hiện có từ một vị trí đĩa, thực hiện Hoạt động xoay trên ảnh và Save the image in PSD format.

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

Ví dụ sau đây cho thấy làm thế nào để lưu một hình ảnh BMP hoàn chỉnh hoặc một phần của nó vào một tệp hoặc dòng.

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

Lựa chọn

ArgumentException

Không thể lưu vào định dạng cụ thể vì nó không được hỗ trợ tại thời điểm này.;optionsBase

ImageSaveException

Hình ảnh xuất khẩu thất bại

Save(Stream, ImageOptionsBase, Rectangle)

Lưu dữ liệu của hình ảnh vào dòng cụ thể trong định dạng tệp cụ thể theo tùy chọn lưu.

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

Parameters

stream Stream

Stream để lưu dữ liệu của hình ảnh đến.

optionsBase ImageOptionsBase

Các tùy chọn tiết kiệm

boundsRectangle Rectangle

Mục đích hình ảnh giới hạn trực tiếp. thiết lập trực tiếp trống để sử dụng giới hạn nguồn.

Examples

Ví dụ sau đây tải lên một hình ảnh từ một tệp, sau đó lưu một phần trực tiếp của bức ảnh vào dòng file 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);
                                                                                                                                 }
                                                                                                                             }

Ví dụ sau đây cho thấy làm thế nào để lưu một hình ảnh BMP hoàn chỉnh hoặc một phần của nó vào một tệp hoặc dòng.

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

Lựa chọn

ArgumentException

Không thể lưu vào định dạng cụ thể vì nó không được hỗ trợ tại thời điểm này.;optionsBase

ImageSaveException

Hình ảnh xuất khẩu thất bại

SetPalette(Màn hình, bool)

Đặt hình ảnh palette.

public abstract void SetPalette(IColorPalette palette, bool updateColors)

Parameters

palette IColorPalette

Palette để đặt.

updateColors bool

nếu thiết lập màu sắc ’thực tế’ sẽ được cập nhật theo bảng màu mới; nếu không, chỉ số màu vẫn không thay đổi. lưu ý rằng chỉ số không thay đổi có thể phá vỡ hình ảnh trên tải nếu một số chỉ số không có nhập bảng màu tương ứng.

UpdateContainer(Image)

Cập nhật container

protected void UpdateContainer(Image container)

Parameters

container Image

container là

Xem thêm

DataStreamSupporter , IObjectWithBounds

 Tiếng Việt