Skip to content

SKData was incorrect when encoding images in specific formats #3142

Open
@Krithika-G

Description

Description

We created an SKBitmap and drew a rectangle on it. The SKBitmap was then converted to an SKImage and subsequently to SKData. However, we encountered an issue while converting to SKData for specific formats such as BMP, GIF, ICO, WBMP, PKM, KTX, ASTC, DNG, HEIF, and AVIF. This issue does not occur when using formats such as JPG, PNG, and WEBP.

Platform: ASP.NET Core
Visual Studio Version: 2022
.NET Version: .NET 8
SkiaSharp Version: 2.88.8

Code

The best way to share code for larger projects is a link to a GitHub repository: https://github.com/user/repo/tree/bug-123

But, you can also share a short block of code here:

public void Convert()
{
    // Example dimensions
    int width = 200;
    int height = 100;

    // Create a new SKBitmap instance
    using (var bitmap = new SKBitmap(width, height))
    {
        // Perform operations with the bitmap, such as drawing
        using (var canvas = new SKCanvas(bitmap))
        {
            // Example: draw a red rectangle
            canvas.Clear(SKColors.White); // Clear with white background
            using (var paint = new SKPaint())
            {
                paint.Color = SKColors.Red;
                canvas.DrawRect(new SKRect(50, 20, 150, 80), paint);
            }
        }
        Stream stream = new MemoryStream();
        SKImage image = SKImage.FromBitmap(bitmap);
        SKData data = image.Encode(SKEncodedImageFormat.Heif, 100);
        data.SaveTo(stream);
    }
}
// some C# code here

You can also share some XAML:

<!-- xaml code here -->

Expected Behavior

The program should run without any exceptions in formats such as BMP, GIF, ICO, WBMP, PKM, KTX, ASTC, DNG, HEIF, and AVIF.

Actual Behavior

Get an exception in specific formats other than formats such as JPG, PNG, and WEBP.

Version of SkiaSharp

2.88.8 (Deprecated)

Last Known Good Version of SkiaSharp

2.88.8 (Deprecated)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Windows 10

Devices

Dell 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz 1.38 GHz

Relevant Screenshots

No response

Relevant Log Output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions