DrawingUtilities

public static class DrawingUtilities
RhinoCommon Drawing Utilities

Methods

BitmapFromIconResource

#Since v6.12
public static Bitmap BitmapFromIconResource(string resourceName, Assembly assembly = null)
Load a Icon from an embedded resource and convert it to a bitmap of the specified size. Will look for a icon image that is greater than or equal to the requested size, if all images are less than the requested size the largest image will be used.
resourceName (string)
assembly (Assembly = null)The assembly containing the manifest resource, will use the calling assembly if null.

BitmapFromIconResource

#Since v6.0
public static Bitmap BitmapFromIconResource(string resourceName, Size bitmapSize, Assembly assembly = null)
Load a Icon from an embedded resource and convert it to a bitmap of the specified size. Will look for a icon image that is greater than or equal to the requested size, if all images are less than the requested size the largest image will be used.
resourceName (string)
bitmapSize (Size)Desired bitmap size
assembly (Assembly = null)The assembly containing the manifest resource, will use the calling assembly if null.

BitmapFromSvg

#Since v8.0
public static Bitmap BitmapFromSvg(string svg, int width, int height, bool adjustForDarkMode)
Create bitmap of a given size from an svg string
svg (string)A valid svg string
width (int)Width of the svg in pixels
height (int)Height of the svg in pixels
adjustForDarkMode (bool)If true dark mode specific attributes will be used in the svg
A

BitmapFromSvg

#Since v7.6
public static Bitmap BitmapFromSvg(string svg, int width, int height)
Create bitmap of a given size from an svg string
svg (string)A valid svg string
width (int)Width of the svg in pixels
height (int)Height of the svg in pixels

CreateCurvePreviewGeometry

#Since v8.0
public static List<Point2f[]> CreateCurvePreviewGeometry(Curve curve, Linetype linetype, int width, int height)
Create a series of closed polyline loops representing a curve and a linetype combination.
curve (Curve)
linetype (Linetype)
width (int)
height (int)

CreateLinetypePreviewGeometryEx

#Since v9.0
public static List<Point2f[]> CreateLinetypePreviewGeometryEx(Curve curve, Linetype linetype, int width, int height, double linetypeScale, int kind)
Preview geometry for a linetype on a curve, by channel, mirroring the viewport renderer. kind 0 returns the dash silhouette polygons with the line cleared under each shape (these are meant to be filled); kind 1 returns curve shape outlines (meant to be stroked); kind 2 returns text and surface shape outlines (meant to be filled with an even-odd rule).
curve (Curve)
linetype (Linetype)
width (int)
height (int)
linetypeScale (double)Scale applied to shape size and spacing, matching the preview's pattern scale.
kind (int)0 = dashes (fill), 1 = curve shapes (stroke), 2 = text/surface shapes (even-odd fill).

CreateMeshPreviewImage

#Since v6.0
public static Bitmap CreateMeshPreviewImage(IEnumerable<Mesh> meshes, IEnumerable<Color> colors, Size size)
Creates a preview image of one or more meshes.
meshes (IEnumerable<Mesh>)The meshes.
colors (IEnumerable<Color>)The draw colors, one for each mesh.
size (Size)The size of the preview image.
A bitmap if successful, null otherwise.

CreateMeshPreviewImage

#Since v6.0
public static Bitmap CreateMeshPreviewImage(Mesh mesh, Color color, Size size)
Creates a preview image of a mesh.
mesh (Mesh)The mesh.
color (Color)The draw color.
size (Size)The size of the preview image.
A bitmap if successful, null otherwise.

CreateMeshPreviewImage

#Since v7.0
public static Bitmap CreateMeshPreviewImage(RhinoDoc doc, IEnumerable<Mesh> meshes, IEnumerable<Color> colors, Size size)
Creates a preview image of one or more meshes.
doc (RhinoDoc)The active document.
meshes (IEnumerable<Mesh>)The meshes.
colors (IEnumerable<Color>)The draw colors, one for each mesh.
size (Size)The size of the preview image.
A bitmap if successful, null otherwise.

DarkModeConvertPixel

#Since v8.0
public static void DarkModeConvertPixel(ref byte r, ref byte g, ref byte b)
Attempt to adjust pixels to an image that works for dark mode
r (ref byte)Red
g (ref byte)Green
b (ref byte)Vlue

DarkModeConvertPixels

#Since v8.0
public static void DarkModeConvertPixels(ref byte[] rgbaBytes)
Attempt to adjust pixels to an image that works for dark mode
rgbaBytes (ref byte[])

IconFromResource

#Since v6.0
public static Icon IconFromResource(string resourceName, Assembly assembly = null)
Load a Icon from an embedded resource.
resourceName (string)The case-sensitive name of the icon manifest resource being requested.
assembly (Assembly = null)The assembly containing the manifest resource, will use the calling assembly if null.
The Icon resource if found and loaded otherwise null.

IconFromResource

#Since v6.0
public static Icon IconFromResource(string resourceName, Size size, Assembly assembly = null)
Load a Icon from an embedded resource.
resourceName (string)The case-sensitive name of the icon manifest resource being requested.
size (Size)The desired size of the icon.
assembly (Assembly = null)The assembly containing the manifest resource, will use the calling assembly if null.
The Icon resource if found and loaded otherwise null.

ImageFromResource

#Since v6.0
public static Image ImageFromResource(string resourceName, Assembly assembly = null)
Load a Image from an embedded resource.
resourceName (string)The case-sensitive name of the image manifest resource being requested.
assembly (Assembly = null)The assembly containing the manifest resource, will use the calling assembly if null.
The Image resource if found and loaded otherwise null.

LoadBitmapWithScaleDown

#Since v6.0
public static Bitmap LoadBitmapWithScaleDown(string iconName, int sizeDesired, Assembly assembly = null)
Loads an icon from an embedded resource and converts it to a bitmap. If the icon is not a standard size, this function scales down a larger image.
iconName (string)The case-sensitive name of the icon manifest resource being requested.
sizeDesired (int)The desired size, in pixels, of the icon.
assembly (Assembly = null)The assembly containing the manifest resource.
The icon converted to a bitmap if successful, null otherwise.
ArgumentExceptionThrown when iconName is not found as an embedded resource in the specified assembly.

LoadIconWithScaleDown

#Since v6.0
public static Icon LoadIconWithScaleDown(string iconName, int sizeDesired, Assembly assembly = null)
Loads an icon from an embedded resource. If the icon is not a standard size, this function scales down a larger image.
iconName (string)The case-sensitive name of the icon manifest resource being requested.
sizeDesired (int)The desired size, in pixels, of the icon.
assembly (Assembly = null)The assembly containing the manifest resource.
The icon if successful, null otherwise.
ArgumentExceptionThrown when iconName is not found as an embedded resource in the specified assembly.

MakeArgb

#Since v8.0
public static int MakeArgb(byte a, byte r, byte g, byte b)
Stores a color into an integer from 4 bytes.
a (byte)Alpha (between 0 and 255)
r (byte)Red (between 0 and 255)
g (byte)Green (between 0 and 255)
b (byte)Blue (between 0 and 255)
An integer containing the ARGB data

PixelsFromSvg

#Since v8.0
public static byte[] PixelsFromSvg(string svg, int width, int height, bool premultiplyAlpha, Color backgroundColor, bool adjustForDarkMode)
Get array of bytes that represent RGBA values for an image of a given size created from SVG
svg (string)A valid svg string
width (int)Width of the svg in pixels
height (int)Height of the svg in pixels
premultiplyAlpha (bool)Pre-lends the background color with the pixels based on their alpha value
backgroundColor (Color)Background color - pass Color.Empty if you don't know what to pass.
adjustForDarkMode (bool)If true swaps any available attributes for their dark mode counterparts>
Null on an exception, an array of Color as bytes otherwise

PixelsFromSvg

#Since v8.0
public static byte[] PixelsFromSvg(string svg, int width, int height, bool premultiplyAlpha, Color backgroundColor)
Get array of bytes that represent RGBA values for an image of a given size created from SVG
svg (string)A valid svg string
width (int)Width of the svg in pixels
height (int)Height of the svg in pixels
premultiplyAlpha (bool)Pre-lends the background color with the pixels based on their alpha value
backgroundColor (Color)Background color - pass Color.Empty if you don't know what to pass.
Null on an exception, an array of Color as bytes otherwise

SvgToRhinoDibIntPtr

#Since v8.0
public static void SvgToRhinoDibIntPtr(string svg, int width, int height, bool adjustForDarkMode, nint pRhinoDib)
Create bitmap of a given size from an svg string
svg (string)
width (int)
height (int)
adjustForDarkMode (bool)
pRhinoDib (nint)