question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Artifacts on translucent WritableBitmap

See original GitHub issue

I drawed translucent WritableBitmap on Bitmap with alpha channel and catched some interesting artifacts. This problem reproduce on Skia and Win32, on Direct2D1 is OK. artefacts

View:

<Grid>
    <Image Source="{Binding Bitmap}" />
    <Image Source="{Binding Background}" />
</Grid>

ViewModel:

Background = new Bitmap(PATH_TO_BACKGROUND_FILE);

var data = new byte[256 * 256 * 4];
for (int y = 0; y < 256; y++) {
    for (int x = 0; x < 256; x++) {
        var pos = (y * 256 + x) * 4;
        data[pos] = 255;
        data[pos + 1] = 255;
        data[pos + 2] = 255;
        data[pos + 3] = 1;
    }
}

var writeableBitmap = new WriteableBitmap(256, 256, PixelFormat.Rgba8888);
using (var l = writeableBitmap.Lock()) {
    for (var r = 0; r < 256; r++) {
        Marshal.Copy(data, r * l.RowBytes, new IntPtr(l.Address.ToInt64() + r * l.RowBytes), l.RowBytes);
    }
}

WritableBitmap = writeableBitmap;

Background for example

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
ahoppercommented, Aug 20, 2019

I believe this is the same problem as https://github.com/AvaloniaUI/Avalonia/issues/2604 and that the alpha needs pre-multiplying for the WriteableBitmap. This is with pre mmultiplied alpha:-

writeablebitmapalpha
0reactions
kekekekscommented, Aug 20, 2019

https://github.com/AvaloniaUI/Avalonia/blob/f0a8e64189c7bf60ce7486a35e4a0a67ca644d18/src/Windows/Avalonia.Direct2D1/PrimitiveExtensions.cs#L99 we are using Format32bppPBGRA and Format32bppPRGBA pixel formats. Direct2D might be doing some preprocessing after image bits are unlocked.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SaveJpeg causing "shadows" artifacts with transparency
Just wanted to check one thing with you. I'm using WriteableBitmap to create an image that I'm as a live tile. Works fine...
Read more >
Artifacts in translucent mode - Rendering
Hi to all. I am having some troubles with a skirt I have in my scene when I am changing its material to...
Read more >
WriteableBitmapEx - RSSing.com
I am trying to apply an transparent image (in png format) over background image. The result is not very good as applied image...
Read more >
Silverlight and WriteableBitmap
I've just released a library to CodePlex that implements a feature missing from Silverlight: the ability to generate bitmaps from pixels in ...
Read more >
Rendering RadRichTextPageView to an Image
Hi Oliver, Rendering the document on an image using WriteableBitmap produces artifacts. We currently don't know of a way to render the document ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found