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

[BUG] <Image background color is different for Jpeg compared to PNG in Xamarin android> #2798

Open
1 task done
Yaavannvignesh opened this issue Mar 14, 2024 · 0 comments
Open
1 task done
Labels

Comments

@Yaavannvignesh
Copy link

Yaavannvignesh commented Mar 14, 2024

Description

We used SkiaSharp in the Xamarin Android platform to create a bitmap and applied a red background color to specific rectangles. We saved the bitmap as both PNG and JPEG image formats. However, we noticed that the JPEG image displays a different background color than the PNG image. This issue only occurs in Xamarin Android, as the background color displays correctly in both PNG and JPEG formats on Windows. Please check and update details

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:

using (var bitmap = new SKBitmap(100, 100))
{
    // Create SKCanvas with the bitmap
    using (var canvas = new SKCanvas(bitmap))
    {
        // Define rectangle parameters
        SKRect rectBounds = new SKRect(0, 0, 100, 100);
        SKPaint paint = new SKPaint
        {
            Color = new SKColor(255, 0, 0, 255)
        };

        // Draw the rectangle on the canvas
        canvas.DrawRect(rectBounds, paint);
    }

    // Create a MemoryStream to hold the image data
    var imageStream = new MemoryStream();
    bitmap.Encode(SKEncodedImageFormat.Jpeg, 100).SaveTo(imageStream);
    imageStream.Position = 0;

    return imageStream;
}

You can also share some XAML:

<!-- xaml code here -->

Expected Behavior

The image's background color should match the PNG.

Actual Behavior

The Background color should match the PNG image.

Version of SkiaSharp

2.88.6

Last Known Good Version of SkiaSharp

2.88.6

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Android

Platform / Operating System Version

Android

Devices

Oppo

Relevant Screenshots

https://github.com/mono/SkiaSharp/assets/131945130/dcfff30a-013a-444d-bd05-22e098091a08

Relevant Log Output

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABHNCSVQICAgIfAhkiAAAAQBJREFUeJzt0UENACAQwLAD/57hjQL2aBUs2TozZ8jYvwN4GRJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSIwhMYbEGBJjSMwF7EwCxk+5tz8AAAAASUVORK5CYII=">

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
None yet
Development

No branches or pull requests

1 participant