[Handler(Bitmap.IHandler)] [TypeConverter(BitmapConverter)] public class Bitmap : Image
Represents an image

Constructors

Bitmap

#
public Bitmap(byte[] bytes)
Initializes a new instance of a Bitmap from a bytes array
bytes (byte[])Array of bytes containing the image data in one of the supported ImageFormat types

Bitmap

#
public Bitmap(IHandler handler)
Initializes a new instance of a Bitmap with the specified handler
Remarks: This is intended to be used by platform specific code to return bitmap instances with a particular handler
handler (Bitmap.IHandler)Platform handler to use for this instance

Bitmap

#
public Bitmap(Image image, int? width = null, int? height = null, ImageInterpolation interpolation = ImageInterpolation.Default)
Create a new scaled bitmap with the specified width and height
image (Image)Image to scale
width (int? = null)Width to scale the source image to
height (int? = null)Height to scale the source image to
interpolation (ImageInterpolation = ImageInterpolation.Default)Interpolation quality

Bitmap

#
public Bitmap(int width, int height, Graphics graphics)
Creates a new bitmap optimized for drawing on the specified graphics
width (int)Width of the bitmap
height (int)Height of the bitmap
graphics (Graphics)Graphics context the bitmap is intended to be drawn on

Bitmap

#
public Bitmap(int width, int height, PixelFormat pixelFormat, IEnumerable<Color> data)
Creates a new bitmap with the specified dimensions, format and pixel data
width (int)Width of the bitmap
height (int)Height of the bitmap
pixelFormat (PixelFormat)Format of each pixel
data (IEnumerable<Color>)Color data enumeration, starting from top-left of the bitmap and width*height length

Bitmap

#
public Bitmap(int width, int height, PixelFormat pixelFormat, IEnumerable<int> data)
Creates a new bitmap with the specified dimensions, format, and integer pixel data
width (int)Width of the bitmap
height (int)Height of the bitmap
pixelFormat (PixelFormat)Format for each pixel
data (IEnumerable<int>)Colordata enumeration, in ARGB format, starting from top-left of the bitmap and width*height length

Bitmap

#
public Bitmap(int width, int height, PixelFormat pixelFormat)
Initializes a new instance of a Bitmap with the specified size and format
width (int)Width of the new bitmap
height (int)Height of the new bitmap
pixelFormat (PixelFormat)Format of each pixel

Bitmap

#
public Bitmap(Size size, PixelFormat pixelFormat)
Initializes a new instance of a Bitmap with the specified size and format
size (Size)Size of the bitmap to create
pixelFormat (PixelFormat)Format of each pixel

Bitmap

#
public Bitmap(Stream stream)
Initializes a new instance of a Bitmap from a stream

Bitmap

#
public Bitmap(string fileName)
Initializes a new instance of a Bitmap from a file

Properties

ControlObject

public object ControlObject { get; }
Gets the instance of the platform-specific object
inherited fromWidget
Remarks: This can sometimes be useful to get the platform-specific object. Some handlers may not have any backing object for its functionality, so this may be null. It is more preferred to use the Widget.Handler and cast that to the platform-specific handler class which can give you additional methods and helpers to do common tasks. For example, the Application object's handler for OS X has a AddFullScreenMenuItem property to specify if you want full screen support in your app.

Handler

public object Handler { get; }
Gets the platform-specific handler for this widget
inherited fromWidget

Height

public int Height { get; }
Gets the height of the image, in pixels.
inherited fromImage
Remarks: Use Image.Size if you wish to get the width and height at the same time.
The height of the image, in pixels
Image.Size

IsDisposed

public bool IsDisposed { get; }
Gets or sets a value indicating whether this Widget has been disposed.
inherited fromWidget
Remarks: When the widget is disposed, it can no longer be used.
true if this instance has been disposed; otherwise, false.

NativeHandle

public nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
inherited fromWidget

Platform

public Platform Platform { get; }
Gets the platform that was used to create the Widget.Handler for this widget
inherited fromWidget
Remarks: This gets set to the current Platform.Instance during the construction of the object

Properties

public PropertyStore Properties { get; }
Gets the dictionary of properties for this widget
inherited fromWidget

Style

public string Style { get; set; }
Gets or sets the style of this widget
inherited fromWidget
Remarks: Styles allow you to attach custom platform-specific logic to a widget. In your platform-specific assembly, use Add{H} to add the style logic with the same id.
// in your UI
var control = new Button { Style = "mystyle" };

// in your platform assembly
using Eto.Mac.Forms.Controls;

Styles.AddHandler<ButtonHandler>("mystyle", handler => {
	// this is where you can use handler.Control to set properties, handle events, etc.
	handler.Control.BezelStyle = NSBezelStyle.SmallSquare;
});

Width

public int Width { get; }
Gets the width of the image, in pixels.
inherited fromImage
Remarks: Use Image.Size if you wish to get the width and height at the same time.
The width of the image, in pixels
Image.Size

Methods

Clone

#
public Bitmap Clone(Rectangle? rectangle = null)
Creates a clone of the bitmap

Dispose

protected virtual void Dispose(bool disposing)
Handles the disposal of this widget
inherited fromWidget
disposing (bool)True if the caller called Widget.Dispose() manually, false if being called from a finalizer

FromResource

#
[MethodImpl(MethodImplOptions.NoInlining)] public static Bitmap FromResource(string resourceName, Assembly assembly = null)
Loads a bitmap from the resource in the specified or caller's assembly
resourceName (string)Name of the resource in the caller's assembly to load. E.g. "MyProject.SomeFolder.YourFile.extension"
assembly (Assembly = null)Assembly to load the resource from, or null to use the caller's assembly
A new instance of a Bitmap loaded from the specified resource

FromResource

#
public static Bitmap FromResource(string resourceName, Type type)
Loads a bitmap from a resource in the same assembly as the specified type
resourceName (string)Full name of the resource in the type's assembly. E.g. "MyProject.SomeFolder.YourFile.extension"
type (Type)Type of the assembly to get the resource.
The bitmap instance.

GetCallback

protected virtual object GetCallback()
Gets an instance of an object used to perform callbacks to the widget from handler implementations
inherited fromWidget
Remarks: The callback should implement the parent class' Widget.ICallback interface so that there only needs to be a single callback for the entire hierarchy. This should return a static instance to avoid having overhead for each instance of your control.
The callback instance to use for this widget

GetPixel

#
public Color GetPixel(int x, int y)
Gets the color of the pixel at the specified coordinates.
Remarks: Note that this method can be extremely slow to go through each pixel of a bitmap. If you need better performance, use Lock() to get access to the bitmap's pixel buffer directly, then optionally use BitmapData.GetPixel(int, int) to get each pixel value.
x (int)The x coordinate
y (int)The y coordinate
The color of the pixel at the specified coordinates

GetPixel

#
public Color GetPixel(Point position)
Gets the color of the pixel at the specified position
Remarks: Note that this method can be extremely slow to go through each pixel of a bitmap. If you need better performance, use Lock() to get access to the bitmap's pixel buffer directly, then optionally use BitmapData.GetPixel(Point) to get each pixel value.
position (Point)Position to get the color of the pixel.
The color of the pixel.

Initialize

protected void Initialize()
Initializes the widget handler
inherited fromWidget
Remarks: This is typically called from the constructor after all of the logic is completed to construct the object. If your handler interface has the AutoInitializeAttribute set to false, then you are responsible for calling this method in your constructor after calling the creation method on your custom handler.

Lock

#
public BitmapData Lock()
Locks the data of the image to directly access the bytes of the image
Remarks: This locks the data to read and write to directly using unsafe pointers. After reading or updating the data, you must call BitmapData.Dispose() to unlock the data before using the bitmap. e.g.:
using (var bd = bitmap.Lock ()) {
	byte* pdata = bd.Data;
	// access data
}
A BitmapData object that carries a pointer and functions for manipulating the data directly

OnStyleChanged

protected virtual void OnStyleChanged(EventArgs e)
Handles when the Widget.Style is changed.
inherited fromWidget

Save

#
public void Save(Stream stream, ImageFormat format)
Saves the bitmap to a stream in the specified format

Save

#
public void Save(string fileName, ImageFormat format)
Saves the bitmap to a file in the specified format

SetPixel

#
public void SetPixel(int x, int y, Color color)
Sets the color of the pixel at the specified coordinates.
Remarks: Note that this method can be extremely slow to set each pixel of a bitmap. If you need better performance, use Lock() to get access to the bitmap's pixel buffer directly, then optionally use BitmapData.SetPixel(int, int, Color) to set each pixel value.
x (int)The x coordinate of the pixel to set.
y (int)The y coordinate of the pixel to set.
color (Color)Color to set the pixel to.

SetPixel

#
public void SetPixel(Point position, Color color)
Sets the pixel color at the specified position.
Remarks: Note that this method can be extremely slow to set each pixel of a bitmap. If you need better performance, use Lock() to get access to the bitmap's pixel buffer directly, then optionally use BitmapData.SetPixel(Point, Color) to set each pixel value.
position (Point)Position to set the pixel color.
color (Color)Color to set.

ToByteArray

#
public byte[] ToByteArray(ImageFormat imageFormat)
Saves the bitmap to an image of the specified imageFormat into a byte array
Remarks: This is merely a helper to save to a byte array instead of a stream.
imageFormat (ImageFormat)

ToString

public override string ToString()
Gets a string that represents the current object with its ID if specified.
inherited fromWidget
A string value indicating the type and ID (if specified) of this widget.
Object.ToString

WithSize

#
public Icon WithSize(int width, int height)
Gets an Icon representation of this Bitmap scaled to draw within the specified fitting size.
Remarks: This is useful when you want to draw the image at a different size than the default size without resizing the image. Note that the width and height specifies the maxiumum drawing size of the Icon, but will not change the aspect of each frame's bitmap. For example, if an existing frame is 128x128, and you specify 16x32, then the resulting frame will draw at 16x16.
width (int)Maxiumum drawing width for the new icon.
height (int)Maxiumum drawing height for the new icon.
A new icon that will draw within the fitting size.

WithSize

#
public Icon WithSize(Size fittingSize)
Gets an Icon representation of this Bitmap scaled to draw within the specified fitting size.
Remarks: This is useful when you want to draw the image at a different size than the default size without resizing the image. Note that the fittingSize specifies the maxiumum drawing size of the Icon, but will not change the aspect of each frame's bitmap. For example, if an existing frame is 128x128, and you specify 16x32, then the resulting frame will draw at 16x16.
fittingSize (Size)The maximum size to draw the Icon.
A new icon that will draw within the fitting size.

Events