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

تصویر را با استفاده از نوع Resize خاص بازسازی کنید.

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

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

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

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

این مثال یک فایل تصویر جدید را در برخی از مکان های دیسک ایجاد می کند، همانطور که توسط ویژگی منبع در مثال 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

صفحه اصلی » آرشیو برچسب ها: Image container

public Image Container { get; }

ارزش املاک

Image

Remarks

اگر این دارایی صفر نباشد، نشان می دهد که تصویر در یک تصویر دیگر قرار دارد.

FileFormat

به دست آوردن ارزش از فرمت فایل

public virtual FileFormat FileFormat { get; }

ارزش املاک

FileFormat

HasBackgroundColor

دریافت یا تنظیم یک مقدار نشان می دهد که آیا تصویر دارای رنگ پس زمینه است.

public virtual bool HasBackgroundColor { get; set; }

ارزش املاک

bool

Height

ارتفاع تصویر را نشان می دهد.

public abstract int Height { get; }

ارزش املاک

int

InterruptMonitor

این کار را انجام می دهد یا مانیتور قطع می شود.

public InterruptMonitor InterruptMonitor { get; set; }

ارزش املاک

InterruptMonitor

Palette

پالت رنگی استفاده نمی شود زمانی که پیکسل ها به طور مستقیم نشان داده می شوند.

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

تعیین می کند که آیا تصویر می تواند از مسیر فایل مشخص شده بارگذاری شود.

public static bool CanLoad(string filePath)

Parameters

filePath string

فایلهای مسیر

Returns

bool

“واقعی” اگر تصویر می تواند از فایل مشخص شده بارگذاری شود؛ در غیر این صورت، “واقعی”.

Examples

این مثال تعیین می کند که آیا تصویر می تواند از یک فایل بارگذاری شود.

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

CanLoad(بایگانی برچسب: LoadOptions)

تعیین می کند که آیا تصویر می تواند از مسیر فایل مشخص شده بارگذاری شود و به صورت اختیاری با استفاده از گزینه های باز مشخص شده.

public static bool CanLoad(string filePath, LoadOptions loadOptions)

Parameters

filePath string

فایلهای مسیر

loadOptions LoadOptions

گزینه های بارگیری

Returns

bool

“واقعی” اگر تصویر می تواند از فایل مشخص شده بارگذاری شود؛ در غیر این صورت، “واقعی”.

CanLoad(Stream)

تعیین می کند که آیا تصویر می تواند از جریان مشخص شده بارگذاری شود.

public static bool CanLoad(Stream stream)

Parameters

stream Stream

جریان برای بارگذاری

Returns

bool

“واقعی” اگر تصویر می تواند از جریان مشخص شده بارگذاری شود؛ در غیر این صورت، “واقعی”.

Examples

این مثال تعیین می کند که آیا تصویر می تواند از یک جریان فایل بارگذاری شود.

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

                                                                                  bool canLoad;

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

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

CanLoad(جریان، LoadOptions)

تعیین می کند که آیا تصویر می تواند از جریان مشخص شده بارگذاری شود و به صورت اختیاری با استفاده از loadOptions".

public static bool CanLoad(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

جریان برای بارگذاری

loadOptions LoadOptions

گزینه های بارگیری

Returns

bool

“واقعی” اگر تصویر می تواند از جریان مشخص شده بارگذاری شود؛ در غیر این صورت، “واقعی”.

CanSave(ImageOptionsBase)

تعیین می کند که آیا تصویر می تواند به فرمت فایل مشخص شده نشان داده شده توسط گزینه های ذخیره شده گذشته ذخیره شود.

public bool CanSave(ImageOptionsBase options)

Parameters

options ImageOptionsBase

گزینه های ذخیره سازی برای استفاده

Returns

bool

“واقعی” اگر تصویر را می توان به فرمت فایل مشخص شده نشان داده شده توسط گزینه های ذخیره شده؛ در غیر این صورت، “دروغ”.

Examples

این مثال نشان می دهد که چگونه می توان مشخص کرد که آیا تصویر می تواند به فرمت فایل مشخص شده نشان داده شده توسط گزینه های ذخیره شده گذشته ذخیره شود.

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

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

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

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

چند صفحه گزینه ها را ایجاد می کند.

Returns

Image

تصویر چند صفحه ای

Create(String[ ], بول)

ایجاد تصویر چند صفحه ای که حاوی فایل های مشخص شده است.

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

Parameters

files string [ ]

فایل ها را

throwExceptionOnLoadError bool

اگر به «واقعی» تنظیم شده است [به استثنای خطای بار بردارید].

Returns

Image

تصویر چند صفحه ای

Create(String[])

ایجاد تصویر چند صفحه ای که حاوی فایل های مشخص شده است.

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(موضوع[])

گزینه های پیش فرض را انتخاب کنید.

public virtual ImageOptionsBase GetDefaultOptions(object[] args)

Parameters

args object [ ]

این استدلال ها

Returns

ImageOptionsBase

گزینه های پیش فرض

GetFileFormat(String)

فرمت فایل را دریافت کنید.

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

به دست آوردن یک دایره ای که با بیت مپ فعلی مطابقت دارد با در نظر گرفتن پیکسل های گذشت. تعداد پیکسل های گذشت باید برابر با اندازه دایره ای مناسب باشد.

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

Parameters

rectangle Rectangle

به سمت راست به سمت راست به سمت راست به سمت راست

pixels int [ ]

پیکسل های 32 بیتی ARGB

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

پیکسل های 32 بیتی ARGB

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 با 8 بیتی در هر پیکسل تولید خواهد شد.برای جلوگیری از آن و ذخیره تصویر PNG با 1 بیتی در هر پیکسل، از این روش برای به دست آوردن گزینه های ذخیره مناسب و عبور آنها استفاده کنید.به روش Aspose.Imaging.Image.Save(System.String،Aspose.Imaging.ImageOptionsBase) به عنوان پارامتر دوم.

public virtual ImageOptionsBase GetOriginalOptions()

Returns

ImageOptionsBase

گزینه های مبتنی بر تنظیمات فایل اصلی.

GetProportionalHeight(int، int، int، int)

یک ارتفاع نسبی به دست می آورد.

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

Parameters

width int

در عرض

height int

ارتفاع است.

newWidth int

عرض جدید است.

Returns

int

ارتفاع متناسب است.

GetProportionalWidth(int، int، int، int)

به اندازه کافی نسبتا گسترده است.

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

Parameters

width int

در عرض

height int

ارتفاع است.

newHeight int

ارتفاع جدید است.

Returns

int

عرض متناسب

GetSerializedStream(ImageOptionsBase، Rectangle، خارج از int)

تبدیل به APS

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

Parameters

imageOptions ImageOptionsBase

گزینه های تصویر

clippingRectangle Rectangle

دایره ی مستطیل

pageNumber int

شماره صفحه

Returns

Stream

جریان سریالی

Load(بایگانی برچسب: LoadOptions)

اگر filePath" یک مسیر فایل است، این روش فقط فایل را باز می کند.اگر filePath" یک URL است، این روش فایل را دانلود می کند، آن را به عنوان یک مسیر موقت ذخیره می کند و آن را باز می کند.

public static Image Load(string filePath, LoadOptions loadOptions)

Parameters

filePath string

مسیر فایل یا URL برای بارگذاری تصویر از.

loadOptions LoadOptions

گزینه های بارگیری

Returns

Image

تصویر بارگذاری شده

Load(String)

اگر filePath" یک مسیر فایل است، این روش فقط فایل را باز می کند.اگر filePath" یک URL است، این روش فایل را دانلود می کند، آن را به عنوان یک مسیر موقت ذخیره می کند و آن را باز می کند.

public static Image Load(string filePath)

Parameters

filePath string

مسیر فایل یا URL برای بارگذاری تصویر از.

Returns

Image

تصویر بارگذاری شده

Examples

این مثال نشان دهنده بارگذاری یک فایل تصویر موجود به یک مثال از Aspose.Imaging.Image با استفاده از مسیر فایل مشخص شده است.

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

Load(جریان، LoadOptions)

یک تصویر جدید از جریان مشخص شده بارگذاری می شود.

public static Image Load(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

جریان برای بارگذاری تصویر از.

loadOptions LoadOptions

گزینه های بارگیری

Returns

Image

تصویر بارگذاری شده

Load(Stream)

یک تصویر جدید از جریان مشخص شده بارگذاری می شود.

public static Image Load(Stream stream)

Parameters

stream Stream

جریان برای بارگذاری تصویر از.

Returns

Image

تصویر بارگذاری شده

Examples

این مثال نشان دهنده استفاده از اشیاء System.IO.Stream برای بارگذاری یک فایل تصویر موجود است.

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

OnPaletteChanged(بایگانی برچسب ها: IColorPalette)

هنگامی که پالت تغییر می کند.

protected virtual void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

پالت قدیمی

newPalette IColorPalette

پالت جدید است.

OnPaletteChanging(بایگانی برچسب ها: IColorPalette)

هنگامی که پالت تغییر می کند.

protected virtual void OnPaletteChanging(IColorPalette oldPalette, IColorPalette newPalette)

Parameters

oldPalette IColorPalette

پالت قدیمی

newPalette IColorPalette

پالت جدید است.

ReleaseManagedResources()

منابع مدیریت شده را رها کنید اطمینان حاصل کنید که منابع غیر مدیریت شده در اینجا رها نمی شوند، زیرا ممکن است در حال حاضر رها شده باشند.

protected override void ReleaseManagedResources()

RemoveMetadata()

حذف متابولیسم

public virtual void RemoveMetadata()

Resize(int، int)

به صورت پیش فرض 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());
                                                        }

تصویر را با استفاده از نوع Resize خاص بازسازی کنید.

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

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

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

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

این مثال یک تصویر 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

تصویر را با استفاده از نوع Resize خاص بازسازی کنید.

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

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

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

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

تصویر 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(بایگانی برچسب ها: Resize)

ارتفاع را به صورت نسبی کاهش دهید.

public virtual void ResizeHeightProportionally(int newHeight, ResizeType resizeType)

Parameters

newHeight int

ارتفاع جدید است.

resizeType ResizeType

نوع بازسازی است.

Examples

این مثال یک تصویر را بارگذاری می کند و آن را به صورت نسبی با استفاده از روش های مختلف بازتاب می کند.تنها ارتفاع مشخص می شود، عرض به طور خودکار محاسبه می شود.

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

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

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

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

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

استفاده از یک ماسک بخش برای سرعت بخشیدن به فرآیند

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

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

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

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

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

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

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

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

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

ResizeHeightProportionally(برچسب ها: ImageResizeSettings)

ارتفاع را به صورت نسبی کاهش دهید.

public virtual void ResizeHeightProportionally(int newHeight, ImageResizeSettings settings)

Parameters

newHeight int

ارتفاع جدید است.

settings ImageResizeSettings

تصویر تنظیمات را بازسازی می کند.

ResizeWidthProportionally(int)

به طور پیش فرض Aspose.Imaging.ResizeType.NearestNeighbourResample استفاده می شود.

public void ResizeWidthProportionally(int newWidth)

Parameters

newWidth int

عرض جدید است.

ResizeWidthProportionally(بایگانی برچسب ها: Resize)

به طور نسبی پهنای باند را کاهش دهید.

public virtual void ResizeWidthProportionally(int newWidth, ResizeType resizeType)

Parameters

newWidth int

عرض جدید است.

resizeType ResizeType

نوع بازسازی است.

Examples

این مثال یک تصویر را بارگذاری می کند و آن را به صورت نسبی با استفاده از روش های مختلف بازتاب می کند.تنها عرض مشخص می شود، ارتفاع به طور خودکار محاسبه می شود.

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

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

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

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

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

ResizeWidthProportionally(برچسب ها: ImageResizeSettings)

به طور نسبی پهنای باند را کاهش دهید.

public virtual void ResizeWidthProportionally(int newWidth, ImageResizeSettings settings)

Parameters

newWidth int

عرض جدید است.

settings ImageResizeSettings

تصویر تنظیمات را بازسازی می کند.

Rotate(کشتی)

چرخش تصویر در اطراف مرکز

public virtual void Rotate(float angle)

Parameters

angle float

زاویه چرخش در درجه ها، ارزش های مثبت به صورت ساعت چرخش می کنند.

RotateFlip(RotateFlipType)

چرخش، چرخش یا چرخش و چرخش تصویر.

public abstract void RotateFlip(RotateFlipType rotateFlipType)

Parameters

rotateFlipType RotateFlipType

نوع فلیپ چرخشی

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 کامل یا بخشی از آن را به یک فایل یا جریان ذخیره کنید.

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

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

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

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

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

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

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

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

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

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

Save(String)

تصویر را به محل مشخص شده فایل ذخیره کنید.

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 با استفاده از مسیر فایل ذخیره می کنیم.

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

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

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

مثال زیر نشان می دهد که چگونه یک تصویر BMP کامل یا بخشی از آن را به یک فایل یا جریان ذخیره کنید.

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

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

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

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

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

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

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

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

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

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

Save(ردیف، ImageOptionsBase، Rectangle)

ذخیره داده های اشیاء به محل فایل مشخص شده در فرمت فایل مشخص شده با توجه به گزینه های ذخیره شده.

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

Parameters

filePath string

فایلهای مسیر

options ImageOptionsBase

گزینه ها را

boundsRectangle Rectangle

تصویر مقصد مستطیل را محدود می کند. مستطیل خالی را برای استفاده از مرزهای منبع تنظیم کنید.

Examples

مثال زیر یک تصویر BMP را از یک فایل بارگذاری می کند و سپس یک بخش مستطیل از تصویر را به یک فایل PNG ذخیره می کند.

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

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

مثال زیر نشان می دهد که چگونه یک تصویر BMP کامل یا بخشی از آن را به یک فایل یا جریان ذخیره کنید.

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

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

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

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

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

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

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

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

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

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

Exceptions

ArgumentNullException

گزینه ها

ImageSaveException

نجات تصویر شکست خورده است

Save(جریان، ImageOptionsBase)

ذخیره داده های تصویر به جریان مشخص شده در فرمت فایل مشخص شده با توجه به گزینه های ذخیره شده.

public void Save(Stream stream, ImageOptionsBase optionsBase)

Parameters

stream Stream

جریان برای ذخیره اطلاعات تصویر به.

optionsBase ImageOptionsBase

گزینه های ذخیره سازی

Examples

مثال زیر یک تصویر را از یک فایل بارگذاری می کند، سپس تصویر را به یک جریان فایل PNG ذخیره می کند.

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

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

این مثال فرآیند ذخیره یک تصویر را به MemoryStream نشان می دهد.برای نشان دادن این عمل، نمونه یک فایل موجود را از یک مکان دیسک بارگذاری می کند، عملیات چرخش را بر روی تصویر انجام می دهد و تصویر را در فرمت PSD ذخیره می کند.

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

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

مثال زیر نشان می دهد که چگونه یک تصویر BMP کامل یا بخشی از آن را به یک فایل یا جریان ذخیره کنید.

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

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

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

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

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

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

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

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

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

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

Exceptions

ArgumentNullException

گزینه ها

ArgumentException

نمی توان به فرمت مشخص شده ذخیره کرد زیرا در حال حاضر پشتیبانی نمی شود؛ گزینه ها

ImageSaveException

صادرات تصویر شکست خورده است.

Save(جریان، ImageOptionsBase، Rectangle)

ذخیره داده های تصویر به جریان مشخص شده در فرمت فایل مشخص شده با توجه به گزینه های ذخیره شده.

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

Parameters

stream Stream

جریان برای ذخیره اطلاعات تصویر به.

optionsBase ImageOptionsBase

گزینه های ذخیره سازی

boundsRectangle Rectangle

تصویر مقصد مستطیل را محدود می کند. مستطیل خالی را برای استفاده از مرزهای منبع تنظیم کنید.

Examples

مثال زیر یک تصویر را از یک فایل بارگذاری می کند، سپس یک بخش مستطیل از تصویر را به یک جریان فایل PNG ذخیره می کند.

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

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

مثال زیر نشان می دهد که چگونه یک تصویر BMP کامل یا بخشی از آن را به یک فایل یا جریان ذخیره کنید.

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

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

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

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

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

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

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

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

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

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

Exceptions

ArgumentNullException

گزینه ها

ArgumentException

نمی توان به فرمت مشخص شده ذخیره کرد زیرا در حال حاضر پشتیبانی نمی شود؛ گزینه ها

ImageSaveException

صادرات تصویر شکست خورده است.

SetPalette(بایگانی برچسب ها: bool)

پالت تصویر را نصب کنید.

public abstract void SetPalette(IColorPalette palette, bool updateColors)

Parameters

palette IColorPalette

پالت را تنظیم کنید.

updateColors bool

اگر به رنگ های “واقعی” تنظیم شده باشد، با توجه به پالت جدید به روز خواهد شد؛ در غیر این صورت شاخص های رنگی بدون تغییر باقی می مانند. توجه داشته باشید که شاخص های بدون تغییر ممکن است تصویر در بارگذاری شکسته شود اگر برخی از شاخص ها ورودی های پالت مربوطه ندارند.

UpdateContainer(Image)

کنتینر را به روز کنید

protected void UpdateContainer(Image container)

Parameters

container Image

این کانتینر

همچنین ببینید

DataStreamSupporter , IObjectWithBounds

 فارسی