WebPImage

WebPImage(Stream)

Initierar en ny instans avWebPImage class från stream.

public WebPImage(Stream stream)
ParameterTypBeskrivning
streamStreamStreamen WebP-bilden.

Exempel

Det här exemplet visar hur man laddar en WebP-bild från en filström och sparar den i PNG.

[C#]

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

// Ladda en WebP-bild från en filström.
using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "test.webp"))
using (Aspose.Imaging.FileFormats.Webp.WebPImage webPImage = new Aspose.Imaging.FileFormats.Webp.WebPImage(stream))
{
    // Spara till PNG
    // Observera att endast den aktiva ramen kommer att lagras i PNG, eftersom PNG inte är ett flersidigt format.
    webPImage.Save(dir + "test.output.png", new Aspose.Imaging.ImageOptions.PngOptions());
}

Se även


WebPImage(Stream, LoadOptions)

Initierar en ny instans avWebPImage klass från stream.

public WebPImage(Stream stream, LoadOptions loadOptions)
ParameterTypBeskrivning
streamStreamStreamen WebP-bilden.
loadOptionsLoadOptionsLastalternativen.

Se även


WebPImage(string)

Initierar en ny instans avWebPImage klass från fil.

public WebPImage(string path)
ParameterTypBeskrivning
pathStringSökvägen till filen WebP Image

Exempel

Det här exemplet visar hur man laddar en WebP-bild från en fil och sparar den i PNG.

[C#]

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

// Ladda en WebP-bild från en fil.
using (Aspose.Imaging.FileFormats.Webp.WebPImage webPImage = new Aspose.Imaging.FileFormats.Webp.WebPImage(dir + "test.webp"))
{
    // Spara till PNG
    // Observera att endast den aktiva ramen kommer att lagras i PNG, eftersom PNG inte är ett flersidigt format.
    webPImage.Save(dir + "test.output.png", new Aspose.Imaging.ImageOptions.PngOptions());
}

Se även


WebPImage(string, LoadOptions)

Initierar en ny instans avWebPImage klass från fil.

public WebPImage(string path, LoadOptions loadOptions)
ParameterTypBeskrivning
pathStringSökvägen till filen WebP Image
loadOptionsLoadOptionsLastalternativen.

Se även


WebPImage(RasterImage)

Initierar en ny instans avWebPImage klass från rasterImage.

public WebPImage(RasterImage rasterImage)
ParameterTypBeskrivning
rasterImageRasterImageRasterbilden.

Exempel

Det här exemplet visar hur man skapar en WebP-bild från en annan rasterbild.

[C#]

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

// Ladda en PNG-bild på 100x100 px.
using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(100, 100))
{
    Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);

    // Fyll hela bilden i rött.
    Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
    graphics.FillRectangle(brush, pngImage.Bounds);

    // Skapa en WebP-bild baserad på PNG-bilden.
    using (Aspose.Imaging.FileFormats.Webp.WebPImage webPImage = new Aspose.Imaging.FileFormats.Webp.WebPImage(pngImage))
    {
        // Spara till en WebP-fil med standardalternativ
        webPImage.Save(dir + "output.webp", new Aspose.Imaging.ImageOptions.WebPOptions());
    }
}

Se även


WebPImage(RasterImage, LoadOptions)

Initierar en ny instans avWebPImage klass från rasterImage.

public WebPImage(RasterImage rasterImage, LoadOptions loadOptions)
ParameterTypBeskrivning
rasterImageRasterImageRasterbilden.
loadOptionsLoadOptionsLastalternativen.

Se även


WebPImage(int, int, WebPOptions)

Initierar en ny instans avWebPImage klass med tom bild.

public WebPImage(int width, int height, WebPOptions options)
ParameterTypBeskrivning
widthInt32Bildens bredd
heightInt32Bildhöjden.
optionsWebPOptionsAlternativen.

Exempel

Det här exemplet visar hur man skapar en WebP-bild med de angivna alternativen från början.

[C#]

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

Aspose.Imaging.ImageOptions.WebPOptions createOptions = new Aspose.Imaging.ImageOptions.WebPOptions();
createOptions.Lossless = true;
createOptions.Quality = 100f;
//createOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(dir + "output.webp");

// Skapa en WebP-bild på 100x100 px.
using (Aspose.Imaging.FileFormats.Webp.WebPImage webPImage = new Aspose.Imaging.FileFormats.Webp.WebPImage(100, 100, createOptions))
{
    Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(webPImage);

    // Fyll hela bilden i rött.
    Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
    graphics.FillRectangle(brush, webPImage.Bounds);

    // Spara till en WebP-fil
    webPImage.Save(dir + "output.webp");
}

Det här exemplet visar hur man skapar en animerad WebP-bild med flera ramar med de angivna alternativen.

[C#]

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

Aspose.Imaging.ImageOptions.WebPOptions createOptions = new Aspose.Imaging.ImageOptions.WebPOptions();
createOptions.Lossless = true;
createOptions.Quality = 100f;
createOptions.AnimBackgroundColor = (uint)Aspose.Imaging.Color.Gray.ToArgb();

// Standardramen plus 36 + 36 ytterligare ramar.
createOptions.AnimLoopCount = 36 + 36 + 1;

// Skapa en WebP-bild på 100x100 px.
using (Aspose.Imaging.FileFormats.Webp.WebPImage webPImage = new Aspose.Imaging.FileFormats.Webp.WebPImage(100, 100, createOptions))
{
    // Den första cirkeln är röd
    Aspose.Imaging.Brushes.SolidBrush brush1 = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);

    // Den andra cirkeln är svart
    Aspose.Imaging.Brushes.SolidBrush brush2 = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Black);

    // Öka gradvis vinkeln på den röda bågen.
    for (int angle = 10; angle <= 360; angle += 10)
    {
        Aspose.Imaging.FileFormats.Webp.WebPFrameBlock block = new Aspose.Imaging.FileFormats.Webp.WebPFrameBlock(100, 100);
        Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(block);
        graphics.FillPie(brush1, block.Bounds, 0, angle);

        webPImage.AddBlock(block);
    }

    // Öka gradvis vinkeln på den svarta bågen och torka ut den röda bågen.
    for (int angle = 10; angle <= 360; angle += 10)
    {
        Aspose.Imaging.FileFormats.Webp.WebPFrameBlock block = new Aspose.Imaging.FileFormats.Webp.WebPFrameBlock(100, 100);

        Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(block);
        graphics.FillPie(brush2, block.Bounds, 0, angle);
        graphics.FillPie(brush1, block.Bounds, angle, 360 - angle);

        webPImage.AddBlock(block);
    }

    // Spara till en WebP-fil
    webPImage.Save(dir + "output.webp");
}

Se även


WebPImage(int, int, WebPOptions, LoadOptions)

Initierar en ny instans avWebPImage klass med tom bild.

public WebPImage(int width, int height, WebPOptions options, LoadOptions loadOptions)
ParameterTypBeskrivning
widthInt32Bildens bredd
heightInt32Bildhöjden.
optionsWebPOptionsAlternativen.
loadOptionsLoadOptionsLastalternativen.

Se även