Represents an image
Constructors
Bitmap
#Initializes a new instance of a Bitmap from a
bytes arrayParameters:
| 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
Parameters:
| 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 heightParameters:
| 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
#Creates a new bitmap optimized for drawing on the specified
graphicsBitmap
#Creates a new bitmap with the specified dimensions, format and pixel data
Parameters:
| 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
#Creates a new bitmap with the specified dimensions, format, and integer pixel data
Parameters:
| 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
#Initializes a new instance of a Bitmap with the specified size and format
Parameters:
| width (int) | Width of the new bitmap |
| height (int) | Height of the new bitmap |
| pixelFormat (PixelFormat) | Format of each pixel |
Bitmap
#Initializes a new instance of a Bitmap with the specified size and format
Parameters:
| size (Size) | Size of the bitmap to create |
| pixelFormat (PixelFormat) | Format of each pixel |
Bitmap
#Initializes a new instance of a Bitmap from a stream
Parameters:
| stream (Stream) | Stream to load from the bitmap |
Properties
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.
Remarks: Use Image.Size if you wish to get the width and height at the same time.
Value: The height of the image, in pixels
See Also: Image.Size
IsDisposed
Gets or sets a value indicating whether this Widget has been disposed.
Remarks: When the widget is disposed, it can no longer be used.
Value:
true if this instance has been disposed; otherwise, false.NativeHandle
public nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
Value: The native handle.
inherited fromWidget
Remarks: This gets set to the current Platform.Instance during the construction of the object
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.
Example:
// 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;
});Remarks: Use Image.Size if you wish to get the width and height at the same time.
Value: The width of the image, in pixels
See Also: Image.Size
Methods
Dispose
public void Dispose()
Disposes of this widget, supressing the finalizer
Parameters:
| 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
Parameters:
| 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 |
Returns: A new instance of a Bitmap loaded from the specified resource
FromResource
#Loads a bitmap from a resource in the same assembly as the specified
typeGetCallback
Gets an instance of an object used to perform callbacks to the widget from handler implementations
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.
Returns: The callback instance to use for this widget
GetPixel
#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.
Returns: The color of the pixel at the specified coordinates
GetPixel
#Gets the color of the pixel at the specified
positionRemarks: 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.
Parameters:
| position (Point) | Position to get the color of the pixel. |
Returns: The color of the pixel.
Initialize
protected void Initialize()
Initializes the widget handler
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
#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
}Returns: A BitmapData object that carries a pointer and functions for manipulating the data directly
inherited fromWidget
Save
#Saves the bitmap to a stream in the specified format
Parameters:
| stream (Stream) | Stream to save the bitmap to |
| format (ImageFormat) | Format to save as |
Save
#Saves the bitmap to a file in the specified format
Parameters:
| fileName (string) | File to save the bitmap to |
| format (ImageFormat) | Format to save as |
SetPixel
#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.
SetPixel
#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.
ToByteArray
#Saves the bitmap to an image of the specified
imageFormat into a byte arrayRemarks: This is merely a helper to save to a byte array instead of a stream.
Parameters:
| imageFormat (ImageFormat) |
ToString
Gets a string that represents the current object with its ID if specified.
Returns: A string value indicating the type and ID (if specified) of this widget.
Overrides: Object.ToString
WithSize
#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.Parameters:
| width (int) | Maxiumum drawing width for the new icon. |
| height (int) | Maxiumum drawing height for the new icon. |
Returns: A new icon that will draw within the fitting size.
WithSize
#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.Parameters:
| fittingSize (Size) | The maximum size to draw the Icon. |
Returns: A new icon that will draw within the fitting size.
Events
inherited fromWidget