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

I need to remove transparency from a PNG and replace White background #33

Closed
zhongkon opened this issue Nov 1, 2021 · 1 comment
Closed

Comments

@zhongkon
Copy link

zhongkon commented Nov 1, 2021

I need to remove transparency from a PNG and replace with white background. the commented out lines are things I have tried. it just keeps coming out transparent.

Imports SkiaSharp
Imports SkiaSharp.QrCode.Image
Using output = New FileStream(Application.StartupPath & "geo.png", FileMode.OpenOrCreate)
Dim Code = New QrCode("test qr code", New Vector2Slim(256, 256), SKEncodedImageFormat.Png)
Code.GenerateImage(output)
End Using

@zhongkon
Copy link
Author

zhongkon commented Nov 1, 2021

`Private Function GenerateQrCode(ByVal content As String, ByVal width As Integer, ByVal height As Integer) As Byte()
Using generator = New QRCodeGenerator()
Dim qr = generator.CreateQrCode(content, ECCLevel.L)
Dim info = New SKImageInfo(width, height)

        Using surface = SKSurface.Create(info)
            Dim canvas = surface.Canvas
            canvas.Clear(SKColors.White)

            Using qrCodeRenderer = New QRCodeRenderer()
                Dim area As SKRect = SKRect.Create(0, 0, info.Width, info.Height)
                qrCodeRenderer.Render(canvas, area, qr, SKColors.Black)
            End Using

            Using image = surface.Snapshot()

                Using data = image.Encode(SKEncodedImageFormat.Png, 100)

                    Using stream = File.OpenWrite(Application.StartupPath & "/geo.png")
                        data.SaveTo(stream)
                    End Using
                    Return data.ToArray()
                End Using
            End Using
        End Using
    End Using
End Function`

@zhongkon zhongkon closed this as completed Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant