xtd 0.2.0
Loading...
Searching...
No Matches
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 {
form::on_paint(e);
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
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
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
Provides data for the xtd::forms::control::paint event.
Definition paint_event_args.hpp:30
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition brush.hpp:18
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.hpp:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10