xtd 0.2.0
Loading...
Searching...
No Matches
graphics.cpp

Shows how to use xtd::drawing::graphics class.

#include <xtd/diagnostics/process>
#include <xtd/drawing/drawing_2d/linear_gradient_brush>
#include <xtd/drawing/drawing_2d/radial_gradient_brush>
#include <xtd/drawing/bitmap>
#include <xtd/drawing/brushes>
#include <xtd/drawing/graphics>
#include <xtd/drawing/system_fonts>
#include <xtd/io/path>
using namespace xtd;
using namespace xtd::collections::generic;
using namespace xtd::diagnostics;
using namespace xtd::drawing;
using namespace xtd::drawing::drawing_2d;
using namespace xtd::io;
auto main() -> int {
auto drawing_bitmap = bitmap {640, 480};
auto graphics = graphics::from_image(drawing_bitmap);
graphics.clear(color::cyan);
graphics.draw_string("Drawing with graphics", drawing::font {"Arial", 34, font_style::regular}, brushes::dark_cyan(), {20.0f, 20.0f, drawing_bitmap.width() - 180.0f, drawing_bitmap.height() - 40.0f});
graphics.fill_ellipse(radial_gradient_brush(point {drawing_bitmap.width() - 100, 100}, color::white, color::yellow, 75), drawing_bitmap.width() - 150, 50, 100, 100);
graphics.draw_ellipse(pen {color::yellow_green, 2}, drawing_bitmap.width() - 150, 50, 100, 100);
graphics.fill_rectangle(brushes::spring_green(), 0, drawing_bitmap.height() - 100, drawing_bitmap.width(), 100);
graphics.fill_rectangle(brushes::red(), drawing_bitmap.width() / 2 - 140, drawing_bitmap.height() - 180, 280, 150);
graphics.fill_rectangle(brushes::black(), drawing_bitmap.width() / 2 - 30, drawing_bitmap.height() - 140, 60, 110);
graphics.fill_rectangle(brushes::white(), drawing_bitmap.width() / 2 - 120, drawing_bitmap.height() - 140, 70, 60);
graphics.fill_rectangle(brushes::white(), drawing_bitmap.width() / 2 + 50, drawing_bitmap.height() - 140, 70, 60);
graphics.fill_polygon(linear_gradient_brush {rectangle {drawing_bitmap.width() / 2 - 160, drawing_bitmap.height() - 300, 320, 120}, color::brown, color::sandy_brown, linear_gradient_mode::backward_diagonal}, list<point> {{drawing_bitmap.width() / 2, drawing_bitmap.height() - 300}, {drawing_bitmap.width() / 2 + 160, drawing_bitmap.height() - 180}, {drawing_bitmap.width() / 2 - 160, drawing_bitmap.height() - 180},});
drawing_bitmap.save(path::combine(path::get_temp_path(), "graphics.png"));
process::start(path::combine(path::get_temp_path(), "graphics.png"));
}
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:33
Encapsulates a GDI+ bitmap, which consists of the pixel data for a graphics image and its attributes....
Definition bitmap.h:26
Encapsulates a xtd::drawing::brush with a linear gradient. This class cannot be inherited.
Definition linear_gradient_brush.h:31
Encapsulates a xtd::drawing::brush with a radial gradient. This class cannot be inherited.
Definition radial_gradient_brush.h:30
Defines a particular format for text, including font face, size, and style attributes....
Definition font.h:45
int32 height() const noexcept
Gets the line spacing of this font.
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition graphics.h:70
void draw_string(const xtd::ustring &s, const xtd::drawing::font &font, const xtd::drawing::brush &brush, const xtd::drawing::rectangle_f &layout_rectangle)
Draws the specified text string at the specified rectangle with the specified xtd::drawing::brush and...
void fill_polygon(const xtd::drawing::brush &brush, const std::vector< xtd::drawing::point > &points)
Fills the interior of a polygon defined by an array of points specified by xtd::drawing::point struct...
void clear(const color &color)
Clears the entire drawing surface and fills it with the specified background color.
void fill_ellipse(const xtd::drawing::brush &brush, const xtd::drawing::rectangle &rect)
Fills the interior of an ellipse defined by a bounding rectangle specified by a xtd::drawing::rectang...
void fill_rectangle(const xtd::drawing::brush &brush, const xtd::drawing::rectangle &rect)
Fills the interior of a rectangle specified by a xtd::drawing::rectangle structure.
void draw_ellipse(const xtd::drawing::pen &pen, const xtd::drawing::rectangle &rect)
Draws an ellipse specified by a bounding xtd::drawing::rectangle structure.
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition pen.h:35
float width() const noexcept
Gets the width of this xtd::drawing::pen, in units of the xtd::drawing::graphics object used for draw...
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition point.h:54
Stores a set of four integers that represent the location and size of a rectangle.
Definition rectangle.h:44
int32 width() const noexcept
Gets the width of this xtd::drawing::rectangle structure.
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition dictionary.h:15
The xtd::diagnostics namespace provides classes that allow you to interact with system processes,...
Definition assert_dialog_result.h:10
The xtd::drawing::drawing_2d namespace provides advanced two-dimensional and vector graphics function...
Definition compositing_mode.h:12
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.h:11
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.h:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10