PngImage

PngImage(int, int)

يقوم بتهيئة مثيل جديد لملفPngImage فئة .

public PngImage(int width, int height)
معامليكتبوصف
widthInt32العرض .
heightInt32الارتفاع .

أمثلة

يوضح هذا المثال كيفية إنشاء صورة PNG بالحجم المحدد ، وتعبئتها بلون خالص وحفظها في ملف.

[C#]

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

// أنشئ صورة PNG بحجم 100 × 100 بكسل.
using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(100, 100))
{
    // قم ببعض عمليات معالجة الصور ، على سبيل المثال ، املأ الصورة بأكملها باللون الأحمر.
    Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
    Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
    graphics.FillRectangle(brush, pngImage.Bounds);

    // حفظ في ملف.
    pngImage.Save(dir + "output.png");
}

أنظر أيضا


PngImage(string)

يقوم بتهيئة مثيل جديد لملفPngImage فئة .

public PngImage(string path)
معامليكتبوصف
pathStringمسار تحميل صورة .

أمثلة

يوضح هذا المثال كيفية تحميل صورة PNG من ملف.

[C#]

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

// تحميل صورة PNG من ملف.
using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(dir + "sample.png"))
{
    // تحويل الصورة إلى تمثيل تدرج الرمادي
    pngImage.Grayscale();

    // حفظ في ملف.
    pngImage.Save(dir + "sample.grayscale.png");
}

أنظر أيضا


PngImage(RasterImage)

يقوم بتهيئة مثيل جديد لملفPngImage فئة .

public PngImage(RasterImage rasterImage)
معامليكتبوصف
rasterImageRasterImageالصورة النقطية .

أمثلة

يوضح هذا المثال كيفية تحميل صورة PNG من صورة BMP.

[C#]

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

// قم بتحميل صورة TrueColor PNG من صورة BMP.
// أولاً ، قم بإنشاء صورة BMP مؤقتة والتي ستكون أساسًا لبناء صورة PNG.
// يمكنك أيضًا تحميل صورة BMP من ملف أو استخدام صورة بأي تنسيق نقطي آخر.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100))
{
    // املأ صورة BMP بالكامل باللون الأحمر.
    Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
    Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
    gr.FillRectangle(brush, bmpImage.Bounds);

    using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(bmpImage))
    {
        System.Console.WriteLine("The PNG color type: {0}", pngImage.GetOriginalOptions());
        pngImage.Save(dir + "output.png");
    }
}

أنظر أيضا


PngImage(string, PngColorType)

يقوم بتهيئة مثيل جديد لملفPngImage فئة .

public PngImage(string path, PngColorType colorType)
معامليكتبوصف
pathStringمسار تحميل صورة .
colorTypePngColorTypeنوع اللون .

استثناءات

استثناءحالة
ArgumentNullException

أمثلة

يوضح هذا المثال كيفية تحميل صورة PNG من ملف بنوع اللون المحدد.

[C#]

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

// تحميل صورة PNG من ملف.
// لاحظ أنه سيتم تحويل الصورة الملونة إلى تدرج الرمادي تلقائيًا.
using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(dir + "sample.png", Aspose.Imaging.FileFormats.Png.PngColorType.Grayscale))
{
    // حفظ في ملف.
    pngImage.Save(dir + "sample.grayscale.png");
}

أنظر أيضا


PngImage(RasterImage, PngColorType)

يقوم بتهيئة مثيل جديد لملفPngImage فئة .

public PngImage(RasterImage rasterImage, PngColorType colorType)
معامليكتبوصف
rasterImageRasterImageالصورة النقطية .
colorTypePngColorTypeنوع اللون .

أمثلة

يوضح هذا المثال كيفية تحميل صورة PNG من صورة BMP بنوع اللون المحدد.

[C#]

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

// قم بتحميل صورة PNG ذات تدرج رمادي من صورة BMP ملونة.
// أولاً ، قم بإنشاء صورة BMP مؤقتة والتي ستكون أساسًا لبناء صورة PNG.
// يمكنك أيضًا تحميل صورة BMP من ملف أو استخدام صورة بأي تنسيق نقطي آخر.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100))
{
    // املأ صورة BMP بالكامل باللون الأحمر.
    Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
    Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
    gr.FillRectangle(brush, bmpImage.Bounds);

    // سيتم تحويل ألوان بكسلات الصورة إلى نظيراتها ذات التدرج الرمادي.
    using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(bmpImage, Aspose.Imaging.FileFormats.Png.PngColorType.Grayscale))
    {
        pngImage.Save(dir + "output.grayscale.png");
    }
}

أنظر أيضا


PngImage(Stream)

يقوم بتهيئة مثيل جديد لملفPngImage فئة .

public PngImage(Stream stream)
معامليكتبوصف
streamStreamالدفق لتحميل صورة .

أمثلة

يوضح هذا المثال كيفية تحميل صورة PNG من ملف أو تدفق ملف.

[C#]

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

// تحميل صورة PNG من دفق ملف.
using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.png"))
{
    using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(stream))
    {
        // تحويل الصورة إلى تمثيل تدرج الرمادي
        pngImage.Grayscale();

        // حفظ في ملف.
        pngImage.Save(dir + "sample.grayscale.png");
    }
}

أنظر أيضا


PngImage(int, int, PngColorType)

يقوم بتهيئة مثيل جديد لملفPngImage فئة .

public PngImage(int width, int height, PngColorType colorType)
معامليكتبوصف
widthInt32العرض .
heightInt32الارتفاع .
colorTypePngColorTypeنوع اللون .

أمثلة

يوضح هذا المثال كيفية إنشاء صورة PNG بالحجم المحدد بنوع اللون المحدد ، وتعبئته بلون خالص وحفظه في ملف.

[C#]

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

// إنشاء صورة PNG بتدرج الرمادي بحجم 100 × 100 بكسل.
// سيتم تحويل جميع الألوان تلقائيًا إلى تنسيق التدرج الرمادي.
using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(100, 100, Aspose.Imaging.FileFormats.Png.PngColorType.Grayscale))
{
    // قم ببعض عمليات معالجة الصور ، على سبيل المثال ، املأ الصورة بأكملها باللون الأحمر.
    Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
    Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
    graphics.FillRectangle(brush, pngImage.Bounds);

    // حفظ في ملف.
    pngImage.Save(dir + "output.grayscale.png");
}

أنظر أيضا


PngImage(PngOptions, int, int)

يقوم بتهيئة مثيل جديد لملفPngImage فئة .

public PngImage(PngOptions pngOptions, int width, int height)
معامليكتبوصف
pngOptionsPngOptionsخيارات png .
widthInt32العرض .
heightInt32الارتفاع .

أمثلة

يوضح هذا المثال كيفية إنشاء صورة PNG بالخيارات المحددة ، وتعبئتها بألوان متدرجة خطية وحفظها في ملف.

[C#]

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

Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();

// عدد البتات لكل قناة لون
createOptions.BitDepth = 8;

// كل بكسل عبارة عن ثلاثية (حمراء ، خضراء ، زرقاء) متبوعة بمكون ألفا.
createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

// الحد الأقصى لمستوى الضغط.
createOptions.CompressionLevel = 9;

// يسمح استخدام المرشحات بضغط الصور ذات الدرجة اللونية المستمرة بشكل أكثر فعالية.
createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;

// استخدم التحميل التدريجي
createOptions.Progressive = true;

// إنشاء صورة PNG مع معلمات مخصصة.
using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(createOptions, 100, 100))
{
    Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
            new Aspose.Imaging.Point(0, 0),
            new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
            Aspose.Imaging.Color.Blue,
            Aspose.Imaging.Color.Transparent);

    Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);

    // املأ الصورة بتدرج شبه شفاف.
    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

    // حفظ في ملف.
    pngImage.Save(dir + "output.explicitoptions.png");
}

أنظر أيضا