CaptureToBitmap() antialiasing with transparent background wrong

Dear @jeff,

please can you create a bug-track for CaptureToBitmap().
(tested in Rhino 8 SR 21, and Rhino 9.0.25182.12305, 2025-07-01)

When I create a bitmap with transparent background, the antialiased pixels get a color change to black. Here a png from Rhino and Inkscape:

Here all project files: wrong_antialiasing.zip (788.2 KB)

Thank you

Michael

@Michael_Meyer - was Rhino 9 running in OpenGL or Direct3d display?

– Dale

Hi @dale,

I’ve tested now OpenGL and Direct3D in Rhino 9, no difference, I get the black border.

Thanks

Michael

I think I see what the problem is… I’ll get this fixed in both V8 and V9.

RH-88256

Thanks,
-Jeff

3 Likes

Too close to the RC release date… so this is going to have to go into the 8.x branch… Which means 8.22 is where you’ll see the fix… The next V9 WIP will have it in there though.

Thanks,
-Jeff

1 Like

RH-88256 is fixed in Rhino 8 Service Release 22

1 Like

Hi @jeff,

sorry, me again. :wink:

The color against transparent backgrounds is fixed. Now I have found that between two colors there is also a wrong color change to black/gray.

Here an example, which shows a transition between magenta, and green:

eggplant.3dm (65.0 KB)
save_2D_with_transparent_background_as_png_64x64.cs (1.2 KB)
eggplant_64x64

Can you take a look again?

Thanks

Michael

This isn’t Rhino doing this…it’s the MSAA (antialiasing) along edge boundaries that’s doing this. Mainly because you’re trying to capture AA’d results at a very, very low resolution, where pixels are rare.

The reason you’re getting gray is because one of the colors is made up of 2 of the primary colors (red and blue) RGB(1, 0, 1)… and the other color is made up of the 3rd primary color Green RGB(0, 1, 0). So when AA kicks in along those edges, it starts sampling and blending the surrounding colors…and some of those samples end up being 50% of color 1 and 50% of color 2… which means you get RGB(0.5, 0.0, 0.5) and RGB(0.0, 0.5, 0.0) … and when you add those two together, you get RGB(0.5, 0.5, 0.5) … i.e. Gray…and you’re also going to get variations therein… i.e. gradations

Here’s a screenshot of Rhino’s viewport zoomed out so that only a few pixels are used (note: I’ve zoomed into the screenshot in order to better show the results).

I’ve also then taken a screenshot at high resolution and then zoomed into it… The effect isn’t as noticeable since there are so many pixels, but the same issue is there…

Here’s the screenshot:

And here’s the zoomed in version…

In summary, the problem is:

  1. You’re using very, very low resolutions to capture AA’d output.
  2. You’re using colors that don’t really blend very well together, since they’re made up of all 3 pure primary colors.

There’s really nothing that I can think of to prevent this…especially since the AA is getting done by the drivers.

That being said, what you could try is to output your “parts” separately…at least the parts that share or have adjacent edges, and then blend and merge the two. However, you’re still going to get gray pixels somewhere along the boundaries simply because of the two colors you’re using… It’s just color arithmetic.. Magenta + Green = White … and any equal variations of those two colors is going to produce gradations of white/gray.

Here’s what I tried…

  1. I hid the pink portion and ran your script.
  2. I unhid the pink portion and hid the green and white portions and ran your script.
  3. I then merged the two results in an image processor.

1 Result:
image

#2 Result:
image

#3 final result:
image

The final result is better than what you get doing it all at once, but again, you’re still going to get gray pixels (or close to gray) due to the two colors you’re using.

And just to drive my point home here… I’ve captured only the green and white portions and then brought them into Photoshop on a separate layer. I then created a background layer and made it Magenta. As you can see, there are still variations of gray pixels that result in the two colors being blended. It’s better, but it still produces gradations of gray…It’s just how things work.

If you don’t want varying shades of gray in your AA’d results, then don’t use all three primary colors when (combined) with portions that will be adjacent with each other. Sorry, that’s all I can recommend atm.

-J

2 Likes

Dear @jeff,

thank you very much for your time, and your detailed look at my problem.

I didn’t realize that green and magenta mix to gray. You are right, to avoid this, I should reduce the Antialiasing (e.g. from 4x to 2x or none) between these colors in my lowres images.

I’ve learned something, thank you again

Michael