Class Image

Class Image

ชื่อพื้นที่: Aspose.Imaging การประกอบ: Aspose.Imaging.dll (25.4.0)

ภาพเป็นชั้นพื้นฐานสําหรับทุกประเภทของภาพ

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

Inheritance

object DisposableObject DataStreamSupporter Image

Derived

RasterImage , VectorImage

Implements

IDisposable , IObjectWithBounds

อนุญาโตตุลาการ

DataStreamSupporter.timeout , DataStreamSupporter.CacheData() , DataStreamSupporter.Save() , DataStreamSupporter.Save(Stream) , DataStreamSupporter.Save(string) , DataStreamSupporter.Save(string, bool) , DataStreamSupporter.SaveData(Stream) , DataStreamSupporter.ReleaseManagedResources() , DataStreamSupporter.OnDataStreamContainerChanging(StreamContainer) , DataStreamSupporter.DataStreamContainer , DataStreamSupporter.IsCached , DisposableObject.Dispose() , DisposableObject.ReleaseManagedResources() , DisposableObject.ReleaseUnmanagedResources() , DisposableObject.VerifyNotDisposed() , DisposableObject.Disposed , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

ตรวจสอบว่าแพลตฟอร์มจะถูกใช้โดยภาพ

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

การรีไซเคิลภาพโดยใช้ประเภทรีไซเคิลที่กําหนด

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

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

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

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

ตัวอย่างนี้สร้างไฟล์ภาพใหม่ในสถานที่ของดิสก์บางอย่างตามที่ระบุโดยคุณสมบัติแหล่งของตัวอย่าง BmpOptions คุณสมบัติหลายตัวสําหรับตัวอย่าง BmpOptions ถูกตั้งค่าก่อนที่จะสร้างภาพจริง โดยเฉพาะอย่างยิ่งคุณสมบัติแหล่งซึ่งหมายถึงสถานที่ของดิสก์จริงในกรณีนี้

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

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

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

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

Constructors

Image()

เริ่มต้นตัวอย่างใหม่ของคลาส Aspose.Imaging.Image

[JsonConstructor]
protected Image()

Image(คอลัมน์)

เริ่มต้นตัวอย่างใหม่ของคลาส Aspose.Imaging.Image

protected Image(IColorPalette colorPalette)

Parameters

colorPalette IColorPalette

แผ่นสี

Properties

AutoAdjustPalette

รับหรือตั้งค่าหมายความว่าอัตโนมัติปรับแพลตฟอร์ม

public bool AutoAdjustPalette { get; set; }

คุณสมบัติมูลค่า

bool

BackgroundColor

รับหรือตั้งค่าสําหรับสีพื้นหลัง

public virtual Color BackgroundColor { get; set; }

คุณสมบัติมูลค่า

Color

BitsPerPixel

รับภาพบิตต่อพิกเซลคํานวณ

public abstract int BitsPerPixel { get; }

คุณสมบัติมูลค่า

int

Bounds

ได้รับข้อ จํากัด ของภาพ

public Rectangle Bounds { get; }

คุณสมบัติมูลค่า

Rectangle

BufferSizeHint

รับหรือตั้งค่าตัวอักษรขนาดกระเป๋าที่กําหนดขนาดที่อนุญาตสูงสุดสําหรับกระเป๋าภายในทั้งหมด

public int BufferSizeHint { get; set; }

คุณสมบัติมูลค่า

int

Container

รับ Aspose.Imaging.Image ภาชนะ

public Image Container { get; }

คุณสมบัติมูลค่า

Image

Remarks

หากคุณสมบัตินี้ไม่ได้หมายความว่าภาพนั้นอยู่ในภาพอื่น

FileFormat

ได้รับค่าของรูปแบบไฟล์

public virtual FileFormat FileFormat { get; }

คุณสมบัติมูลค่า

FileFormat

HasBackgroundColor

รับหรือตั้งค่าหมายความว่าภาพมีสีพื้นหลังหรือไม่

public virtual bool HasBackgroundColor { get; set; }

คุณสมบัติมูลค่า

bool

Height

ได้รับความสูงของภาพ

public abstract int Height { get; }

คุณสมบัติมูลค่า

int

InterruptMonitor

รับหรือตั้งค่าจอแสดงผลที่หยุด

public InterruptMonitor InterruptMonitor { get; set; }

คุณสมบัติมูลค่า

InterruptMonitor

Palette

รับหรือตั้งค่าแพลตฟอร์มสี พลตฟอร์มสีไม่ได้ใช้เมื่อพิกเซลถูกนําเสนอโดยตรง

public IColorPalette Palette { get; set; }

คุณสมบัติมูลค่า

IColorPalette

Size

รับขนาดภาพ

public Size Size { get; }

คุณสมบัติมูลค่า

Size

Examples

ตัวอย่างนี้แสดงให้เห็นวิธีการโหลดภาพ DJVU จากไฟล์และพิมพ์ข้อมูลเกี่ยวกับหน้า

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

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

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

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

UsePalette

ได้รับค่าที่แสดงให้เห็นว่าแผงภาพจะถูกใช้หรือไม่

public virtual bool UsePalette { get; }

คุณสมบัติมูลค่า

bool

Examples

ตรวจสอบว่าแพลตฟอร์มจะถูกใช้โดยภาพ

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

Width

รับภาพกว้าง

public abstract int Width { get; }

คุณสมบัติมูลค่า

int

Methods

CanLoad(รั้ว)

กําหนดว่าภาพสามารถโหลดได้จากเส้นทางไฟล์ที่ระบุได้หรือไม่

public static bool CanLoad(string filePath)

Parameters

filePath string

เส้นทางไฟล์

Returns

bool

‘จริง’ ถ้าภาพสามารถดาวน์โหลดจากไฟล์ที่ระบุหรือไม่ ‘ผิดพลาด’

Examples

ตัวอย่างนี้ระบุว่าภาพสามารถโหลดได้จากไฟล์หรือไม่

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

CanLoad(ลวด, LoadOptions)

กําหนดว่าภาพสามารถโหลดได้จากเส้นทางไฟล์ที่ระบุและเลือกโดยใช้ตัวเลือกเปิดที่ระบุ

public static bool CanLoad(string filePath, LoadOptions loadOptions)

Parameters

filePath string

เส้นทางไฟล์

loadOptions LoadOptions

ตัวเลือกโหลด

Returns

bool

‘จริง’ ถ้าภาพสามารถดาวน์โหลดจากไฟล์ที่ระบุหรือไม่ ‘ผิดพลาด’

CanLoad(Stream)

กําหนดว่าภาพสามารถโหลดได้จากไหลที่ระบุได้หรือไม่

public static bool CanLoad(Stream stream)

Parameters

stream Stream

กระแสที่จะโหลดจาก

Returns

bool

‘จริง’ ถ้าภาพสามารถโหลดได้จากกระแสที่ระบุหรือไม่ ‘ล้มเหลว’

Examples

ตัวอย่างนี้ระบุว่าภาพสามารถโหลดได้จากไฟล์ Stream

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

                                                                                  bool canLoad;

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

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

CanLoad(แหล่งจ่ายไฟ LoadOptions)

กําหนดว่าภาพสามารถโหลดได้จากกระแสที่ระบุและเลือกโดยใช้ loadOptions" ที่ระบุ

public static bool CanLoad(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

กระแสที่จะโหลดจาก

loadOptions LoadOptions

ตัวเลือกโหลด

Returns

bool

‘จริง’ ถ้าภาพสามารถโหลดได้จากกระแสที่ระบุหรือไม่ ‘ล้มเหลว’

CanSave(ImageOptionsBase)

กําหนดว่าภาพสามารถบันทึกไว้ในรูปแบบไฟล์ที่ระบุโดยตัวเลือกบันทึกที่ผ่านไป

public bool CanSave(ImageOptionsBase options)

Parameters

options ImageOptionsBase

การประหยัดตัวเลือกที่จะใช้

Returns

bool

‘จริง’ ถ้าภาพสามารถบันทึกไว้ในรูปแบบไฟล์ที่ระบุโดยตัวเลือกบันทึกที่ผ่านไป หรือ ‘ผิดพลาด’

Examples

ตัวอย่างนี้แสดงให้เห็นวิธีการตรวจสอบว่าภาพสามารถบันทึกไว้ในรูปแบบไฟล์ที่ระบุโดยตัวเลือกบันทึกที่ผ่านไป

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

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

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

Create(ImageOptionsBase, int, int)

สร้างภาพใหม่โดยใช้ตัวเลือกการสร้างที่ระบุ

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

Parameters

imageOptions ImageOptionsBase

ตัวเลือกภาพ

width int

ความกว้าง

height int

ความสูง

Returns

Image

รูปภาพที่สร้างขึ้นใหม่

Examples

ตัวอย่างนี้สร้างไฟล์ภาพใหม่ในสถานที่ของดิสก์บางอย่างตามที่ระบุโดยคุณสมบัติแหล่งของตัวอย่าง BmpOptions คุณสมบัติหลายตัวสําหรับตัวอย่าง BmpOptions ถูกตั้งค่าก่อนที่จะสร้างภาพจริง โดยเฉพาะอย่างยิ่งคุณสมบัติแหล่งซึ่งหมายถึงสถานที่ของดิสก์จริงในกรณีนี้

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

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

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

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

Create(Image[])

สร้างภาพใหม่โดยใช้ภาพที่ระบุเป็นหน้า

public static Image Create(Image[] images)

Parameters

images Image [ ]

รูปภาพ

Returns

Image

ภาพเป็น IMultipageImage

Create(MultipageCreateOptions)

สร้างตัวเลือกหลายหน้าที่ระบุ

public static Image Create(MultipageCreateOptions multipageCreateOptions)

Parameters

multipageCreateOptions MultipageCreateOptions

Multipage สร้างตัวเลือก

Returns

Image

ภาพหลายหน้า

Create(รั้ว[ ], บอล)

สร้างภาพหลายหน้าที่มีไฟล์ที่ระบุ

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

Parameters

files string [ ]

ไฟล์

throwExceptionOnLoadError bool

ถ้าคุณตั้งค่าเป็น ‘จริง’ [ลบข้อผิดพลาดในการโหลด]

Returns

Image

ภาพหลายหน้า

Create(รั้ว[])

สร้างภาพหลายหน้าที่มีไฟล์ที่ระบุ

public static Image Create(string[] files)

Parameters

files string [ ]

ไฟล์

Returns

Image

ภาพหลายหน้า

Create(Image[ ], บอล)

สร้างภาพใหม่ภาพที่ระบุเป็นหน้า

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

Parameters

images Image [ ]

รูปภาพ

disposeImages bool

ถ้าคุณตั้งค่าเป็น ‘จริง’ [ให้ภาพ ]

Returns

Image

ภาพเป็น IMultipageImage

Crop(Rectangle)

รั้วตรงที่ระบุ

public virtual void Crop(Rectangle rectangle)

Parameters

rectangle Rectangle

ตุ๊กตา

Examples

ตัวอย่างต่อไปนี้จะปลูกรูปสกรู พื้นที่ปลูกจะระบุผ่าน Aspose.Imaging.Rectangle

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

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

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

Crop(int, int, int, int)

รูปภาพของพืชที่มีการเปลี่ยนแปลง

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

Parameters

leftShift int

เปลี่ยนด้านซ้าย

rightShift int

เปลี่ยนที่เหมาะสม

topShift int

เปลี่ยนด้านบน

bottomShift int

เปลี่ยนด้านล่าง

Examples

ตัวอย่างต่อไปนี้จะปลูกรูปสกรู พื้นที่การปลูกจะระบุผ่านเส้นทางด้านซ้ายด้านบนด้านขวาด้านล่าง

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

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

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

~Image()

protected ~Image()

GetCanNotSaveMessage(ImageOptionsBase)

ได้รับข้อความไม่สามารถบันทึกได้

protected virtual string GetCanNotSaveMessage(ImageOptionsBase optionsBase)

Parameters

optionsBase ImageOptionsBase

ตัวเลือกภาพ

Returns

string

มันไม่สามารถบันทึกข้อความ

GetDefaultOptions(วัตถุ[])

รับตัวเลือกแบบ default

public virtual ImageOptionsBase GetDefaultOptions(object[] args)

Parameters

args object [ ]

ข้อตกลง

Returns

ImageOptionsBase

ตัวเลือกที่กําหนดเอง

GetFileFormat(รั้ว)

รับรูปแบบไฟล์

public static FileFormat GetFileFormat(string filePath)

Parameters

filePath string

เส้นทางไฟล์

Returns

FileFormat

รูปแบบไฟล์ที่กําหนด

Examples

ตัวอย่างนี้แสดงให้เห็นวิธีการกําหนดรูปแบบภาพโดยไม่ต้องโหลดภาพทั้งหมดจากไฟล์

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

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

Remarks

รูปแบบไฟล์ที่กําหนดไม่ได้หมายความว่าภาพที่ระบุสามารถโหลดได้ ใช้หนึ่งในวิธีการโหลด CanLoad เพื่อตรวจสอบว่าไฟล์สามารถโหลดได้หรือไม่

GetFileFormat(Stream)

รับรูปแบบไฟล์

public static FileFormat GetFileFormat(Stream stream)

Parameters

stream Stream

กระแส

Returns

FileFormat

รูปแบบไฟล์ที่กําหนด

Examples

ตัวอย่างนี้แสดงให้เห็นวิธีการกําหนดรูปแบบภาพโดยไม่ต้องโหลดภาพทั้งหมดจากไฟล์

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

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

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

Remarks

รูปแบบไฟล์ที่กําหนดไม่ได้หมายความว่าภาพที่ระบุสามารถโหลดได้ ใช้หนึ่งในวิธีการโหลด CanLoad เพื่อตรวจสอบว่าสามารถโหลดได้หรือไม่

GetFitRectangle(Rectangle)

ได้รับแนวตั้งที่ตรงกับภาพปัจจุบัน

protected Rectangle GetFitRectangle(Rectangle rectangle)

Parameters

rectangle Rectangle

ตรงเพื่อให้เหมาะสม ตรงสําหรับ

Returns

Rectangle

คู่มือที่เหมาะสม

GetFitRectangle(ก้น, int[])

ได้รับแนวตั้งที่ตรงกับ bitmap ในขณะที่พิกเซลที่ผ่านการคํานวณ พิกเซลที่ผ่านการคํานวณแนวตั้งควรเท่ากับขนาดแนวตั้งที่ตรง

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

Parameters

rectangle Rectangle

ตรงเพื่อให้เหมาะสม ตรงสําหรับ

pixels int [ ]

32 บิต ARGB pixels array

Returns

Rectangle

คู่มือที่เหมาะสม

GetFittingRectangle(ใบมีด, int, int)

ได้รับแนวตั้งที่ตรงกับภาพปัจจุบัน

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

Parameters

rectangle Rectangle

ตรงเพื่อให้เหมาะสม ตรงสําหรับ

width int

ความกว้างของวัตถุ

height int

ความสูงของวัตถุ

Returns

Rectangle

ตะแกรงที่เหมาะสมหรือยกเว้นถ้าไม่มี ตะแกรงที่เหมาะสมสามารถพบได้

GetFittingRectangle(ก้น, int[ ], int , int)

ได้รับแนวตั้งที่ตรงกับภาพปัจจุบัน

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

Parameters

rectangle Rectangle

ตรงเพื่อให้เหมาะสม ตรงสําหรับ

pixels int [ ]

พิกเซล ARGB 32 บิต

width int

ความกว้างของวัตถุ

height int

ความสูงของวัตถุ

Returns

Rectangle

ตะแกรงที่เหมาะสมหรือยกเว้นถ้าไม่มี ตะแกรงที่เหมาะสมสามารถพบได้

GetImage2Export(ImageOptionsBase, Rectangle, IImageExporter)

ได้รับภาพที่จะส่งออก

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

Parameters

optionsBase ImageOptionsBase

ตัวเลือกภาพฐาน

boundsRectangle Rectangle

เส้นผ่าศูนย์กลางแนวตั้ง

exporter IImageExporter

ผู้ส่งออก

Returns

Image

รูปภาพที่จะส่งออก

GetOriginalOptions()

รับตัวเลือกตามการตั้งค่าไฟล์เดิมนี่อาจเป็นประโยชน์ในการรักษาความลึกและพารามิเตอร์อื่น ๆ ของภาพเดิมไม่เปลี่ยนแปลงตัวอย่างเช่นถ้าเราโหลดภาพ PNG สีดําและสีขาวด้วย 1 บิตต่อพิกเซลแล้วบันทึกมันโดยใช้Aspose.Imaging.DataStreamSupporter.Save(System.String) วิธีการภาพ PNG output กับ 8 บิตต่อพิกเซลจะผลิตเพื่อหลีกเลี่ยงและบันทึกภาพ PNG ด้วย 1 บิตต่อพิกเซลใช้วิธีการนี้เพื่อรับตัวเลือกการบันทึกที่เหมาะสมและผ่านพวกเขาวิธีการ Aspose.Imaging.Image.Save(System.String,Aspose.Imaging.ImageOptionsBase) เป็นพารามิเตอร์ที่สอง

public virtual ImageOptionsBase GetOriginalOptions()

Returns

ImageOptionsBase

ตัวเลือกตามการตั้งค่าไฟล์เดิม

GetProportionalHeight(int, int, int)

ได้รับความสูง proportional

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

Parameters

width int

ความกว้าง

height int

ความสูง

newWidth int

ความกว้างใหม่

Returns

int

ความสูง proportional

GetProportionalWidth(int, int, int)

ได้รับความกว้าง proportional

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

Parameters

width int

ความกว้าง

height int

ความสูง

newHeight int

ความสูงใหม่

Returns

int

ความกว้าง proportional

GetSerializedStream(ImageOptionsBase, Rectangle, out int)

แปลงเป็น APS

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

Parameters

imageOptions ImageOptionsBase

ตัวเลือกภาพ

clippingRectangle Rectangle

คลิกที่ตรง

pageNumber int

หมายเลขหน้า

Returns

Stream

กระแส سریال

Load(ลวด, LoadOptions)

ดาวน์โหลดภาพใหม่จากเส้นทางไฟล์ที่ระบุหรือ URL.If filePath’ เป็นเส้นทางไฟล์วิธีการเพียงเปิดไฟล์.If filePath’ เป็น URL, the method downloads the file, stores it as a temporary one, and opens it. If filePath’ is an URL, the method downloads the file, stores it as a temporary one, and opens it.

public static Image Load(string filePath, LoadOptions loadOptions)

Parameters

filePath string

เส้นทางไฟล์หรือ URL เพื่อโหลดภาพจาก

loadOptions LoadOptions

ตัวเลือกโหลด

Returns

Image

ภาพที่โหลด

Load(รั้ว)

ดาวน์โหลดภาพใหม่จากเส้นทางไฟล์ที่ระบุหรือ URL.If filePath’ เป็นเส้นทางไฟล์วิธีการเพียงเปิดไฟล์.If filePath’ เป็น URL, the method downloads the file, stores it as a temporary one, and opens it. If filePath’ is an URL, the method downloads the file, stores it as a temporary one, and opens it.

public static Image Load(string filePath)

Parameters

filePath string

เส้นทางไฟล์หรือ URL เพื่อโหลดภาพจาก

Returns

Image

ภาพที่โหลด

Examples

ตัวอย่างนี้แสดงให้เห็นถึงการโหลดไฟล์ภาพที่มีอยู่ไปยังตัวอย่าง Aspose.Imaging.Image โดยใช้เส้นทางไฟล์ที่ระบุ

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

Load(แหล่งจ่ายไฟ LoadOptions)

ดาวน์โหลดภาพใหม่จากกระแสที่ระบุ

public static Image Load(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

กระแสเพื่อโหลดภาพจาก

loadOptions LoadOptions

ตัวเลือกโหลด

Returns

Image

ภาพที่โหลด

Load(Stream)

ดาวน์โหลดภาพใหม่จากกระแสที่ระบุ

public static Image Load(Stream stream)

Parameters

stream Stream

กระแสเพื่อโหลดภาพจาก

Returns

Image

ภาพที่โหลด

Examples

ตัวอย่างนี้แสดงให้เห็นถึงการใช้ Objects System.IO.Stream เพื่อโหลดไฟล์ภาพที่มีอยู่

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

OnPaletteChanged(IColorPalette, IColorPalette)

โทรเมื่อแพลตฟอร์มมีการเปลี่ยนแปลง

protected virtual void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

แพลิเคชันเก่า

newPalette IColorPalette

แพลิเคชันใหม่

OnPaletteChanging(IColorPalette, IColorPalette)

การเรียกเมื่อแพลตฟอร์มจะเปลี่ยนแปลง

protected virtual void OnPaletteChanging(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

แพลิเคชันเก่า

newPalette IColorPalette

แพลิเคชันใหม่

ReleaseManagedResources()

เปิดตัวทรัพยากรที่จัดการ ตรวจสอบให้แน่ใจว่าไม่มีทรัพยากรที่ไม่ได้จัดการจะเปิดตัวที่นี่เนื่องจากอาจมีการเปิดตัวแล้ว

protected override void ReleaseManagedResources()

RemoveMetadata()

ดาวน์โหลด metadata

public virtual void RemoveMetadata()

Resize(int, int)

resize the image. The default Aspose.Imaging.ResizeType.NearestNeighbourResample ใช้

public void Resize(int newWidth, int newHeight)

Parameters

newWidth int

ความกว้างใหม่

newHeight int

ความสูงใหม่

Examples

ตัวอย่างต่อไปนี้แสดงให้เห็นว่าวิธีการรีไซเคิลโลหะ (WMF และ EMF)

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

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

ตัวอย่างต่อไปนี้แสดงให้เห็นวิธีการรีไซเคิลภาพ SVG และบันทึกเป็น PNG

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

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

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

Resize(int, int, resizeType)

รีไซเคิลภาพ

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

Parameters

newWidth int

ความกว้างใหม่

newHeight int

ความสูงใหม่

resizeType ResizeType

ประเภทการรีไซเคิล

Examples

รีไซเคิลภาพ EPS และส่งออกเป็นรูปแบบ PNG

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

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

การรีไซเคิลภาพโดยใช้ประเภทรีไซเคิลที่กําหนด

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

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

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

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

ตัวอย่างนี้โหลดภาพ WMF และรีไซเคิลโดยใช้วิธีการรีไซเคิลต่างๆ

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

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

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

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

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

ตัวอย่างนี้โหลดภาพและรีไซเคิลโดยใช้วิธีการรีไซเคิลต่างๆ

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

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

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

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

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

ตัวอย่างนี้โหลดภาพเรสเตอร์และรีไซเคิลโดยใช้วิธีการรีไซเคิลต่างๆ

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

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

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

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

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

ตัวอย่างนี้โหลดภาพ ODG มัลติหน้าและรีไซเคิลโดยใช้วิธีการรีไซเคิลต่างๆ

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

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

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

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

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

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

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

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

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

ใช้หน้ากากส่วนเพื่อเร่งกระบวนการแบ่ง

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

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

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

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

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

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

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

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

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

Resize(int, int, ImageResizeSettings)

รีไซเคิลภาพ

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

Parameters

newWidth int

ความกว้างใหม่

newHeight int

ความสูงใหม่

settings ImageResizeSettings

การตั้งค่ารีไซเคิล

Examples

การรีไซเคิลภาพโดยใช้ประเภทรีไซเคิลที่กําหนด

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

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

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

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

แก้ไขภาพ EPS โดยใช้การตั้งค่าขั้นสูง

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

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

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

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

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

ตัวอย่างนี้โหลดภาพและรีไซเคิลโดยใช้การตั้งค่ารีไซเคิลต่างๆ

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

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

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

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

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

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

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

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

ResizeHeightProportionally(int)

รีไซเคิลความสูงอย่างต่อเนื่อง การใช้ Aspose.Imaging.ResizeType.NearestNeighbourResample แบบกําหนดเอง

public void ResizeHeightProportionally(int newHeight)

Parameters

newHeight int

ความสูงใหม่

ResizeHeightProportionally(int, ResizeType)

ลดความสูงอย่างต่อเนื่อง

public virtual void ResizeHeightProportionally(int newHeight, ResizeType resizeType)

Parameters

newHeight int

ความสูงใหม่

resizeType ResizeType

ประเภทของ Resize

Examples

ตัวอย่างนี้โหลดภาพและรีไซเคิลได้ตามความเหมาะสมโดยใช้วิธีการรีไซเคิลต่างๆ เพียงความสูงจะระบุความกว้างจะคํานวณโดยอัตโนมัติ

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

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

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

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

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

ใช้หน้ากากส่วนเพื่อเร่งกระบวนการแบ่ง

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

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

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

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

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

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

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

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

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

ResizeHeightProportionally(int, ImageResizeSettings)

ลดความสูงอย่างต่อเนื่อง

public virtual void ResizeHeightProportionally(int newHeight, ImageResizeSettings settings)

Parameters

newHeight int

ความสูงใหม่

settings ImageResizeSettings

ภาพรีไซเคิลการตั้งค่า

ResizeWidthProportionally(int)

รีไซเคิลความกว้างอย่างเป็นมิตร การใช้ Aspose.Imaging.ResizeType.NearestNeighbourResample แบบกําหนดเอง

public void ResizeWidthProportionally(int newWidth)

Parameters

newWidth int

ความกว้างใหม่

ResizeWidthProportionally(int, ResizeType)

ลดความกว้างอย่าง proportional

public virtual void ResizeWidthProportionally(int newWidth, ResizeType resizeType)

Parameters

newWidth int

ความกว้างใหม่

resizeType ResizeType

ประเภทของ Resize

Examples

ตัวอย่างนี้โหลดภาพและรีไซเคิลได้ตามความเหมาะสมโดยใช้วิธีการรีไซเคิลต่างๆ ความกว้างเท่านั้นที่ระบุความสูงจะคํานวณโดยอัตโนมัติ

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

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

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

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

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

ResizeWidthProportionally(int, ImageResizeSettings)

ลดความกว้างอย่าง proportional

public virtual void ResizeWidthProportionally(int newWidth, ImageResizeSettings settings)

Parameters

newWidth int

ความกว้างใหม่

settings ImageResizeSettings

ภาพรีไซเคิลการตั้งค่า

Rotate(เฟอร์รี่)

ภาพหมุนรอบศูนย์กลาง

public virtual void Rotate(float angle)

Parameters

angle float

มุมหมุนในเกรด หมายเลขเชิงบวกจะหมุนตามชั่วโมง

RotateFlip(RotateFlipType)

รูต, flips, หรือ รูตและ flips ภาพ

public abstract void RotateFlip(RotateFlipType rotateFlipType)

Parameters

rotateFlipType RotateFlipType

ประเภทของหมุน flip

Examples

ตัวอย่างนี้แสดงให้เห็นถึงการใช้การดําเนินงานหมุนบนภาพ ตัวอย่างโหลดไฟล์ภาพที่มีอยู่จากตําแหน่งดิสก์บางอย่างและดําเนินการหมุนบนภาพตามค่าของ Enum Aspose.Imaging.RotateFlipType

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

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

ตัวอย่างนี้โหลดรูปภาพหมุนด้วย 90 องศาตามนาฬิกาและฟลีตัวเลือกภาพแนวนอนและ(หรือ)แนวตั้ง

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

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

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

ตัวอย่างนี้โหลดภาพ ODG, รอบมันด้วย 90 องศาตามนาฬิกาและตัวเลือกฟิล์มภาพแนวนอนและ/หรือแนวตั้ง

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

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

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

Save()

บันทึกข้อมูลภาพไปยังกระแสพื้นฐาน

public override sealed void Save()

Examples

ตัวอย่างต่อไปนี้แสดงให้เห็นวิธีการบันทึกภาพ BMP entiree หรือส่วนหนึ่งในไฟล์หรือกระแส

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

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

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

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

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

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

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

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

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

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

Save(รั้ว)

บันทึกภาพไปยังตําแหน่งไฟล์ที่ระบุ

public override void Save(string filePath)

Parameters

filePath string

เส้นทางไฟล์เพื่อบันทึกภาพ

Save(รั้ว, ImageOptionsBase)

การบันทึกข้อมูลของวัตถุไปยังตําแหน่งไฟล์ที่ระบุในรูปแบบไฟล์ที่ระบุตามตัวเลือกการบันทึก

public virtual void Save(string filePath, ImageOptionsBase options)

Parameters

filePath string

เส้นทางไฟล์

options ImageOptionsBase

ตัวเลือก

Examples

ตัวอย่างต่อไปนี้โหลดภาพ BMP จากไฟล์แล้วบันทึกภาพไปยังไฟล์ PNG

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

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

ตัวอย่างนี้แสดงให้เห็นขั้นตอนง่ายๆในการบันทึกภาพ เพื่อแสดงการทํางานนี้เราโหลดไฟล์ที่มีอยู่จากตําแหน่งดิสก์บางส่วนดําเนินการหมุนภาพและบันทึกภาพในรูปแบบ PSD โดยใช้ File Path

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

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

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

ตัวอย่างต่อไปนี้แสดงให้เห็นวิธีการบันทึกภาพ BMP entiree หรือส่วนหนึ่งในไฟล์หรือกระแส

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

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

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

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

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

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

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

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

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

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

Save(รั้ว, ImageOptionsBase, Rectangle)

การบันทึกข้อมูลของวัตถุไปยังตําแหน่งไฟล์ที่ระบุในรูปแบบไฟล์ที่ระบุตามตัวเลือกการบันทึก

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

Parameters

filePath string

เส้นทางไฟล์

options ImageOptionsBase

ตัวเลือก

boundsRectangle Rectangle

ภาพจุดหมายปลายทางขอบขอบขอบ ปรับขอบขอบที่ว่างเปล่าเพื่อใช้ขอบแหล่ง

Examples

ตัวอย่างต่อไปนี้โหลดภาพ BMP จากไฟล์แล้วบันทึกส่วนตรงของภาพไปยังไฟล์ PNG

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

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

ตัวอย่างต่อไปนี้แสดงให้เห็นวิธีการบันทึกภาพ BMP entiree หรือส่วนหนึ่งในไฟล์หรือกระแส

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

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

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

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

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

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

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

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

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

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

Exceptions

ArgumentNullException

ตัวเลือก

ImageSaveException

การบันทึกภาพล้มเหลว

Save(กระแส, ImageOptionsBase)

บันทึกข้อมูลของภาพไปยังกระแสที่ระบุในรูปแบบไฟล์ที่ระบุตามตัวเลือกการบันทึก

public void Save(Stream stream, ImageOptionsBase optionsBase)

Parameters

stream Stream

กระแสเพื่อบันทึกข้อมูลของภาพ

optionsBase ImageOptionsBase

ตัวเลือกการประหยัด

Examples

ตัวอย่างต่อไปนี้โหลดภาพจากไฟล์แล้วบันทึกภาพไปยังไฟล์ PNG

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

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

ตัวอย่างนี้แสดงให้เห็นกระบวนการของการบันทึกภาพไปยัง MemoryStream เพื่อแสดงการทํางานนี้ ตัวอย่างโหลดไฟล์ที่มีอยู่จากตําแหน่งดิสก์บางอย่างดําเนินการในการหมุนภาพและบันทึกภาพในรูปแบบ PSD

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

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

ตัวอย่างต่อไปนี้แสดงให้เห็นวิธีการบันทึกภาพ BMP entiree หรือส่วนหนึ่งในไฟล์หรือกระแส

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

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

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

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

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

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

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

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

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

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

Exceptions

ArgumentNullException

ตัวเลือก

ArgumentException

ไม่สามารถบันทึกไว้ในรูปแบบที่ระบุเพราะมันไม่ได้รับการสนับสนุนในขณะนี้

ImageSaveException

การส่งออกภาพล้มเหลว

Save(กระแส, ImageOptionsBase, Rectangle)

บันทึกข้อมูลของภาพไปยังกระแสที่ระบุในรูปแบบไฟล์ที่ระบุตามตัวเลือกการบันทึก

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

Parameters

stream Stream

กระแสเพื่อบันทึกข้อมูลของภาพ

optionsBase ImageOptionsBase

ตัวเลือกการประหยัด

boundsRectangle Rectangle

ภาพจุดหมายปลายทางขอบขอบขอบ ปรับขอบขอบที่ว่างเปล่าเพื่อใช้ขอบแหล่ง

Examples

ตัวอย่างต่อไปนี้โหลดภาพจากไฟล์แล้วบันทึกส่วนตรงของภาพไปยังไฟล์ PNG

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

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

ตัวอย่างต่อไปนี้แสดงให้เห็นวิธีการบันทึกภาพ BMP entiree หรือส่วนหนึ่งในไฟล์หรือกระแส

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

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

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

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

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

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

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

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

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

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

Exceptions

ArgumentNullException

ตัวเลือก

ArgumentException

ไม่สามารถบันทึกไว้ในรูปแบบที่ระบุเพราะมันไม่ได้รับการสนับสนุนในขณะนี้

ImageSaveException

การส่งออกภาพล้มเหลว

SetPalette(IColorPalette, บอล)

สร้างภาพแพลตฟอร์ม

public abstract void SetPalette(IColorPalette palette, bool updateColors)

Parameters

palette IColorPalette

แพลิเคชันที่กําหนดไว้

updateColors bool

หากกําหนดสี “จริง” จะได้รับการปรับปรุงตามแพลตฟอร์มใหม่; ในทางอื่น ๆ ตัวชี้วัดสีจะยังคงไม่เปลี่ยนแปลง. โปรดทราบว่าตัวชี้วัดที่ไม่ได้เปลี่ยนแปลงอาจรบกวนภาพบนโหลดถ้าบางตัวชี้วัดไม่มีรายการแพลตฟอร์มที่เกี่ยวข้อง.

UpdateContainer(Image)

ปรับปรุงคอนเทนเนอร์

protected void UpdateContainer(Image container)

Parameters

container Image

ภาชนะ

ดูเพิ่มเติม

DataStreamSupporter , IObjectWithBounds

 แบบไทย