Bitmapclass

objectBitmap
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public sealed class Sandbox.Bitmap

Constructors1

Showing 1 constructors

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

ParameterTypeDescription
widthint
heightint
floatingPoint = Falsebool

Methods59

Showing 59 methods

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

Adjusts brightness, contrast, and saturation in one pass.

ParameterTypeDescription
brightness = 1float
contrast = 1float
saturation = 1float
hueDegrees = 0float
Returns:void

public void AdjustHue(float angle)PUBLIC

Adjusts the hue of the bitmap.

ParameterTypeDescription
anglefloatThe angle to rotate the hue, in degrees (0 to 360).
Returns:void

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

Applies a Gaussian blur effect to the current bitmap.

ParameterTypeDescription
radiusfloatThe radius of the blur, controlling its intensity. Must be non-negative.
tileClamp = TrueboolDetermines the behavior at the edges of the bitmap: `true` to clamp the edges (default), or `false` to repeat the edges.
Returns:void

public void Clear(Color color)PUBLIC

Clears the bitmap to the specified color.

ParameterTypeDescription
colorColorThe color to fill the bitmap with.
Returns:void

public Sandbox.Bitmap Clone()PUBLIC

Copy the bitmap to a new one without any changes.

Returns:Bitmap

public void Colorize(Color color)PUBLIC

Color the bitmap using this color, respect alpha

ParameterTypeDescription
colorColor
Returns:void

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

Loads a bitmap from the specified byte array.

ParameterTypeDescription
databyte[]The byte array containing the image data.
Returns:BitmapA new `Sandbox.Bitmap` instance.

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

ParameterTypeDescription
databyte[]
Returns:Bitmap

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

Creates a Bitmap instance from PSD file data.

ParameterTypeDescription
databyte[]Byte array containing the PSD file data.
Returns:BitmapA 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)PUBLICSTATIC

ParameterTypeDescription
svgContentsstring
widthNullable<int>
heightNullable<int>
scale = nullNullable<Vector2>
offset = nullNullable<Vector2>
rotation = nullNullable<float>
Returns:Bitmap

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

ParameterTypeDescription
databyte[]
Returns:Bitmap

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

ParameterTypeDescription
databyte[]
Returns:Bitmap

public Sandbox.Bitmap Crop(Sandbox.Rect rect)PUBLIC

Crops the bitmap to the specified rectangle.

ParameterTypeDescription
rectRectThe rectangle to crop to.
Returns:BitmapA new `Sandbox.Bitmap` instance with the cropped image.

public virtual sealed void Dispose()PUBLICVIRTUAL

Returns:void

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

Draws another bitmap onto this bitmap.

ParameterTypeDescription
bitmapBitmapThe bitmap to draw.
destRectRectThe destination rectangle for the drawn bitmap.
Returns:void

public void DrawLine(Vector2 start, Vector2 end)PUBLIC

Draws a line using the current pen settings.

ParameterTypeDescription
startVector2The starting point of the line.
endVector2The ending point of the line.
Returns:void

public void DrawLines(Vector2[] points)PUBLIC

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

ParameterTypeDescription
pointsVector2[]The points to connect with lines.
Returns:void

public void DrawPolygon(Vector2[] points)PUBLIC

Draws a polygon using the current pen settings.

ParameterTypeDescription
pointsVector2[]The points of the polygon.
Returns:void

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

Draws a rectangle using the current pen settings.

ParameterTypeDescription
rectRect
marginsMargin
Returns:void

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

Draws text onto this bitmap

ParameterTypeDescription
scopeScope
rectRect
flags = 132TextFlag
Returns:void

public Sandbox.Bitmap FlipHorizontal()PUBLIC

Flips the bitmap horizontally.

Returns:BitmapA new `Sandbox.Bitmap` instance with the flipped image.

public Sandbox.Bitmap FlipVertical()PUBLIC

Flips the bitmap vertically.

Returns:BitmapA new `Sandbox.Bitmap` instance with the flipped image.

public Color GetPixel(int x, int y)PUBLIC

Retrieves the color of a specific pixel in the bitmap.

ParameterTypeDescription
xintThe x-coordinate of the pixel.
yintThe y-coordinate of the pixel.
Returns:ColorThe color of the pixel at the specified coordinates.

public Color[] GetPixels()PUBLIC

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

Returns:Color[]

public Color.Rgba16[] GetPixels16()PUBLIC

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

Returns:Rgba16[]

public Color32[] GetPixels32()PUBLIC

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

Returns:Color32[]

public Sandbox.Bitmap HeightmapToNormalMap(float strength = 1)PUBLIC

Converts a heightmap to a normal map using parallel processing.

ParameterTypeDescription
strength = 1floatThe strength of the normal map effect (default is 1.0).
Returns:BitmapThe generated normal map as an SKBitmap.

public void InsertPadding(Sandbox.UI.Margin margin)PUBLIC

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

ParameterTypeDescription
marginMargin
Returns:void

public void InvertColor()PUBLIC

Inverts the colors of the bitmap while preserving alpha.

Returns:void

public static bool IsIes(byte[] data)PUBLICSTATIC

Return true if this data is a Ies file

ParameterTypeDescription
databyte[]
Returns:bool

public bool IsOpaque()PUBLIC

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

Returns:bool

public static bool IsPsd(byte[] data)PUBLICSTATIC

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

ParameterTypeDescription
databyte[]Byte array to check.
Returns:boolTrue if the data is a PSD file, otherwise false.

public static bool IsTga(byte[] data)PUBLICSTATIC

Return true if this data is a Tga file

ParameterTypeDescription
databyte[]
Returns:bool

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

ParameterTypeDescription
dataReadOnlySpan<byte>
Returns:bool

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

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

ParameterTypeDescription
newWidthintThe new width of the bitmap.
newHeightintThe new height of the bitmap.
smooth = TrueboolResample smoothly. If false this will be nearest neighbour.
Returns:BitmapA new `Sandbox.Bitmap` instance with the specified dimensions.

public Sandbox.Bitmap Rotate(float degrees)PUBLIC

Rotates the bitmap by the specified angle.

ParameterTypeDescription
degreesfloatThe angle in degrees to rotate the bitmap.
Returns:BitmapA new `Sandbox.Bitmap` instance with the rotated image.

public void SetAntialias(bool on)PUBLIC

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

ParameterTypeDescription
onbool
Returns:void

public void SetBlendMode(Sandbox.BlendMode blendMode)PUBLIC

Sets the pen to use a specific blend mode.

ParameterTypeDescription
blendModeBlendModeThe blend mode to apply.
Returns:void

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

Sets the pen for drawing dashed or dotted lines.

ParameterTypeDescription
colorColorThe color of the pen.
widthfloatThe width of the pen in pixels.
dashPatternfloat[]An array defining the dash pattern (e.g., [10, 5] for 10px dash, 5px gap).
Returns:void

public void SetFill(Color color)PUBLIC

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

ParameterTypeDescription
colorColorThe color to fill the shapes with.
Returns:void

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

Sets the pen for drawing with a linear gradient.

ParameterTypeDescription
startVector2the gradient's start point.
endVector2the gradient's end point.
gradientGradientThe color of the gradient.
Returns:void

public void SetPen(Color color, float width)PUBLIC

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

ParameterTypeDescription
colorColorThe color of the pen.
widthfloatThe width of the pen in pixels.
Returns:void

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

Sets the color of a specific pixel in the bitmap.

ParameterTypeDescription
xintThe x-coordinate of the pixel.
yintThe y-coordinate of the pixel.
colorColorThe color to set the pixel to.
Returns:void

public void SetPixels(Color[] colors)PUBLIC

ParameterTypeDescription
colorsColor[]
Returns:void

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

Sets the pen for drawing with a radial gradient.

ParameterTypeDescription
centerVector2The gradient's center.
radiusfloatThe radius of the gradient.
gradientGradientThe color of the gradient.
Returns:void

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

Applies a Gaussian blur effect to the current bitmap.

ParameterTypeDescription
amountfloat
tileClamp = Truebool
Returns:void

public void Tint(Color color)PUBLIC

Tint the bitmap using this color, respect alpha

ParameterTypeDescription
colorColor
Returns:void

public byte[] ToBmp()PUBLIC

Exports the bitmap as a BMP byte array.

Returns:byte[]A byte array containing the BMP image data.

public byte[] ToFormat(Sandbox.ImageFormat format)PUBLIC

Exports the bitmap to the specified engine format

ParameterTypeDescription
formatImageFormatThe target image format to encode to.
Returns:byte[]

public byte[] ToJpg(int quality = 100)PUBLIC

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

ParameterTypeDescription
quality = 100intThe quality of the JPEG, between 0 and 100.
Returns:byte[]A byte array containing the JPEG image data.

public byte[] ToPng()PUBLIC

Exports the bitmap as a PNG byte array.

Returns:byte[]A byte array containing the PNG image data.

public Sandbox.Texture ToTexture(bool mips = True)PUBLIC

Try to create a texture from this bitmap

ParameterTypeDescription
mips = Truebool
Returns:Texture

public byte[] ToWebP(int quality = 100)PUBLIC

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

ParameterTypeDescription
quality = 100intThe quality of the WebP image, between 0 and 100.
Returns:byte[]A byte array containing the WebP HDR image data.

Properties9

Showing 9 properties

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

Returns:int

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

Returns:int

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

Returns:int

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

Returns:bool

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

Returns:bool

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

Returns:int

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