Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SKData was incorrect when encoding images in specific formats #3142

Open
1 task done
Krithika-G opened this issue Jan 16, 2025 · 0 comments
Open
1 task done

SKData was incorrect when encoding images in specific formats #3142

Krithika-G opened this issue Jan 16, 2025 · 0 comments
Labels

Comments

@Krithika-G
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: New
Development

No branches or pull requests

1 participant