TBTK
ImagePanel.h
Go to the documentation of this file.
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 
23 #ifndef COM_DAFER45_TBTK_IMAGE_PANEL
24 #define COM_DAFER45_TBTK_IMAGE_PANEL
25 
26 #include <wx/wx.h>
27 #include <wx/sizer.h>
28 
29 #include <opencv2/core/core.hpp>
30 
31 namespace TBTK{
32 
33 class ImagePanel : public wxPanel{
34 public:
36  ImagePanel(wxWindow *parent);
37 
39  ~ImagePanel();
40 
42  void setImage(wxString file, wxBitmapType format);
43 
45  void setImage(const cv::Mat &image);
46 
48  void onPaintEvent(wxPaintEvent &event);
49 
51  void onSizeEvent(wxSizeEvent &event);
52 
54  void paintNow();
55 
57  void render(wxDC &dc);
58 protected:
59  DECLARE_EVENT_TABLE();
60 private:
62  wxImage image;
63 
65  wxBitmap resizedImage;
66 
68  int width;
69 
71  int height;
72 };
73 
74 inline void ImagePanel::setImage(const cv::Mat &image){
75  unsigned char *data = new unsigned char[image.elemSize()*image.cols*image.rows];
76  for(unsigned int n = 0; n < image.elemSize()*image.cols*image.rows; n++)
77  data[n] = image.data[n];
78 
79  this->image = wxImage(image.cols, image.rows, data, false);
80  width = -1;
81  height = -1;
82 }
83 
84 }; //End namespace TBTK
85 
86 #endif
void setImage(wxString file, wxBitmapType format)
void onSizeEvent(wxSizeEvent &event)
Definition: ImagePanel.h:33
void render(wxDC &dc)
ImagePanel(wxWindow *parent)
Definition: ModelFactory.h:35
void onPaintEvent(wxPaintEvent &event)