Issue Displaying Bitmaps in Display Pipeline on macOS (Apple Silicon)

I’m developing a Rhino plugin that needs to display custom bitmaps in the Rhino viewport using a display conduit. While this works as expected on Windows, the bitmaps are not showing up in the display pipeline on macOS, specifically on Apple Silicon Macs. I’ve simplified my code to eliminate other potential factors, but the issue persists.

Here’s a basic example of what I’m trying to achieve:

using Rhino.Display;
using System.Drawing; //Common
using Rhino.DocObjects;

public class CustomDisplayConduit : DisplayConduit
{
    private DisplayBitmap _bitmap;

    protected override void DrawForeground(DrawForegroundEventArgs e)
    {
        if (_bitmap == null)
        {
            var image = new Bitmap(@"path_to_your_image.png");  // Also tried DrawingUtilities.BitmapFromIconResource()
            _bitmap = new DisplayBitmap(image);
        }

        if (_bitmap != null)
        {
            e.Display.DrawBitmap(_bitmap, 10, 10, 100, 100);
        }
    }
}

Details:

  • OS: macOS on Apple Silicon
  • Rhino Version: Rhino 8
  • Direct Bitmap Loading: Initially, I attempted to load bitmaps directly using System.Drawing.Bitmap, which displayed fine on Windows but not on macOS.
  • Using Rhino’s Drawing Utilities: I switched to using Rhino.UI.DrawingUtilities.BitmapFromIconResource to ensure the bitmaps are loaded in a manner that’s potentially more compatible with Rhino’s ecosystem. This approach also failed to display the bitmaps on macOS.
  • Simplification: I removed all scaling and dynamic positioning logic to rule out complexity as the cause. The issue remained.
  • Cross-Platform Verification: I’ve confirmed the code execution reaches the bitmap drawing logic on macOS through logging, suggesting the issue lies with the display or bitmap handling on macOS.

I’m looking for insights on why this issue might be occurring on macOS and how to resolve it. Any advice, or suggestions for further debugging, would be greatly appreciated.

Thank you in advance for your help!

Hi @Ryan_Johann1,

I’ve logged an issue so a developer can look into this.

https://mcneel.myjetbrains.com/youtrack/issue/RH-81192

Thanks,

– Dale

1 Like

Hi @Ryan_Johann1, i do only see 3 arguments (bitmap, left, top) in DrawBitmap

Could this be the issue ?
_
c.

Hi @clement

Thankyou for the response. Yes your right only 3 arguments, excuse the mistake in my example above. To be more specific this is the code example im trying out now but still no luck.

public class CustomDisplayConduit : DisplayConduit
{
    private DisplayBitmap _bitmap;

    protected override void DrawForeground(DrawForegroundEventArgs e)
    {
        if (_bitmap == null)
        {
            var svgResourceName = GetType().Assembly.GetManifestResourceNames().
                FirstOrDefault(x => x.Contains("my_svg"));

            using var stream = GetType().Assembly.GetManifestResourceStream(svgResourceName);
            using var reader = new StreamReader(stream);
            var svgContent = reader.ReadToEnd();

            var bitmap = DrawingUtilities.BitmapFromSvg(svgContent, 24, 24, true);
            
            _bitmap = new DisplayBitmap(bitmap);
        }

        if (_bitmap != null)
        {
            int contentX = 10;
            int contentY = 10;

            e.Display.DrawBitmap(_bitmap, contentX, contentY);
        }
    }
}

For more context. Previously my plugin was target net48 for Rhino 6, im now targeting net7 for Rhino 8. This is my rhinocommon package im targeting.

Previously when the plugin was targeting Rhino 6 i was use a png from my Resources e.g Resources.myImage, then i was scaling that bitmap with this code.

    public static Bitmap ResizeImage(this Image image, int width, int height)
    {
        var destRect = new Rectangle(0, 0, width, height);
        var destImage = new Bitmap(width, height);

        destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

        using (var graphics = Graphics.FromImage(destImage))
        {
            graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
            graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

            using (var wrapMode = new ImageAttributes())
            {
                wrapMode.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
                graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
            }
        }

        return destImage;
    }

But that code doesn’t work on macos hence im trying the first block of code.

Id like to add ive also tried just using the bitmap straight (not scaling) but still had no success.

My final goal is to draw a bitmap in the viewport but also have the ability to scale it based on the viewports dpi. Working on Windows and Mac for Rhino 8.

Thanks

The display pipeline bitmap drawing routines in RhinoCommon have only been written for OpenGL so they will fail on Mac. We need to write a metal version of the code to get things working.

@stevebaer thankyou for the quick response!

We are writing a cross-platform plugin and our Mac user base has been increasing. So we would defiantly be looking for this feature. Please keep me updated when it is supported for Mac.

Thankyou.