xtd 0.2.0
draw_image.cpp

shows how to draw image in paint event using xtd::drawing::graphics::draw_image.

Windows

macOS

Gnome

#include <xtd/forms/application>
#include <xtd/forms/form>
#include <xtd/forms/images>
#include <xtd/math>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
class form_main : public form {
public:
form_main() {
text("Draw image example");
}
protected:
void on_paint(paint_event_args& e) override {
auto image_size = math::min(e.clip_rectangle().width, e.clip_rectangle().height);
auto image_rect = rectangle((e.clip_rectangle().width - image_size) / 2, (e.clip_rectangle().height - image_size) / 2, image_size, image_size);
e.graphics().draw_image(image, image_rect);
}
private:
xtd::drawing::image image = images::from_name("system-file-manager", xtd::drawing::size {1024, 1024});
};
auto main() -> int {
application::run(form_main());
}
An abstract base class that provides functionality for the bitmap and metafile descended classes.
Definition image.hpp:49
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
void on_paint(paint_event_args &e) override
Raises the xtd::forms::control::paint event.
static xtd::drawing::image from_name(const xtd::string &name)
Gets image object with specified name.
Definition images.hpp:1268
Provides data for the xtd::forms::control::paint event.
Definition paint_event_args.hpp:30
static xtd::byte min(xtd::byte a, xtd::byte b) noexcept
Returns the smaller of two 8-bit unsigned integers.
@ e
The E key.
Definition console_key.hpp:96
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.hpp:10
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Stores a set of four integers that represent the location and size of a rectangle.
Definition rectangle.hpp:44
Stores an ordered pair of integers, which specify a height and width.
Definition size.hpp:31