xtd 0.2.0
xtd::drawing::bitmap Class Reference

Definition

Encapsulates a GDI+ bitmap, which consists of the pixel data for a graphics image and its attributes. A bitmap is an object used to work with images defined by pixel data.

class drawing_export_ bitmap : public xtd::drawing::image
Inheritance
xtd::objectxtd::drawing::imagextd::drawing::bitmap
Namespace
xtd::drawing
Library
xtd.drawing
Remarks
To draw an image on a Windows Form, you should use one of the draw_image methods.
Examples:
about_box.cpp, about_dialog.cpp, about_dialog_from_executing_assembly_informations.cpp, about_dialog_system.cpp, colored_tab_pages.cpp, countries.cpp, fill_ellipse.cpp, fill_rectangle.cpp, fill_rounded_rectangle.cpp, graphics.cpp, hello_world_png.cpp, image.cpp, image_xpm.cpp, minesweeper.cpp, painting.cpp, status_bar.cpp, and toggle_button2.cpp.

Fields

static bitmap empty
 Represent an empty bitmap. More...
 

Constructors

 bitmap (const image &original)
 Initializes a new instance of the bitmap class from the specified existing image. More...
 
 bitmap (const image &original, const xtd::drawing::size &new_size)
 Initializes a new instance of the bitmap class from the specified existing image, scaled to the specified size. More...
 
 bitmap (const image &original, int32 width, int32 height)
 Initializes a new instance of the bitmap class from the specified existing image, scaled to the specified size. More...
 
 bitmap (const image &original, const rectangle &new_rect)
 Initializes a new instance of the bitmap class from the specified existing image, scaled to the specified rectangle. More...
 
 bitmap (const xtd::ustring &filename)
 Initializes a new instance of the bitmap class from the specified file. More...
 
 bitmap (const xtd::ustring &filename, bool use_icm)
 Initializes a new instance of the bitmap class from the specified file. More...
 
 bitmap (std::istream &stream)
 Initializes a new instance of the bitmap class from the specified data stream. More...
 
 bitmap (std::istream &stream, bool use_icm)
 Initializes a new instance of the bitmap class from the specified data stream. More...
 
 bitmap (const char *const *bits)
 Initializes a new instance of the bitmap class from the specified data xpm. More...
 
 bitmap (int32 width, int32 height)
 Initializes a new instance of the xtd::drawing::bitmap class with the specified size. More...
 
 bitmap (int32 width, int32 height, const graphics &g)
 Initializes a new instance of the xtd::drawing::bitmap class with the specified size and with the resolution of the specified xtd::drawing::raphics object. More...
 
 bitmap (int32 width, int32 height, xtd::drawing::imaging::pixel_format format)
 Initializes a new instance of the xtd::drawing::bitmap class with the specified size. More...
 
 bitmap (int32 width, int32 height, int32 stride, xtd::drawing::imaging::pixel_format format, intptr scan0)
 Initializes a new instance of the xtd::drawing::bitmap class with the specified size. More...
 
 bitmap (const xtd::drawing::size &size)
 Initializes a new instance of the xtd::drawing::bitmap class with the specified size. More...
 

Methods

bitmap clone (const rectangle &rect) const
 Creates a copy of the section of this xtd::drawing::bitmap defined with a specified rectangle. More...
 
bitmap clone (const rectangle_f &rect) const
 Creates a copy of the section of this xtd::drawing::bitmap defined with a specified rectangle. More...
 
intptr get_hbitmap () const
 Creates a GDI bitmap object from this xtd::drawing::bitmap. More...
 
intptr get_hbitmap (const color &background) const
 Creates a GDI bitmap object from this xtd::drawing::bitmap. More...
 
intptr get_hicon () const
 Returns the handle to an icon. More...
 
drawing::color get_pixel (int32 x, int32 y) const
 Gets the color of the specified pixel in this bitmap. More...
 
xtd::drawing::imaging::bitmap_data lock_bits (const rectangle &rect, xtd::drawing::imaging::image_lock_mode flags, xtd::drawing::imaging::pixel_format format)
 Locks a xtd::drawing::bitmap into system memory. More...
 
xtd::drawing::imaging::bitmap_data lock_bits (const rectangle &rect, xtd::drawing::imaging::image_lock_mode flags, xtd::drawing::imaging::pixel_format format, const xtd::drawing::imaging::bitmap_data &data)
 Locks a xtd::drawing::bitmap into system memory. More...
 
void make_transparent ()
 Makes the default transparent color transparent for this xtd::drawing::bitmap. More...
 
void make_transparent (const color &transparent_color)
 Makes the specified color transparent for this xtd::drawing::bitmap. More...
 
void set_pixel (int32 x, int32 y, const drawing::color &color)
 Sets the color of the specified pixel in this xtd::drawing::bitmap. More...
 
void set_resolution (int32 x_dpi, int32 y_dpi)
 Sets the resolution for this xtd::drawing::bitmap. More...
 
void unlock_bits (const xtd::drawing::imaging::bitmap_data &data)
 Unlocks this xtd::drawing::bitmap from system memory. More...
 
static bitmap from_hicon (intptr icon)
 Creates a xtd::drawing::bitmap from a Windows handle to an icon. More...
 

Additional Inherited Members

- Static Public Attributes inherited from xtd::drawing::image
static image empty
 Represent an empty xtd::drawing::image. More...
 
- Public Member Functions inherited from xtd::drawing::image
int32 flags () const noexcept
 Gets attribute flags for the pixel data of this xtd::drawing::image. More...
 
std::vector< guidframe_dimentions_list () const noexcept
 Gets an array of GUIDs that represent the dimensions of frames within this image. More...
 
intptr handle () const noexcept
 Gets the handle of this image. More...
 
int32 height () const noexcept
 Gets the height, in pixels, of this image. More...
 
float horizontal_resolution () const noexcept
 Gets the horizontal resolution, in pixels per inch, of this image. More...
 
imaging::color_palette palette () const noexcept
 Gets the color palette used for this image. More...
 
void palette (const imaging::color_palette &palette) noexcept
 Sets the color palette used for this image. More...
 
const size_fphysical_dimension () const noexcept
 Gets the width and height of this image. More...
 
imaging::pixel_format pixel_format () const noexcept
 Gets the pixel format for this image. More...
 
const std::vector< int32 > & property_id_list () const noexcept
 Gets IDs of the property items stored in this image. More...
 
const std::vector< imaging::property_item > & property_items () const noexcept
 Gets all the property items (pieces of metadata) stored in this image. More...
 
const imaging::image_formatraw_format () const noexcept
 Gets the file format of this image. More...
 
const drawing::sizesize () const noexcept
 Gets the width and height, in pixels, of this image. More...
 
const std::anytag () const noexcept
 Gets an object that provides additional data about the image. More...
 
void tag (const std::any &tag) noexcept
 Sets an object that provides additional data about the image. More...
 
float vertical_resolution () const noexcept
 Gets the vertical resolution, in pixels per inch, of this image. More...
 
int32 width () const noexcept
 Gets the width, in pixels, of this image. More...
 
image blur (int32 radius) const
 Blurs the image whith the specified radius. More...
 
graphics create_graphics ()
 Creates the xtd::drawing::graphics for the image. More...
 
bool equals (const image &image) const noexcept override
 
xtd::drawing::rectangle_f get_bounds (xtd::drawing::graphics_unit page_unit) const noexcept
 Gets the bounds of the image in the specified unit. More...
 
xtd::drawing::imaging::encoder_parameters get_encoder_parameter_list (xtd::guid encoder) const noexcept
 Returns information about the parameters supported by the specified image encoder. More...
 
size_t get_frame_count (const xtd::drawing::imaging::frame_dimension &dimension) const
 Returns the number of frames of the specified dimension. More...
 
xtd::drawing::imaging::property_item get_property_item (int32 propid)
 Gets the specified property item from this xtd::drawing::image. More...
 
xtd::drawing::image get_thmbnail_image (int32 thumb_width, int32 thunb_height) noexcept
 Returns a thumbnail for this xtd::drawing::image. More...
 
void rotate_flip (xtd::drawing::rotate_flip_type rotate_flip_type)
 Rotates, flips, or rotates and flips the xtd::drawing::image. More...
 
void save (const xtd::ustring &filename) const
 Saves this xtd::drawing::image to the specified file or stream. More...
 
void save (const xtd::ustring &filename, const xtd::drawing::imaging::image_format &format) const
 Saves this xtd::drawing::image to the specified file in the specified format. More...
 
void save (std::ostream &stream, const xtd::drawing::imaging::image_format &format) const
 Saves this image to the specified stream in the specified format. More...
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const noexcept
 Creates a shallow copy of the current object. More...
 
virtual xtd::ustring to_string () const noexcept
 Returns a sxd::ustring that represents the current object. More...
 
- Public Member Functions inherited from xtd::iequatable< image >
virtual bool equals (const image &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type. More...
 
- Static Public Member Functions inherited from xtd::drawing::image
static image from_file (const xtd::ustring &filename)
 Creates an image from the specified file. More...
 
static bitmap from_hbitmap (intptr hbitmap)
 Creates a xtd::drawing::bitmap from a handle to a GDI bitmap. More...
 
static image from_stream (std::istream &stream)
 Creates an xtd::drawing::image from the specified data stream. More...
 
static image from_data (const char *const *bits)
 Creates an xtd::drawing::image from the specified data pointer. More...
 
static int32 get_pixel_format_size (xtd::drawing::imaging::pixel_format pixfmt) noexcept
 Returns the color depth, in number of bits per pixel, of the specified pixel format. More...
 
static bool is_alpha_pixel_format (xtd::drawing::imaging::pixel_format pixfmt) noexcept
 Returns a value that indicates whether the pixel format for this xtd::drawing::image contains alpha information. More...
 
static bool is_canonical_pixel_format (xtd::drawing::imaging::pixel_format pixfmt) noexcept
 Returns a value that indicates whether the pixel format is 32 bits per pixel. More...
 
static bool is_extended_pixel_format (xtd::drawing::imaging::pixel_format pixfmt) noexcept
 Returns a value that indicates whether the pixel format is 64 bits per pixel. More...
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Constructor & Destructor Documentation

◆ bitmap() [1/14]

xtd::drawing::bitmap::bitmap ( const image original)
explicit

Initializes a new instance of the bitmap class from the specified existing image.

Parameters
originalThe xtd::drawing::image from which to create the new bitmap.

◆ bitmap() [2/14]

xtd::drawing::bitmap::bitmap ( const image original,
const xtd::drawing::size new_size 
)

Initializes a new instance of the bitmap class from the specified existing image, scaled to the specified size.

Parameters
originalThe xtd::drawing::image from which to create the new bitmap.
new_sizeThe xtd::drawing::size structure that represent the size of the new bitmap.

◆ bitmap() [3/14]

xtd::drawing::bitmap::bitmap ( const image original,
int32  width,
int32  height 
)

Initializes a new instance of the bitmap class from the specified existing image, scaled to the specified size.

Parameters
originalThe xtd::drawing::image from which to create the new bitmap.
widthThe width, in pixels, of the new xtd::drawing::bitmap.
heightThe height, in pixels, of the new xtd::drawing::bitmap.

◆ bitmap() [4/14]

xtd::drawing::bitmap::bitmap ( const image original,
const rectangle new_rect 
)

Initializes a new instance of the bitmap class from the specified existing image, scaled to the specified rectangle.

Parameters
originalThe xtd::drawing::image from which to create the new bitmap.
new_rectThe xtd::drawing::rect structure that represent the location and size of the new bitmap.

◆ bitmap() [5/14]

xtd::drawing::bitmap::bitmap ( const xtd::ustring filename)
explicit

Initializes a new instance of the bitmap class from the specified file.

Parameters
filenameThe bitmap file name and path.
Remarks
The file name and path can be relative to the application or an absolute path. Use this constructor to open images with the following file formats: BMP, GIF, EXIF, JPG, PNG and TIFF. For more information about supported formats, see Types of Bitmaps. The file remains locked until the xtd::drawing::bitmap is disposed.

◆ bitmap() [6/14]

xtd::drawing::bitmap::bitmap ( const xtd::ustring filename,
bool  use_icm 
)
explicit

Initializes a new instance of the bitmap class from the specified file.

Parameters
filenameThe bitmap file name and path.
use_icmtrue to use color correction for this xtd::drawing::bitmap; otherwise, false.
Remarks
The file name and path can be relative to the application or an absolute path. Use this constructor to open images with the following file formats: BMP, GIF, EXIF, JPG, PNG and TIFF. For more information about supported formats, see Types of Bitmaps. The file remains locked until the xtd::drawing::bitmap is disposed.

◆ bitmap() [7/14]

xtd::drawing::bitmap::bitmap ( std::istream &  stream)
explicit

Initializes a new instance of the bitmap class from the specified data stream.

Parameters
streamThe data stream used to load the image.
Remarks
You must keep the stream open for the lifetime of the xtd::drawing::bitmap.

◆ bitmap() [8/14]

xtd::drawing::bitmap::bitmap ( std::istream &  stream,
bool  use_icm 
)
explicit

Initializes a new instance of the bitmap class from the specified data stream.

Parameters
streamThe data stream used to load the image.
use_icmtrue to use color correction for this xtd::drawing::bitmap; otherwise, false.
Remarks
You must keep the stream open for the lifetime of the xtd::drawing::bitmap.
Due to a limitation of the GDI+ decoder, an xtd::argument_exception is thrown if you construct a bitmap from a .png image file with a single dimension greater than 65,535 pixels.

◆ bitmap() [9/14]

xtd::drawing::bitmap::bitmap ( const char *const *  bits)
explicit

Initializes a new instance of the bitmap class from the specified data xpm.

Parameters
bitsThe data xpm used to load the image.

◆ bitmap() [10/14]

xtd::drawing::bitmap::bitmap ( int32  width,
int32  height 
)

Initializes a new instance of the xtd::drawing::bitmap class with the specified size.

Parameters
widthThe width, in pixels, of the new bitmap.
heightThe height, in pixels, of the new bitmap.

◆ bitmap() [11/14]

xtd::drawing::bitmap::bitmap ( int32  width,
int32  height,
const graphics g 
)

Initializes a new instance of the xtd::drawing::bitmap class with the specified size and with the resolution of the specified xtd::drawing::raphics object.

Parameters
widthThe width, in pixels, of the new bitmap.
heightThe height, in pixels, of the new bitmap.
gThe Graphics object that specifies the resolution for the new Bitmap.
Remarks
The new xtd::drawing::bitmap that this method creates takes its horizontal and vertical resolution from the xtd::drawing::graphics::dpi_x and xtd::drawing::graphics::dpi_y properties of g, respectively.

◆ bitmap() [12/14]

xtd::drawing::bitmap::bitmap ( int32  width,
int32  height,
xtd::drawing::imaging::pixel_format  format 
)

Initializes a new instance of the xtd::drawing::bitmap class with the specified size.

Parameters
widthThe width, in pixels, of the new bitmap.
heightThe height, in pixels, of the new bitmap.
formatThe pixel format for the new xtd::drawing::bitmap class with the specified size and format.

◆ bitmap() [13/14]

xtd::drawing::bitmap::bitmap ( int32  width,
int32  height,
int32  stride,
xtd::drawing::imaging::pixel_format  format,
intptr  scan0 
)

Initializes a new instance of the xtd::drawing::bitmap class with the specified size.

Parameters
widthThe width, in pixels, of the new bitmap.
heightThe height, in pixels, of the new bitmap.
strideInteger that specifies the byte offset between the beginning of one scan line and the next. This is usually (but not necessarily) the number of bytes in the pixel format (for example, 2 for 16 bits per pixel) multiplied by the width of the bitmap. The value passed to this parameter must be a multiple of four.
formatThe pixel format for the new xtd::drawing::bitmap class with the specified size and format.
scan0Pointer to an array of bytes that contains the pixel data.

◆ bitmap() [14/14]

xtd::drawing::bitmap::bitmap ( const xtd::drawing::size size)
explicit

Initializes a new instance of the xtd::drawing::bitmap class with the specified size.

Parameters
sizethe size, in pixels, of the new bitmap.

Member Function Documentation

◆ clone() [1/2]

bitmap xtd::drawing::bitmap::clone ( const rectangle rect) const

Creates a copy of the section of this xtd::drawing::bitmap defined with a specified rectangle.

Parameters
rectDefines the portion of this bitmap to copy.

◆ clone() [2/2]

bitmap xtd::drawing::bitmap::clone ( const rectangle_f rect) const

Creates a copy of the section of this xtd::drawing::bitmap defined with a specified rectangle.

Parameters
rectDefines the portion of this bitmap to copy.

◆ from_hicon()

static bitmap xtd::drawing::bitmap::from_hicon ( intptr  icon)
static

Creates a xtd::drawing::bitmap from a Windows handle to an icon.

Parameters
hiconA handle to an icon.
Returns
The xtd::drawing::bitmap that this method creates.

◆ get_hbitmap() [1/2]

intptr xtd::drawing::bitmap::get_hbitmap ( ) const

Creates a GDI bitmap object from this xtd::drawing::bitmap.

Returns
A handle to the GDI bitmap object that this method creates.
Remarks
You are responsible for calling the GDI DeleteObject method to free the memory used by the GDI bitmap object. For more information about GDI bitmaps, see Bitmaps in the Windows GDI documentation.

◆ get_hbitmap() [2/2]

intptr xtd::drawing::bitmap::get_hbitmap ( const color background) const

Creates a GDI bitmap object from this xtd::drawing::bitmap.

Parameters
backgroundA xtd::drawing::color structure that specifies the background color. This parameter is ignored if the bitmap is totally opaque.
Returns
A handle to the GDI bitmap object that this method creates.
Remarks
You are responsible for calling the GDI DeleteObject method to free the memory used by the GDI bitmap object. For more information about GDI bitmaps, see Bitmaps in the Windows GDI documentation.

◆ get_hicon()

intptr xtd::drawing::bitmap::get_hicon ( ) const

Returns the handle to an icon.

Returns
A Windows handle to an icon with the same image as the xtd::drawing::bitmap.
Remarks
Initially, an icon created from the handle will have the same size as the original bitmap.

◆ get_pixel()

drawing::color xtd::drawing::bitmap::get_pixel ( int32  x,
int32  y 
) const

Gets the color of the specified pixel in this bitmap.

Parameters
xThe x-coordinate of the pixel to retrieve.
yThe y-coordinate of the pixel to retrieve.
Returns
A xtd::drawing::color structure that represents the color of the specified pixel.

◆ lock_bits() [1/2]

Locks a xtd::drawing::bitmap into system memory.

Parameters
rectA xtd::drawing::rectangle structure that specifies the portion of the xtd::drawing::bitmap to lock.
flagsAn xtd::drawing::imaging::image_lock_mode enumeration that specifies the access level (read/write) for the xtd::drawing::bitmap.
formatA xtd::drawing::imaging::pixel_format enumeration that specifies the data format of this xtd::drawing::bitmap.
Returns
A xtd::drawing::imaging::bitmap_data that contains information about this lock operation.
Remarks
Use the xtd::drawing::bitmap::lock_bits method to lock an existing bitmap in system memory so that it can be changed programmatically. You can change the color of an image with the xtd::drawing::bitmap::set_pixel method, although the xtd::drawing::bitmap::lock_bits method offers better performance for large-scale changes.
The xtd::drawing::imaging::bitmap_data specifies the attributes of the xtd::drawing::bitmap, such as size, pixel format, the starting address of the pixel data in memory, and length of each scan line (stride).
When calling this method, you should use a member of the xtd::drawing::imaging::pixel_format enumeration that contains a specific bits-per-pixel (BPP) value. Using xtd::drawing::imaging::pixel_format values such as xtd::drawing::imaging::pixel_format::indexed and xtd::drawing::imaging::pixel_format::gdi will throw an xtd::argument_exception. Also, passing the incorrect pixel format for a bitmap will throw an xtd::argument_exception.

◆ lock_bits() [2/2]

Locks a xtd::drawing::bitmap into system memory.

Parameters
rectA xtd::drawing::rectangle structure that specifies the portion of the xtd::drawing::bitmap to lock.
flagsAn xtd::drawing::imaging::image_lock_mode enumeration that specifies the access level (read/write) for the xtd::drawing::bitmap.
formatA xtd::drawing::imaging::pixel_format enumeration that specifies the data format of this xtd::drawing::bitmap.
dataA xtd::drawing::imaging::bitmap_data that contains information about the lock operation.
Returns
A xtd::drawing::imaging::bitmap_data that contains information about this lock operation.
Remarks
Use the xtd::drawing::bitmap::lock_bits method to lock an existing bitmap in system memory so that it can be changed programmatically. You can change the color of an image with the xtd::drawing::bitmap::set_pixel method, although the xtd::drawing::bitmap::lock_bits method offers better performance for large-scale changes.
The xtd::drawing::imaging::bitmap_data specifies the attributes of the xtd::drawing::bitmap, such as size, pixel format, the starting address of the pixel data in memory, and length of each scan line (stride).
When calling this method, you should use a member of the xtd::drawing::imaging::pixel_format enumeration that contains a specific bits-per-pixel (BPP) value. Using xtd::drawing::imaging::pixel_format values such as xtd::drawing::imaging::pixel_format::indexed and xtd::drawing::imaging::pixel_format::gdi will throw an xtd::argument_exception. Also, passing the incorrect pixel format for a bitmap will throw an xtd::argument_exception.

◆ make_transparent() [1/2]

void xtd::drawing::bitmap::make_transparent ( )

Makes the default transparent color transparent for this xtd::drawing::bitmap.

Remarks
The system palette defines one color as the default transparent, or alpha, color. This method makes the default transparent color transparent for this xtd::drawing::bitmap. If no transparent color is specified by the system, xtd::drawing::color::light_gray is the transparent color.
When you call xtd::drawing::bitmap::make_transparent, the bitmap will be converted to the xtd::drawing::imaging::pixel_format::format_32bpp_argb format, as this format supports an alpha channel.

◆ make_transparent() [2/2]

void xtd::drawing::bitmap::make_transparent ( const color transparent_color)

Makes the specified color transparent for this xtd::drawing::bitmap.

Parameters
transprent_colorThe xtd::drawing::color structure that represents the color to make transparent.
Remarks
When you call xtd::drawing::bitmap::make_transparent, the bitmap will be converted to the xtd::drawing::imaging::pixel_format::format_32bpp_argb format, as this format supports an alpha channel.

◆ set_pixel()

void xtd::drawing::bitmap::set_pixel ( int32  x,
int32  y,
const drawing::color color 
)

Sets the color of the specified pixel in this xtd::drawing::bitmap.

Parameters
xThe x-coordinate of the pixel to retrieve.
yThe y-coordinate of the pixel to retrieve.
colorA xtd::drawing::color structure that represents the color of the specified pixel.

◆ set_resolution()

void xtd::drawing::bitmap::set_resolution ( int32  x_dpi,
int32  y_dpi 
)

Sets the resolution for this xtd::drawing::bitmap.

Parameters
x_dpiThe horizontal resolution, in dots per inch, of the xtd::drawing::bitmap.
y_dpiThe vertical resolution, in dots per inch, of the xtd::drawing::bitmap.
Remarks
Use this method to set the desired resolution on a newly created bitmap. Changing the resolution of the image does not change its physical size.

◆ unlock_bits()

void xtd::drawing::bitmap::unlock_bits ( const xtd::drawing::imaging::bitmap_data data)

Unlocks this xtd::drawing::bitmap from system memory.

Parameters
dataA xtd::drawing::imaging::bitmap_data that specifies information about the lock operation.
Remarks
The xtd::drawing::imaging::bitmap_data specifies the attributes of the xtd::drawing::bitmap, such as size, pixel format, the starting address of the pixel data in memory, and length of each scan line (stride).

Member Data Documentation

◆ empty

bitmap xtd::drawing::bitmap::empty
static

Represent an empty bitmap.


The documentation for this class was generated from the following file: