xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
image.h
Go to the documentation of this file.
1 #pragma once
5 #include <any>
6 #include <cstdint>
7 #include <memory>
8 #include <iostream>
9 #include <xtd/object.h>
10 #include <xtd/ustring.h>
11 #include "../drawing_export.h"
12 #include "imaging/color_palette.h"
14 #include "imaging/image_flags.h"
15 #include "imaging/image_format.h"
16 #include "imaging/pixel_format.h"
17 #include "imaging/property_item.h"
18 #include "graphics.h"
19 #include "rectangle.h"
20 #include "size.h"
21 #include "size_f.h"
22 
24 namespace xtd {
26  namespace drawing {
34  class drawing_export_ image : public object {
35  public:
37  image() = default;
38  image(const image& image) = default;
39  image& operator=(const image& image) = default;
40  ~image();
41  bool operator==(const image& image) const {return data_->handle_ == image.data_->handle_;}
42  bool operator!=(const image& image) const {return !operator==(image);}
44 
46 
49  static image empty;
51 
53 
75  int32_t flags() const {return static_cast<int32_t>(data_->flags_);}
76 
82  const std::vector<guid>& frame_dimentions_list() const {return data_->frame_dimentions_list_;}
83 
86  intptr_t handle() const {return data_->handle_;}
87 
90  int32_t height() const {return data_->size_.height();}
91 
94  float horizontal_resolution() const {return data_->horizontal_resolution_;}
95 
99  imaging::color_palette palette() const {return data_->palette_;}
102  void palette(const imaging::color_palette& palette) {data_->palette_ = palette;}
103 
107  const size_f& physical_dimension() const {return data_->physical_dimension_;}
108 
111  imaging::pixel_format pixel_format() const {return data_->pixel_format_;}
112 
116  const std::vector<int32_t>& property_id_list() const {return data_->property_id_list_;}
117 
121  const std::vector<imaging::property_item>& property_items() const {return data_->property_ityems_;}
122 
125  const imaging::image_format& raw_format() const {return data_->raw_format_;}
126 
129  const drawing::size& size() const {return data_->size_;}
130 
133  const std::any& tag() const {return data_->tag_;}
136  void tag(const std::any& tag) {data_->tag_ = tag;}
137 
140  float vertical_resolution() const {return data_->vertical_resolution_;}
141 
144  int32_t width() const {return data_->size_.width();}
146 
148 
153  graphics create_graphics() {return graphics::from_image(*this);}
154 
155  static image from_hbitmap(intptr_t hbitmap) {return image(hbitmap);}
156 
160  static image from_file(const xtd::ustring& filename) {return image(filename);}
161 
162  static image from_stream(std::istream& stream) {return image(stream);}
163 
164  static image from_data(const char* const* bits) {return image(bits);}
165 
166  void save(const xtd::ustring& filename) const;
167  void save(const xtd::ustring& filename, const imaging::image_format& format) const;
168  void save(std::ostream& stream, const imaging::image_format& format) const;
170 
171  protected:
172  explicit image(intptr_t hbitmap);
173  explicit image(const xtd::ustring& fileName);
174  explicit image(std::istream& stream);
175  explicit image(const char* const* bits);
176  image(int32_t width, int32_t height);
177  image(const image& image, int32_t width, int32_t height);
178  image(const image& image, const rectangle& rect);
179  void update_properties();
180 
181  struct data {
183  std::vector<guid> frame_dimentions_list_;
184  intptr_t handle_ = 0;
185  float horizontal_resolution_ = .0f;
186  imaging::color_palette palette_;
188  size_f physical_dimension_;
189  std::vector<int32_t> property_id_list_;
190  std::vector<imaging::property_item> property_ityems_;
191  imaging::image_format raw_format_;
192  drawing::size size_;
193  std::any tag_;
194  float vertical_resolution_ = .0f;
195  };
196  std::shared_ptr<data> data_ = std::make_shared<data>();
197  };
198  }
199 }
int32_t flags() const
Gets attribute flags for the pixel data of this Image.
Definition: image.h:75
const std::any & tag() const
Gets an object that provides additional data about the image.
Definition: image.h:133
const size_f & physical_dimension() const
Gets the width and height of this image.
Definition: image.h:107
The pixel format is undefined.
Specifies the file format of the image. Not inheritable.
Definition: image_format.h:25
image_flags
Specifies the attributes of the pixel data contained in an xtd::drawing::image object. The xtd::drawing:iImage::flags property returns a member of this enumeration.
Definition: image_flags.h:22
static image from_file(const xtd::ustring &filename)
Creates an image from the specified file.
Definition: image.h:160
Contains xtd::drawing::imaging::color_palette class.
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
const std::vector< imaging::property_item > & property_items() const
Gets all the property items (pieces of metadata) stored in this image.
Definition: image.h:121
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
const imaging::image_format & raw_format() const
Gets the file format of this image.
Definition: image.h:125
Contains xtd::drawing::imaging::image_flags class.
const std::vector< int32_t > & property_id_list() const
Gets IDs of the property items stored in this image.
Definition: image.h:116
intptr_t handle() const
Get the handle of this image.
Definition: image.h:86
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:50
Contains xtd::drawing::imaging::frame_dimension class.
Stores an ordered pair of floating-point, which specify a height and width.
Definition: size_f.h:24
const std::vector< guid > & frame_dimentions_list() const
Gets an array of GUIDs that represent the dimensions of frames within this image. ...
Definition: image.h:82
Contains xtd::drawing::rectangle class.
pixel_format
Specifies the format of the color data for each pixel in the image.
Definition: pixel_format.h:25
imaging::pixel_format pixel_format() const
Gets the pixel format for this image.
Definition: image.h:111
Contains xtd::drawing::imaging::property_item class.
There is no format information.
imaging::color_palette palette() const
Gets the color palette used for this image.
Definition: image.h:99
Contains xtd::drawing::size class.
const drawing::size & size() const
Gets the width and height, in pixels, of this image.
Definition: image.h:129
Stores a set of four integers that represent the location and size of a rectangle.
Definition: rectangle.h:25
int32_t height() const
Gets the height, in pixels, of this image.
Definition: image.h:90
Contains xtd::ustring class.
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
An abstract base class that provides functionality for the bitmap and metafile descended classes...
Definition: image.h:34
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:30
Contains xtd::drawing::size_f class.
float vertical_resolution() const
Gets the vertical resolution, in pixels per inch, of this image.
Definition: image.h:140
Defines an array of colors that make up a color palette. The colors are 32-bit ARGB colors...
Definition: color_palette.h:29
void palette(const imaging::color_palette &palette)
Sets the color palette used for this image.
Definition: image.h:102
int32_t width() const
Gets the width, in pixels, of this image.
Definition: image.h:144
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:48
Contains xtd::drawing::imaging::image_format class.
void tag(const std::any &tag)
Sets an object that provides additional data about the image.
Definition: image.h:136
static image empty
Represent an empty xtd::drawing::image.
Definition: image.h:49
Contains xtd::drawing::graphics class.
float horizontal_resolution() const
Gets the horizontal resolution, in pixels per inch, of this image.
Definition: image.h:94
Contains xtd::drawing::imaging::pixel_format enum class.
graphics create_graphics()
Creates the xtd::drawing::graphics for the image.
Definition: image.h:153
Definition: image.h:181