s&box docs

public sealed class Sandbox.Bitmap

Broader workflow and conceptual references connected to this API.

Constructors

Showing 1 constructors

public Bitmap(int width, int height, bool floatingPoint = False)

Parameters

  • floatingPoint: Default: False

Methods

Showing 59 methods

public void Adjust(float brightness = 1, float contrast = 1, float saturation = 1, float hueDegrees = 0)

Adjusts brightness, contrast, and saturation in one pass.

Parameters

  • brightness: Default: 1
  • contrast: Default: 1
  • saturation: Default: 1
  • hueDegrees: Default: 0

public void AdjustHue(float angle)

Adjusts the hue of the bitmap.

Parameters

  • angle: The angle to rotate the hue, in degrees (0 to 360).

public void Blur(float radius, bool tileClamp = True)

Applies a Gaussian blur effect to the current bitmap.

Parameters

  • radius: The radius of the blur, controlling its intensity. Must be non-negative.
  • tileClamp: Determines the behavior at the edges of the bitmap: `true` to clamp the edges (default), or `false` to repeat the edges. Default: True

public void Clear(Color color)

Clears the bitmap to the specified color.

Parameters

  • color: The color to fill the bitmap with.

public Sandbox.Bitmap Clone()

Copy the bitmap to a new one without any changes.

public void Colorize(Color color)

Color the bitmap using this color, respect alpha

public static Sandbox.Bitmap CreateFromBytes(byte[] data)

Loads a bitmap from the specified byte array.

Parameters

  • data: The byte array containing the image data.

Returns

A new `Sandbox.Bitmap` instance.

public static Sandbox.Bitmap CreateFromIesBytes(byte[] data)

public static Sandbox.Bitmap CreateFromPsdBytes(byte[] data)

Creates a Bitmap instance from PSD file data.

Parameters

  • data: Byte array containing the PSD file data.

Returns

A Bitmap instance if successful, or null if the data is not valid PSD.

public static Sandbox.Bitmap CreateFromSvgString(string svgContents, System.Nullable`1<int> width, System.Nullable`1<int> height, System.Nullable`1<Vector2> scale = null, System.Nullable`1<Vector2> offset = null, System.Nullable`1<float> rotation = null)

Parameters

  • scale: Default: null
  • offset: Default: null
  • rotation: Default: null

public static Sandbox.Bitmap CreateFromTgaBytes(byte[] data)

public static Sandbox.Bitmap CreateFromTifBytes(byte[] data)

public Sandbox.Bitmap Crop(Sandbox.Rect rect)

Crops the bitmap to the specified rectangle.

Parameters

  • rect: The rectangle to crop to.

Returns

A new `Sandbox.Bitmap` instance with the cropped image.

public virtual sealed void Dispose()

public void DrawBitmap(Sandbox.Bitmap bitmap, Sandbox.Rect destRect)

Draws another bitmap onto this bitmap.

Parameters

  • bitmap: The bitmap to draw.
  • destRect: The destination rectangle for the drawn bitmap.

public void DrawLine(Vector2 start, Vector2 end)

Draws a line using the current pen settings.

Parameters

  • start: The starting point of the line.
  • end: The ending point of the line.

public void DrawLines(Vector2[] points)

Draws connected lines through a series of points using the current pen settings.

Parameters

  • points: The points to connect with lines.

public void DrawPolygon(Vector2[] points)

Draws a polygon using the current pen settings.

Parameters

  • points: The points of the polygon.

public void DrawRoundRect(Sandbox.Rect rect, Sandbox.UI.Margin margins)

Draws a rectangle using the current pen settings.

public void DrawText(Sandbox.TextRendering.Scope scope, Sandbox.Rect rect, Sandbox.TextFlag flags = 132)

Draws text onto this bitmap

Parameters

  • flags: Default: 132

public Sandbox.Bitmap FlipHorizontal()

Flips the bitmap horizontally.

Returns

A new `Sandbox.Bitmap` instance with the flipped image.

public Sandbox.Bitmap FlipVertical()

Flips the bitmap vertically.

Returns

A new `Sandbox.Bitmap` instance with the flipped image.

public Color GetPixel(int x, int y)

Retrieves the color of a specific pixel in the bitmap.

Parameters

  • x: The x-coordinate of the pixel.
  • y: The y-coordinate of the pixel.

Returns

The color of the pixel at the specified coordinates.

public Color[] GetPixels()

Retrieves the pixel data of the bitmap as an array of colors.

public Color.Rgba16[] GetPixels16()

Retrieves the pixel data of the bitmap as an array of colors.

public Color32[] GetPixels32()

Retrieves the pixel data of the bitmap as an array of colors.

public Sandbox.Bitmap HeightmapToNormalMap(float strength = 1)

Converts a heightmap to a normal map using parallel processing.

Parameters

  • strength: The strength of the normal map effect (default is 1.0). Default: 1

Returns

The generated normal map as an SKBitmap.

public void InsertPadding(Sandbox.UI.Margin margin)

Shrink the image by adding padding all around - without resizing the bitmap

public void InvertColor()

Inverts the colors of the bitmap while preserving alpha.

public static bool IsIes(byte[] data)

Return true if this data is a Ies file

public bool IsOpaque()

Returns true if this bitmap is completely opaque (no alpha) This does a pixel by pixel search, so it's not the fastest.

public static bool IsPsd(byte[] data)

Checks if the provided byte array is a valid PSD file.

Parameters

  • data: Byte array to check.

Returns

True if the data is a PSD file, otherwise false.

public static bool IsTga(byte[] data)

Return true if this data is a Tga file

public static bool IsTif(System.ReadOnlySpan`1<byte> data)

public Sandbox.Bitmap Resize(int newWidth, int newHeight, bool smooth = True)

Resizes the bitmap to the specified dimensions and returns a new bitmap.

Parameters

  • newWidth: The new width of the bitmap.
  • newHeight: The new height of the bitmap.
  • smooth: Resample smoothly. If false this will be nearest neighbour. Default: True

Returns

A new `Sandbox.Bitmap` instance with the specified dimensions.

public Sandbox.Bitmap Rotate(float degrees)

Rotates the bitmap by the specified angle.

Parameters

  • degrees: The angle in degrees to rotate the bitmap.

Returns

A new `Sandbox.Bitmap` instance with the rotated image.

public void SetAntialias(bool on)

Sets the pen for drawing with a solid color and stroke style.

public void SetBlendMode(Sandbox.BlendMode blendMode)

Sets the pen to use a specific blend mode.

Parameters

  • blendMode: The blend mode to apply.

public void SetDashedPen(Color color, float width, float[] dashPattern)

Sets the pen for drawing dashed or dotted lines.

Parameters

  • color: The color of the pen.
  • width: The width of the pen in pixels.
  • dashPattern: An array defining the dash pattern (e.g., [10, 5] for 10px dash, 5px gap).

public void SetFill(Color color)

Sets the pen for drawing filled shapes with a solid color.

Parameters

  • color: The color to fill the shapes with.

public void SetLinearGradient(Vector2 start, Vector2 end, Sandbox.Gradient gradient)

Sets the pen for drawing with a linear gradient.

Parameters

  • start: the gradient's start point.
  • end: the gradient's end point.
  • gradient: The color of the gradient.

public void SetPen(Color color, float width)

Sets the pen for drawing with a solid color and stroke style.

Parameters

  • color: The color of the pen.
  • width: The width of the pen in pixels.

public void SetPixel(int x, int y, Color color)

Sets the color of a specific pixel in the bitmap.

Parameters

  • x: The x-coordinate of the pixel.
  • y: The y-coordinate of the pixel.
  • color: The color to set the pixel to.

public void SetPixels(Color[] colors)

public void SetRadialGradient(Vector2 center, float radius, Sandbox.Gradient gradient)

Sets the pen for drawing with a radial gradient.

Parameters

  • center: The gradient's center.
  • radius: The radius of the gradient.
  • gradient: The color of the gradient.

public void Sharpen(float amount, bool tileClamp = True)

Applies a Gaussian blur effect to the current bitmap.

Parameters

  • tileClamp: Default: True

public void Tint(Color color)

Tint the bitmap using this color, respect alpha

public byte[] ToBmp()

Exports the bitmap as a BMP byte array.

Returns

A byte array containing the BMP image data.

public byte[] ToFormat(Sandbox.ImageFormat format)

Exports the bitmap to the specified engine format

public byte[] ToJpg(int quality = 100)

Exports the bitmap as a JPEG byte array with the specified quality.

Parameters

  • quality: The quality of the JPEG, between 0 and 100. Default: 100

Returns

A byte array containing the JPEG image data.

public byte[] ToPng()

Exports the bitmap as a PNG byte array.

Returns

A byte array containing the PNG image data.

public Sandbox.Texture ToTexture(bool mips = True)

Try to create a texture from this bitmap

Parameters

  • mips: Default: True

public byte[] ToWebP(int quality = 100)

Exports the bitmap as an HDR WebP byte array with the specified quality.

Parameters

  • quality: The quality of the WebP image, between 0 and 100. Default: 100

Returns

A byte array containing the WebP HDR image data.

Properties

Showing 9 properties

public int Sandbox.Bitmap.ByteCount { get; set; }

public int Sandbox.Bitmap.BytesPerPixel { get; set; }

public int Sandbox.Bitmap.Height { get; set; }

public bool Sandbox.Bitmap.IsFloatingPoint { get; set; }

public virtual sealed bool Sandbox.Bitmap.IsValid { get; set; }

public Vector2Int Sandbox.Bitmap.Size { get; set; }

The width and height of the bitmap

public int Sandbox.Bitmap.Width { get; set; }

Metadata

FieldValue
NamespaceSandbox
Typeclass
AssemblySandbox.Engine
Doc IDT:Sandbox.Bitmap

On this page

Constructorspublic Bitmap(System.Int32 width, System.Int32 height, System.Boolean floatingPoint = False)Methodspublic System.Void Adjust(System.Single brightness = 1, System.Single contrast = 1, System.Single saturation = 1, System.Single hueDegrees = 0)public System.Void AdjustHue(System.Single angle)public System.Void Blur(System.Single radius, System.Boolean tileClamp = True)public System.Void Clear(Color color)public Sandbox.Bitmap Clone()public System.Void Colorize(Color color)public static Sandbox.Bitmap CreateFromBytes(System.Byte[] data)public static Sandbox.Bitmap CreateFromIesBytes(System.Byte[] data)public static Sandbox.Bitmap CreateFromPsdBytes(System.Byte[] data)public static Sandbox.Bitmap CreateFromSvgString(System.String svgContents, System.Nullable`1<System.Int32> width, System.Nullable`1<System.Int32> height, System.Nullable`1<Vector2> scale = null, System.Nullable`1<Vector2> offset = null, System.Nullable`1<System.Single> rotation = null)public static Sandbox.Bitmap CreateFromTgaBytes(System.Byte[] data)public static Sandbox.Bitmap CreateFromTifBytes(System.Byte[] data)public Sandbox.Bitmap Crop(Sandbox.Rect rect)public virtual sealed System.Void Dispose()public System.Void DrawArc(Sandbox.Rect rect, System.Single startAngle, System.Single sweepAngle, System.Boolean useCenter)public System.Void DrawArc(Sandbox.Rect rect, System.Single startAngle, System.Single sweepAngle)public System.Void DrawBitmap(Sandbox.Bitmap bitmap, Sandbox.Rect destRect)public System.Void DrawCircle(System.Single x, System.Single y, System.Single radius)public System.Void DrawCircle(Vector2 center, System.Single radius)public System.Void DrawLine(Vector2 start, Vector2 end)public System.Void DrawLines(Vector2[] points)public System.Void DrawPolygon(Vector2[] points)public System.Void DrawRect(Sandbox.Rect rect)public System.Void DrawRect(System.Single x, System.Single y, System.Single width, System.Single height)public System.Void DrawRoundRect(Sandbox.Rect rect, Sandbox.UI.Margin margins)public System.Void DrawText(Sandbox.TextRendering.Scope scope, Sandbox.Rect rect, Sandbox.TextFlag flags = 132)public Sandbox.Bitmap FlipHorizontal()public Sandbox.Bitmap FlipVertical()public Color GetPixel(System.Int32 x, System.Int32 y)public Color[] GetPixels()public Color.Rgba16[] GetPixels16()public Color32[] GetPixels32()public Sandbox.Bitmap HeightmapToNormalMap(System.Single strength = 1)public System.Void InsertPadding(Sandbox.UI.Margin margin)public System.Void InvertColor()public static System.Boolean IsIes(System.Byte[] data)public System.Boolean IsOpaque()public static System.Boolean IsPsd(System.Byte[] data)public static System.Boolean IsTga(System.Byte[] data)public static System.Boolean IsTif(System.ReadOnlySpan`1<System.Byte> data)public Sandbox.Bitmap Resize(System.Int32 newWidth, System.Int32 newHeight, System.Boolean smooth = True)public Sandbox.Bitmap Rotate(System.Single degrees)public System.Void SetAntialias(System.Boolean on)public System.Void SetBlendMode(Sandbox.BlendMode blendMode)public System.Void SetDashedPen(Color color, System.Single width, System.Single[] dashPattern)public System.Void SetFill(Color color)public System.Void SetLinearGradient(Vector2 start, Vector2 end, Sandbox.Gradient gradient)public System.Void SetPen(Color color, System.Single width)public System.Void SetPixel(System.Int32 x, System.Int32 y, Color color)public System.Void SetPixels(Color[] colors)public System.Void SetRadialGradient(Vector2 center, System.Single radius, Sandbox.Gradient gradient)public System.Void Sharpen(System.Single amount, System.Boolean tileClamp = True)public System.Void Tint(Color color)public System.Byte[] ToBmp()public System.Byte[] ToFormat(Sandbox.ImageFormat format)public System.Byte[] ToJpg(System.Int32 quality = 100)public System.Byte[] ToPng()public Sandbox.Texture ToTexture(System.Boolean mips = True)public System.Byte[] ToWebP(System.Int32 quality = 100)Propertiespublic System.Int32 Sandbox.Bitmap.ByteCount { get; set; }public System.Int32 Sandbox.Bitmap.BytesPerPixel { get; set; }public Vector2 Sandbox.Bitmap.Center { get; set; }public System.Int32 Sandbox.Bitmap.Height { get; set; }public System.Boolean Sandbox.Bitmap.IsFloatingPoint { get; set; }public virtual sealed System.Boolean Sandbox.Bitmap.IsValid { get; set; }public Sandbox.Rect Sandbox.Bitmap.Rect { get; set; }public Vector2Int Sandbox.Bitmap.Size { get; set; }public System.Int32 Sandbox.Bitmap.Width { get; set; }Metadata