public sealed class Sandbox.Bitmap
Related Guides
Broader workflow and conceptual references connected to this API.
You can define your own custom asset types as GameResources. They give you a nice inspector window and they're hotloaded in-game, which means you can whip things up pretty quickly if you're using them.
The Storage system provides a simple, unified way to manage user-generated content in your game. Whether you're saving game progress, storing player creations, or anything else, Storage handles everything from local file management to Steam Workshop integration.
In the editor Textures can be generated in a number of ways. They can be created from an image (which is pretty normal), or a color, or a gradient, or text, or SVG source. These are called texture generators.
Constructors
Showing 1 constructors
public Bitmap(int width, int height, bool floatingPoint = False)
Parameters
floatingPoint: Default: False
No results match this filter.
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: 1contrast: Default: 1saturation: Default: 1hueDegrees: 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: nulloffset: Default: nullrotation: 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 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.
No results match this filter.
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; }
No results match this filter.
Metadata
| Field | Value |
|---|---|
| Namespace | Sandbox |
| Type | class |
| Assembly | Sandbox.Engine |
| Doc ID | T:Sandbox.Bitmap |