xtd - Reference Guide 0.2.0
image.h
Go to the documentation of this file.
1 #pragma once
5 #include <any>
6 #include <cstdint>
7 #include <map>
8 #include <memory>
9 #include <iostream>
10 #include <xtd/object.h>
11 #include <xtd/ustring.h>
12 #include "../drawing_export.h"
13 #include "imaging/color_palette.h"
16 #include "imaging/image_flags.h"
17 #include "imaging/image_format.h"
18 #include "imaging/pixel_format.h"
19 #include "imaging/property_item.h"
20 #include "graphics.h"
21 #include "graphics_unit.h"
22 #include "rectangle.h"
23 #include "rotate_flip_type.h"
24 #include "size.h"
25 #include "size_f.h"
26 
28 namespace xtd {
30  namespace drawing {
32  class bitmap;
34 
47  class drawing_export_ image : public object {
48  public:
50  image() = default;
51  image(const image& image) = default;
52  image& operator =(const image& image) = default;
53  ~image();
54  bool operator ==(const image& image) const;
55  bool operator !=(const image& image) const;
57 
59 
62  static image empty;
64 
66 
88  int32_t flags() const;
89 
95  std::vector<guid> frame_dimentions_list() const;
96 
99  intptr_t handle() const;
100 
103  int32_t height() const;
104 
107  float horizontal_resolution() const;
108 
112  imaging::color_palette palette() const;
115  void palette(const imaging::color_palette& palette);
116 
120  const size_f& physical_dimension() const;
121 
125 
129  const std::vector<int32_t>& property_id_list() const;
130 
134  const std::vector<imaging::property_item>& property_items() const;
135 
138  const imaging::image_format& raw_format() const;
139 
142  const drawing::size& size() const;
143 
146  const std::any& tag() const;
149  void tag(const std::any& tag);
150 
153  float vertical_resolution() const;
154 
157  int32_t width() const;
159 
161 
163 
168 
172  static image from_file(const xtd::ustring& filename) {return image(filename);}
173 
178  static bitmap from_hbitmap(intptr_t hbitmap);
179 
185  static image from_stream(std::istream& stream);
186 
191  static image from_data(const char* const* bits);
192 
196  xtd::drawing::rectangle_f get_bounds(xtd::drawing::graphics_unit page_unit) const;
197 
201  xtd::drawing::imaging::encoder_parameters get_encoder_parameter_list(xtd::guid encoder) const;
202 
209  size_t get_frame_count(const xtd::drawing::imaging::frame_dimension& dimension) const;
210 
214  static int32_t get_pixel_format_size(xtd::drawing::imaging::pixel_format pixfmt);
215 
222  xtd::drawing::imaging::property_item get_property_item(int32_t propid);
223 
230  xtd::drawing::image get_thmbnail_image(int32_t thumb_width, int32_t thunb_height);
231 
235  static bool is_alpha_pixel_format(xtd::drawing::imaging::pixel_format pixfmt);
236 
240  static bool is_canonical_pixel_format(xtd::drawing::imaging::pixel_format pixfmt);
241 
245  static bool is_extended_pixel_format(xtd::drawing::imaging::pixel_format pixfmt);
246 
252 
257  void save(const xtd::ustring& filename) const;
261  void save(const xtd::ustring& filename, const xtd::drawing::imaging::image_format& format) const;
267  void save(std::ostream& stream, const xtd::drawing::imaging::image_format& format) const;
269 
270  protected:
272  explicit image(intptr_t hbitmap);
273  explicit image(const xtd::ustring& fileName);
274  explicit image(std::istream& stream);
275  explicit image(const char* const* bits);
276  image(int32_t width, int32_t height);
277  image(const image& image, int32_t width, int32_t height);
278  image(const image& image, const rectangle& rect);
280 
281  private:
282  void update_properties();
283 
284  struct data {
286  std::map<xtd::guid, size_t> frame_dimensions = {{xtd::drawing::imaging::frame_dimension::page().guid(), 1}};
287  intptr_t handle_ = 0;
288  float horizontal_resolution_ = .0f;
289  imaging::color_palette palette_;
291  size_f physical_dimension_;
292  std::vector<int32_t> property_id_list_;
293  std::vector<imaging::property_item> property_items_;
294  imaging::image_format raw_format_;
295  drawing::size size_;
296  std::any tag_;
297  float vertical_resolution_ = .0f;
298  xtd::drawing::imaging::encoder_parameters encoder_parameter_list_;
299  };
300  std::shared_ptr<data> data_ = std::make_shared<data>();
301  };
302  }
303 }
rotate_flip_type
Specifies how much an image is rotated and the axis used to flip the image.
Definition: rotate_flip_type.h:19
static graphics from_image(const xtd::drawing::image &image)
Creates a new xtd::drawing::graphics from the specified xtd::drawing::image.
Contains xtd::drawing::rotate_flip_type enum class.
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:20
static image from_file(const xtd::ustring &filename)
Creates an image from the specified file.
Definition: image.h:172
Enum flags attribute.
Contains xtd::drawing::imaging::color_palette class.
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:30
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Stores a set of four floating-point numbers that represent the location and size of a rectangle...
Definition: rectangle_f.h:34
Contains xtd::drawing::imaging::image_flags class.
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:51
Contains xtd::drawing::imaging::frame_dimension class.
Stores an ordered pair of floating-point, which specify a height and width.
Definition: size_f.h:29
Encapsulates a metadata property to be included in an image file. Not inheritable.
Definition: property_item.h:25
Encapsulates a GDI+ bitmap, which consists of the pixel data for a graphics image and its attributes...
Definition: bitmap.h:24
Contains xtd::drawing::rectangle class.
Encapsulates an array of EncoderParameter objects.
Definition: encoder_parameters.h:22
static frame_dimension page()
Gets the page dimension.
Definition: frame_dimension.h:49
pixel_format
Specifies the format of the color data for each pixel in the image.
Definition: pixel_format.h:23
Provides properties that get the frame dimensions of an image. Not inheritable.
Definition: frame_dimension.h:23
Contains xtd::drawing::imaging::property_item class.
There is no format information.
Contains xtd::drawing::size class.
Stores a set of four integers that represent the location and size of a rectangle.
Definition: rectangle.h:44
Contains xtd::ustring class.
const xtd::guid & guid() const
Gets a globally unique identifier (GUID) that represents this frame_dimension object.
Definition: frame_dimension.h:45
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:47
Contains xtd::drawing::imaging::encoder_parameters class.
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.
Represents a globally unique identifier (GUID). A GUID is a 128-bit integer (16 bytes) that can be us...
Definition: guid.h:23
Contains xtd::drawing::graphics_unit enum class.
Defines an array of colors that make up a color palette. The colors are 32-bit ARGB colors...
Definition: color_palette.h:29
graphics_unit
Specifies the unit of measure for the given data. This enumeration has a flags attribute that allows ...
Definition: graphics_unit.h:17
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:70
Contains xtd::drawing::imaging::image_format class.
static image empty
Represent an empty xtd::drawing::image.
Definition: image.h:62
Contains xtd::drawing::graphics class.
Contains xtd::drawing::imaging::pixel_format enum class.
graphics create_graphics()
Creates the xtd::drawing::graphics for the image.
Definition: image.h:167