TBTK
Need a break? Support the development by playing Polarity Puzzles
ImagePanel.h
1 /* Copyright 2017 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
17 
24 #ifndef COM_DAFER45_TBTK_IMAGE_PANEL
25 #define COM_DAFER45_TBTK_IMAGE_PANEL
26 
27 #include <wx/wx.h>
28 #include <wx/sizer.h>
29 
30 #include <opencv2/core/core.hpp>
31 
32 namespace TBTK{
33 
34 class ImagePanel : public wxPanel{
35 public:
37  ImagePanel(wxWindow *parent);
38 
40  ~ImagePanel();
41 
43  void setImage(wxString file, wxBitmapType format);
44 
46  void setImage(const cv::Mat &image);
47 
49  void onPaintEvent(wxPaintEvent &event);
50 
52  void onSizeEvent(wxSizeEvent &event);
53 
55  void paintNow();
56 
58  void render(wxDC &dc);
59 protected:
60  DECLARE_EVENT_TABLE();
61 private:
63  wxImage image;
64 
66  wxBitmap resizedImage;
67 
69  int width;
70 
72  int height;
73 };
74 
75 inline void ImagePanel::setImage(const cv::Mat &image){
76  unsigned char *data = new unsigned char[image.elemSize()*image.cols*image.rows];
77  for(unsigned int n = 0; n < image.elemSize()*image.cols*image.rows; n++)
78  data[n] = image.data[n];
79 
80  this->image = wxImage(image.cols, image.rows, data, false);
81  width = -1;
82  height = -1;
83 }
84 
85 }; //End namespace TBTK
86 
87 #endif
88 
Definition: Boolean.h:32