]>
Commit | Line | Data |
---|---|---|
01111366 RR |
1 | /* |
2 | * Program: image | |
1d5b7a0b | 3 | * |
01111366 RR |
4 | * Author: Robert Roebling |
5 | * | |
6 | * Copyright: (C) 1998, Robert Roebling | |
7 | * | |
8 | */ | |
9 | ||
3d05544e JS |
10 | // For compilers that support precompilation, includes "wx/wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #ifdef __BORLANDC__ | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
17 | #ifndef WX_PRECOMP | |
01111366 | 18 | #include "wx/wx.h" |
3d05544e JS |
19 | #endif |
20 | ||
01111366 | 21 | #include "wx/image.h" |
a23fd0e1 | 22 | #include "wx/file.h" |
a8d4e3ac VS |
23 | #include "wx/mstream.h" |
24 | #include "wx/wfstream.h" | |
a23fd0e1 | 25 | |
dc1dbfc6 | 26 | #include "smile.xbm" |
bea56879 | 27 | #include "smile.xpm" |
dc1dbfc6 | 28 | |
a8d4e3ac | 29 | |
01111366 RR |
30 | // derived classes |
31 | ||
32 | class MyFrame; | |
33 | class MyApp; | |
34 | ||
35 | // MyCanvas | |
36 | ||
37 | class MyCanvas: public wxScrolledWindow | |
38 | { | |
1d5b7a0b VZ |
39 | public: |
40 | MyCanvas() {}; | |
01111366 | 41 | MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size ); |
1d5b7a0b | 42 | ~MyCanvas(); |
01111366 | 43 | void OnPaint( wxPaintEvent &event ); |
9390a202 | 44 | void CreateAntiAliasedBitmap(); |
1d5b7a0b | 45 | |
e1929140 RR |
46 | wxBitmap *my_horse_png; |
47 | wxBitmap *my_horse_jpeg; | |
48 | wxBitmap *my_horse_gif; | |
ca26177c | 49 | wxBitmap *my_horse_bmp; |
cbd4be25 | 50 | wxBitmap *my_horse_pcx; |
6319afe3 | 51 | wxBitmap *my_horse_pnm; |
60a41aee | 52 | wxBitmap *my_horse_tiff; |
9d8bdf2d VS |
53 | wxBitmap *my_horse_xpm; |
54 | ||
dc1dbfc6 | 55 | wxBitmap *my_smile_xbm; |
e8fdc264 | 56 | wxBitmap *my_square; |
9390a202 | 57 | wxBitmap *my_anti; |
1d5b7a0b | 58 | |
bea56879 VZ |
59 | protected: |
60 | wxBitmap m_bmpSmileXpm; | |
61 | wxIcon m_iconSmileXpm; | |
62 | ||
60a41aee | 63 | private: |
1d5b7a0b VZ |
64 | DECLARE_DYNAMIC_CLASS(MyCanvas) |
65 | DECLARE_EVENT_TABLE() | |
01111366 RR |
66 | }; |
67 | ||
68 | // MyFrame | |
69 | ||
70 | class MyFrame: public wxFrame | |
71 | { | |
1d5b7a0b VZ |
72 | public: |
73 | MyFrame(); | |
01111366 | 74 | |
01111366 | 75 | void OnAbout( wxCommandEvent &event ); |
ab0f0386 | 76 | void OnNewFrame( wxCommandEvent &event ); |
01111366 | 77 | void OnQuit( wxCommandEvent &event ); |
1d5b7a0b | 78 | |
01111366 | 79 | MyCanvas *m_canvas; |
1d5b7a0b | 80 | |
60a41aee | 81 | private: |
1d5b7a0b VZ |
82 | DECLARE_DYNAMIC_CLASS(MyFrame) |
83 | DECLARE_EVENT_TABLE() | |
01111366 RR |
84 | }; |
85 | ||
ab0f0386 VZ |
86 | class MyImageFrame : public wxFrame |
87 | { | |
88 | public: | |
89 | MyImageFrame(wxFrame *parent, const wxBitmap& bitmap) | |
90 | : wxFrame(parent, -1, _T("Frame with image"), | |
91 | wxDefaultPosition, wxDefaultSize, | |
f6bcfd97 | 92 | wxCAPTION | wxSYSTEM_MENU), |
ab0f0386 VZ |
93 | m_bitmap(bitmap) |
94 | { | |
95 | SetClientSize(bitmap.GetWidth(), bitmap.GetHeight()); | |
96 | } | |
97 | ||
98 | void OnPaint(wxPaintEvent& WXUNUSED(event)) | |
99 | { | |
100 | wxPaintDC dc( this ); | |
101 | dc.DrawBitmap( m_bitmap, 0, 0 ); | |
102 | } | |
103 | ||
104 | private: | |
105 | wxBitmap m_bitmap; | |
106 | ||
107 | DECLARE_EVENT_TABLE() | |
108 | }; | |
109 | ||
01111366 RR |
110 | // MyApp |
111 | ||
112 | class MyApp: public wxApp | |
113 | { | |
1d5b7a0b VZ |
114 | public: |
115 | virtual bool OnInit(); | |
01111366 RR |
116 | }; |
117 | ||
118 | // main program | |
119 | ||
120 | IMPLEMENT_APP(MyApp) | |
121 | ||
122 | // MyCanvas | |
123 | ||
124 | IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow) | |
125 | ||
ab0f0386 VZ |
126 | BEGIN_EVENT_TABLE(MyImageFrame, wxFrame) |
127 | EVT_PAINT(MyImageFrame::OnPaint) | |
128 | END_EVENT_TABLE() | |
129 | ||
1d5b7a0b VZ |
130 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) |
131 | EVT_PAINT(MyCanvas::OnPaint) | |
01111366 RR |
132 | END_EVENT_TABLE() |
133 | ||
acbd13a3 | 134 | MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, |
1d5b7a0b | 135 | const wxPoint &pos, const wxSize &size ) |
81278df2 VZ |
136 | : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER ) |
137 | #if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW | |
138 | , m_bmpSmileXpm((const char **) smile_xpm) | |
139 | , m_iconSmileXpm((const char **) smile_xpm) | |
140 | #endif | |
01111366 | 141 | { |
60a41aee RR |
142 | my_horse_png = (wxBitmap*) NULL; |
143 | my_horse_jpeg = (wxBitmap*) NULL; | |
144 | my_horse_gif = (wxBitmap*) NULL; | |
145 | my_horse_bmp = (wxBitmap*) NULL; | |
146 | my_horse_pcx = (wxBitmap*) NULL; | |
147 | my_horse_pnm = (wxBitmap*) NULL; | |
148 | my_horse_tiff = (wxBitmap*) NULL; | |
9d8bdf2d | 149 | my_horse_xpm = (wxBitmap*) NULL; |
dc1dbfc6 | 150 | my_smile_xbm = (wxBitmap*) NULL; |
60a41aee RR |
151 | my_square = (wxBitmap*) NULL; |
152 | my_anti = (wxBitmap*) NULL; | |
153 | ||
154 | SetBackgroundColour(* wxWHITE); | |
155 | ||
156 | wxBitmap bitmap( 100, 100 ); | |
157 | ||
158 | wxMemoryDC dc; | |
159 | dc.SelectObject( bitmap ); | |
160 | dc.SetBrush( wxBrush( "orange", wxSOLID ) ); | |
cf3da716 | 161 | dc.SetPen( *wxBLACK_PEN ); |
60a41aee | 162 | dc.DrawRectangle( 0, 0, 100, 100 ); |
cf3da716 RR |
163 | dc.SetBrush( *wxWHITE_BRUSH ); |
164 | dc.DrawRectangle( 20, 20, 60, 60 ); | |
60a41aee RR |
165 | dc.SelectObject( wxNullBitmap ); |
166 | ||
167 | // try to find the directory with our images | |
168 | wxString dir; | |
169 | if ( wxFile::Exists("./horse.png") ) | |
81278df2 | 170 | dir = "./"; |
60a41aee RR |
171 | else if ( wxFile::Exists("../horse.png") ) |
172 | dir = "../"; | |
173 | else | |
174 | wxLogWarning("Can't find image files in either '.' or '..'!"); | |
175 | ||
a8d4e3ac | 176 | wxImage image = bitmap.ConvertToImage(); |
60a41aee | 177 | |
bea56879 | 178 | #if wxUSE_LIBPNG |
176fe5af | 179 | if ( !image.SaveFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG )) |
60a41aee | 180 | wxLogError("Can't save file"); |
f6bcfd97 | 181 | |
176fe5af | 182 | image.Destroy(); |
60a41aee | 183 | |
cc977e5f | 184 | image.LoadFile( dir + wxString("test.png") ); |
a8d4e3ac | 185 | my_square = new wxBitmap( image ); |
f6bcfd97 | 186 | |
176fe5af | 187 | image.Destroy(); |
cc977e5f | 188 | |
176fe5af | 189 | if ( !image.LoadFile( dir + wxString("horse.png")) ) |
60a41aee RR |
190 | wxLogError("Can't load PNG image"); |
191 | else | |
a8d4e3ac | 192 | my_horse_png = new wxBitmap( image ); |
bea56879 | 193 | #endif // wxUSE_LIBPNG |
60a41aee | 194 | |
bea56879 | 195 | #if wxUSE_LIBJPEG |
176fe5af | 196 | image.Destroy(); |
279ababf | 197 | |
176fe5af | 198 | if ( !image.LoadFile( dir + wxString("horse.jpg")) ) |
60a41aee RR |
199 | wxLogError("Can't load JPG image"); |
200 | else | |
9d8bdf2d | 201 | my_horse_jpeg = new wxBitmap( image ); |
bea56879 | 202 | #endif // wxUSE_LIBJPEG |
6e47faf1 JS |
203 | |
204 | #if wxUSE_GIF | |
176fe5af | 205 | image.Destroy(); |
279ababf | 206 | |
176fe5af | 207 | if ( !image.LoadFile( dir + wxString("horse.gif")) ) |
60a41aee RR |
208 | wxLogError("Can't load GIF image"); |
209 | else | |
9d8bdf2d | 210 | my_horse_gif = new wxBitmap( image ); |
6e47faf1 | 211 | #endif |
cbd4be25 | 212 | |
6e47faf1 | 213 | #if wxUSE_PCX |
176fe5af | 214 | image.Destroy(); |
279ababf | 215 | |
60a41aee RR |
216 | if ( !image.LoadFile( dir + wxString("horse.pcx"), wxBITMAP_TYPE_PCX ) ) |
217 | wxLogError("Can't load PCX image"); | |
218 | else | |
9d8bdf2d | 219 | my_horse_pcx = new wxBitmap( image ); |
6e47faf1 | 220 | #endif |
cbd4be25 | 221 | |
176fe5af | 222 | image.Destroy(); |
279ababf | 223 | |
60a41aee RR |
224 | if ( !image.LoadFile( dir + wxString("horse.bmp"), wxBITMAP_TYPE_BMP ) ) |
225 | wxLogError("Can't load BMP image"); | |
226 | else | |
9d8bdf2d | 227 | my_horse_bmp = new wxBitmap( image ); |
6319afe3 | 228 | |
a8d4e3ac | 229 | #if wxUSE_XPM |
9d8bdf2d VS |
230 | image.Destroy(); |
231 | ||
232 | if ( !image.LoadFile( dir + wxString("horse.xpm"), wxBITMAP_TYPE_XPM ) ) | |
233 | wxLogError("Can't load XPM image"); | |
234 | else | |
235 | my_horse_xpm = new wxBitmap( image ); | |
236 | ||
a8d4e3ac VS |
237 | if ( !image.SaveFile( dir + wxString("test.xpm"), wxBITMAP_TYPE_XPM )) |
238 | wxLogError("Can't save file"); | |
239 | #endif | |
240 | ||
6e47faf1 | 241 | #if wxUSE_PNM |
176fe5af | 242 | image.Destroy(); |
279ababf | 243 | |
60a41aee RR |
244 | if ( !image.LoadFile( dir + wxString("horse.pnm"), wxBITMAP_TYPE_PNM ) ) |
245 | wxLogError("Can't load PNM image"); | |
246 | else | |
9d8bdf2d | 247 | my_horse_pnm = new wxBitmap( image ); |
6e47faf1 | 248 | #endif |
f048e32f | 249 | |
60a41aee | 250 | #if wxUSE_LIBTIFF |
176fe5af | 251 | image.Destroy(); |
279ababf | 252 | |
60a41aee RR |
253 | if ( !image.LoadFile( dir + wxString("horse.tif"), wxBITMAP_TYPE_TIF ) ) |
254 | wxLogError("Can't load TIFF image"); | |
255 | else | |
9d8bdf2d | 256 | my_horse_tiff = new wxBitmap( image ); |
60a41aee RR |
257 | #endif |
258 | ||
60a41aee | 259 | CreateAntiAliasedBitmap(); |
dc1dbfc6 RL |
260 | |
261 | my_smile_xbm = new wxBitmap( (const char*)smile_bits, smile_width, | |
262 | smile_height, 1 ); | |
bfef20bf | 263 | |
81278df2 | 264 | #if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW |
bfef20bf GRG |
265 | // demonstrates XPM automatically using the mask when saving |
266 | if ( m_bmpSmileXpm.Ok() ) | |
267 | m_bmpSmileXpm.SaveFile("saved.xpm", wxBITMAP_TYPE_XPM); | |
81278df2 | 268 | #endif |
01111366 RR |
269 | } |
270 | ||
1d5b7a0b | 271 | MyCanvas::~MyCanvas() |
01111366 | 272 | { |
60a41aee RR |
273 | delete my_horse_pnm; |
274 | delete my_horse_png; | |
275 | delete my_horse_jpeg; | |
276 | delete my_horse_gif; | |
277 | delete my_horse_bmp; | |
278 | delete my_horse_pcx; | |
279 | delete my_horse_tiff; | |
9d8bdf2d | 280 | delete my_horse_xpm; |
dc1dbfc6 | 281 | delete my_smile_xbm; |
60a41aee RR |
282 | delete my_square; |
283 | delete my_anti; | |
01111366 RR |
284 | } |
285 | ||
286 | void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
287 | { | |
be25e480 RR |
288 | wxPaintDC dc( this ); |
289 | PrepareDC( dc ); | |
a91b47e8 | 290 | |
be25e480 RR |
291 | dc.DrawText( "Loaded image", 30, 10 ); |
292 | if (my_square && my_square->Ok()) dc.DrawBitmap( *my_square, 30, 30 ); | |
f048e32f | 293 | |
be25e480 RR |
294 | dc.DrawText( "Drawn directly", 150, 10 ); |
295 | dc.SetBrush( wxBrush( "orange", wxSOLID ) ); | |
cf3da716 | 296 | dc.SetPen( *wxBLACK_PEN ); |
be25e480 | 297 | dc.DrawRectangle( 150, 30, 100, 100 ); |
cf3da716 RR |
298 | dc.SetBrush( *wxWHITE_BRUSH ); |
299 | dc.DrawRectangle( 170, 50, 60, 60 ); | |
be25e480 | 300 | |
408b4168 | 301 | if (my_anti && my_anti->Ok()) |
be25e480 RR |
302 | dc.DrawBitmap( *my_anti, 280, 30 ); |
303 | ||
304 | dc.DrawText( "PNG handler", 30, 135 ); | |
305 | if (my_horse_png && my_horse_png->Ok()) | |
408b4168 | 306 | { |
be25e480 RR |
307 | dc.DrawBitmap( *my_horse_png, 30, 150 ); |
308 | wxRect rect(0,0,100,100); | |
309 | wxBitmap sub( my_horse_png->GetSubBitmap(rect) ); | |
310 | dc.DrawText( "GetSubBitmap()", 280, 190 ); | |
311 | dc.DrawBitmap( sub, 280, 210 ); | |
312 | } | |
313 | ||
314 | dc.DrawText( "JPEG handler", 30, 365 ); | |
408b4168 | 315 | if (my_horse_jpeg && my_horse_jpeg->Ok()) |
be25e480 RR |
316 | dc.DrawBitmap( *my_horse_jpeg, 30, 380 ); |
317 | ||
318 | dc.DrawText( "GIF handler", 30, 595 ); | |
408b4168 | 319 | if (my_horse_gif && my_horse_gif->Ok()) |
be25e480 RR |
320 | dc.DrawBitmap( *my_horse_gif, 30, 610 ); |
321 | ||
322 | dc.DrawText( "PCX handler", 30, 825 ); | |
408b4168 | 323 | if (my_horse_pcx && my_horse_pcx->Ok()) |
be25e480 RR |
324 | dc.DrawBitmap( *my_horse_pcx, 30, 840 ); |
325 | ||
326 | dc.DrawText( "BMP handler", 30, 1055 ); | |
408b4168 | 327 | if (my_horse_bmp && my_horse_bmp->Ok()) |
be25e480 RR |
328 | dc.DrawBitmap( *my_horse_bmp, 30, 1070 ); |
329 | ||
330 | dc.DrawText( "PNM handler", 30, 1285 ); | |
408b4168 | 331 | if (my_horse_pnm && my_horse_pnm->Ok()) |
be25e480 | 332 | dc.DrawBitmap( *my_horse_pnm, 30, 1300 ); |
408b4168 | 333 | |
be25e480 | 334 | dc.DrawText( "TIFF handler", 30, 1515 ); |
408b4168 | 335 | if (my_horse_tiff && my_horse_tiff->Ok()) |
4b05d973 | 336 | dc.DrawBitmap( *my_horse_tiff, 30, 1530 ); |
be25e480 | 337 | |
9d8bdf2d VS |
338 | dc.DrawText( "XPM handler", 30, 1745 ); |
339 | if (my_horse_xpm && my_horse_xpm->Ok()) | |
340 | dc.DrawBitmap( *my_horse_xpm, 30, 1760 ); | |
341 | ||
408b4168 | 342 | if (my_smile_xbm && my_smile_xbm->Ok()) |
be25e480 | 343 | { |
9d8bdf2d VS |
344 | dc.DrawText( "XBM bitmap", 30, 1975 ); |
345 | dc.DrawText( "(green on red)", 30, 1990 ); | |
176fe5af GRG |
346 | dc.SetTextForeground( "GREEN" ); |
347 | dc.SetTextBackground( "RED" ); | |
9d8bdf2d | 348 | dc.DrawBitmap( *my_smile_xbm, 30, 2010 ); |
408b4168 | 349 | |
176fe5af | 350 | dc.SetTextForeground( "BLACK" ); |
9d8bdf2d VS |
351 | dc.DrawText( "After wxImage conversion", 150, 1975 ); |
352 | dc.DrawText( "(red on white)", 150, 1990 ); | |
176fe5af | 353 | dc.SetTextForeground( "RED" ); |
a8d4e3ac | 354 | wxImage i = my_smile_xbm->ConvertToImage(); |
176fe5af GRG |
355 | i.SetMaskColour( 255, 255, 255 ); |
356 | i.Replace( 0, 0, 0, | |
be25e480 RR |
357 | wxRED_PEN->GetColour().Red(), |
358 | wxRED_PEN->GetColour().Green(), | |
359 | wxRED_PEN->GetColour().Blue() ); | |
9d8bdf2d | 360 | dc.DrawBitmap( i.ConvertToBitmap(), 150, 2010, TRUE ); |
176fe5af | 361 | dc.SetTextForeground( "BLACK" ); |
be25e480 | 362 | } |
176fe5af | 363 | |
408b4168 | 364 | |
41fbc841 | 365 | wxBitmap mono( 60,50,1 ); |
82ea63e6 RR |
366 | wxMemoryDC memdc; |
367 | memdc.SelectObject( mono ); | |
bfef20bf | 368 | memdc.SetPen( *wxBLACK_PEN ); |
82ea63e6 | 369 | memdc.SetBrush( *wxWHITE_BRUSH ); |
41fbc841 RR |
370 | memdc.DrawRectangle( 0,0,60,50 ); |
371 | memdc.SetTextForeground( *wxBLACK ); | |
372 | memdc.DrawText( "Hi!", 5, 5 ); | |
373 | memdc.SetBrush( *wxBLACK_BRUSH ); | |
374 | memdc.DrawRectangle( 33,5,20,20 ); | |
375 | memdc.SetPen( *wxRED_PEN ); | |
376 | memdc.DrawLine( 5, 42, 50, 42 ); | |
82ea63e6 | 377 | memdc.SelectObject( wxNullBitmap ); |
176fe5af | 378 | |
408b4168 | 379 | if (mono.Ok()) |
82ea63e6 | 380 | { |
9d8bdf2d VS |
381 | dc.DrawText( "Mono bitmap", 30, 2095 ); |
382 | dc.DrawText( "(red on green)", 30, 2110 ); | |
82ea63e6 RR |
383 | dc.SetTextForeground( "RED" ); |
384 | dc.SetTextBackground( "GREEN" ); | |
9d8bdf2d | 385 | dc.DrawBitmap( mono, 30, 2130 ); |
408b4168 | 386 | |
bea56879 | 387 | dc.SetTextForeground( "BLACK" ); |
9d8bdf2d VS |
388 | dc.DrawText( "After wxImage conversion", 150, 2095 ); |
389 | dc.DrawText( "(red on white)", 150, 2110 ); | |
bea56879 | 390 | dc.SetTextForeground( "RED" ); |
a8d4e3ac | 391 | wxImage i = mono.ConvertToImage(); |
408b4168 VZ |
392 | i.SetMaskColour( 255,255,255 ); |
393 | i.Replace( 0,0,0, | |
82ea63e6 RR |
394 | wxRED_PEN->GetColour().Red(), |
395 | wxRED_PEN->GetColour().Green(), | |
396 | wxRED_PEN->GetColour().Blue() ); | |
9d8bdf2d | 397 | dc.DrawBitmap( i.ConvertToBitmap(), 150, 2130, TRUE ); |
bea56879 VZ |
398 | dc.SetTextForeground( "BLACK" ); |
399 | } | |
400 | ||
9d8bdf2d | 401 | dc.DrawText("XPM bitmap", 30, 2230); |
bea56879 VZ |
402 | if ( m_bmpSmileXpm.Ok() ) |
403 | { | |
9d8bdf2d | 404 | dc.DrawBitmap(m_bmpSmileXpm, 30, 2250, TRUE); |
bea56879 VZ |
405 | } |
406 | ||
9d8bdf2d | 407 | dc.DrawText("XPM icon", 150, 2230); |
bea56879 VZ |
408 | if ( m_iconSmileXpm.Ok() ) |
409 | { | |
9d8bdf2d | 410 | dc.DrawIcon(m_iconSmileXpm, 150, 2250); |
82ea63e6 | 411 | } |
9390a202 | 412 | } |
1d5b7a0b | 413 | |
9390a202 RR |
414 | void MyCanvas::CreateAntiAliasedBitmap() |
415 | { | |
416 | wxBitmap bitmap( 300, 300 ); | |
a91b47e8 | 417 | |
9390a202 | 418 | wxMemoryDC dc; |
a91b47e8 | 419 | |
9390a202 | 420 | dc.SelectObject( bitmap ); |
a91b47e8 | 421 | |
9390a202 | 422 | dc.Clear(); |
f048e32f | 423 | |
6e47faf1 | 424 | dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL) ); |
9390a202 RR |
425 | dc.SetTextForeground( "RED" ); |
426 | dc.DrawText( "This is anti-aliased Text.", 20, 20 ); | |
427 | dc.DrawText( "And a Rectangle.", 20, 60 ); | |
f048e32f | 428 | |
9390a202 | 429 | dc.SetBrush( *wxRED_BRUSH ); |
91b8de8d | 430 | dc.SetPen( *wxTRANSPARENT_PEN ); |
9390a202 | 431 | dc.DrawRoundedRectangle( 20, 100, 200, 180, 20 ); |
f048e32f | 432 | |
a8d4e3ac | 433 | wxImage original= bitmap.ConvertToImage(); |
9390a202 | 434 | wxImage anti( 150, 150 ); |
a91b47e8 | 435 | |
9390a202 | 436 | /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */ |
f048e32f | 437 | |
9390a202 RR |
438 | for (int y = 1; y < 149; y++) |
439 | for (int x = 1; x < 149; x++) | |
440 | { | |
441 | int red = original.GetRed( x*2, y*2 ) + | |
f048e32f VZ |
442 | original.GetRed( x*2-1, y*2 ) + |
443 | original.GetRed( x*2, y*2+1 ) + | |
9390a202 | 444 | original.GetRed( x*2+1, y*2+1 ); |
f048e32f VZ |
445 | red = red/4; |
446 | ||
9390a202 | 447 | int green = original.GetGreen( x*2, y*2 ) + |
f048e32f VZ |
448 | original.GetGreen( x*2-1, y*2 ) + |
449 | original.GetGreen( x*2, y*2+1 ) + | |
9390a202 | 450 | original.GetGreen( x*2+1, y*2+1 ); |
f048e32f VZ |
451 | green = green/4; |
452 | ||
9390a202 | 453 | int blue = original.GetBlue( x*2, y*2 ) + |
f048e32f VZ |
454 | original.GetBlue( x*2-1, y*2 ) + |
455 | original.GetBlue( x*2, y*2+1 ) + | |
9390a202 | 456 | original.GetBlue( x*2+1, y*2+1 ); |
f048e32f | 457 | blue = blue/4; |
9390a202 RR |
458 | anti.SetRGB( x, y, red, green, blue ); |
459 | } | |
460 | my_anti = new wxBitmap( anti.ConvertToBitmap() ); | |
01111366 RR |
461 | } |
462 | ||
463 | // MyFrame | |
464 | ||
79490c3d VZ |
465 | const int ID_QUIT = 108; |
466 | const int ID_ABOUT = 109; | |
ab0f0386 | 467 | const int ID_NEW = 110; |
01111366 RR |
468 | |
469 | IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) | |
470 | ||
471 | BEGIN_EVENT_TABLE(MyFrame,wxFrame) | |
472 | EVT_MENU (ID_ABOUT, MyFrame::OnAbout) | |
473 | EVT_MENU (ID_QUIT, MyFrame::OnQuit) | |
ab0f0386 | 474 | EVT_MENU (ID_NEW, MyFrame::OnNewFrame) |
01111366 RR |
475 | END_EVENT_TABLE() |
476 | ||
1d5b7a0b VZ |
477 | MyFrame::MyFrame() |
478 | : wxFrame( (wxFrame *)NULL, -1, "wxImage sample", | |
479 | wxPoint(20,20), wxSize(470,360) ) | |
01111366 RR |
480 | { |
481 | wxMenu *file_menu = new wxMenu(); | |
f6bcfd97 | 482 | file_menu->Append( ID_NEW, "&Show image..."); |
ab0f0386 | 483 | file_menu->AppendSeparator(); |
81278df2 | 484 | file_menu->Append( ID_ABOUT, "&About..."); |
ab0f0386 | 485 | file_menu->AppendSeparator(); |
90e58684 | 486 | file_menu->Append( ID_QUIT, "E&xit"); |
1d5b7a0b | 487 | |
01111366 | 488 | wxMenuBar *menu_bar = new wxMenuBar(); |
90e58684 | 489 | menu_bar->Append(file_menu, "&File"); |
3d05544e | 490 | |
01111366 | 491 | SetMenuBar( menu_bar ); |
1d5b7a0b | 492 | |
917e533b RR |
493 | CreateStatusBar(2); |
494 | int widths[] = { -1, 100 }; | |
495 | SetStatusWidths( 2, widths ); | |
1d5b7a0b | 496 | |
fb1585ae | 497 | m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) ); |
cbd4be25 | 498 | |
bea56879 | 499 | // 500 width * 2100 height |
176fe5af | 500 | m_canvas->SetScrollbars( 10, 10, 50, 220 ); |
01111366 RR |
501 | } |
502 | ||
503 | void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) | |
504 | { | |
505 | Close( TRUE ); | |
506 | } | |
507 | ||
508 | void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) | |
509 | { | |
1d5b7a0b | 510 | (void)wxMessageBox( "wxImage demo\n" |
41fbc841 | 511 | "Robert Roebling (c) 1998,2000", |
1d5b7a0b | 512 | "About wxImage Demo", wxICON_INFORMATION | wxOK ); |
fb1585ae RR |
513 | } |
514 | ||
ab0f0386 VZ |
515 | void MyFrame::OnNewFrame( wxCommandEvent &WXUNUSED(event) ) |
516 | { | |
f6bcfd97 BP |
517 | wxString filename = wxFileSelector(_T("Select image file")); |
518 | if ( !filename ) | |
519 | return; | |
520 | ||
521 | wxImage image; | |
522 | if ( !image.LoadFile(filename) ) | |
523 | { | |
524 | wxLogError(_T("Couldn't load image from '%s'."), filename.c_str()); | |
525 | ||
526 | return; | |
527 | } | |
528 | ||
529 | (new MyImageFrame(this, image.ConvertToBitmap()))->Show(); | |
ab0f0386 VZ |
530 | } |
531 | ||
01111366 RR |
532 | //----------------------------------------------------------------------------- |
533 | // MyApp | |
534 | //----------------------------------------------------------------------------- | |
535 | ||
1d5b7a0b | 536 | bool MyApp::OnInit() |
01111366 | 537 | { |
e9c4b1a2 JS |
538 | #if wxUSE_LIBPNG |
539 | wxImage::AddHandler( new wxPNGHandler ); | |
540 | #endif | |
541 | ||
542 | #if wxUSE_LIBJPEG | |
543 | wxImage::AddHandler( new wxJPEGHandler ); | |
544 | #endif | |
545 | ||
60a41aee RR |
546 | #if wxUSE_LIBTIFF |
547 | wxImage::AddHandler( new wxTIFFHandler ); | |
548 | #endif | |
549 | ||
6e47faf1 | 550 | #if wxUSE_GIF |
e1929140 | 551 | wxImage::AddHandler( new wxGIFHandler ); |
6e47faf1 JS |
552 | #endif |
553 | ||
554 | #if wxUSE_PCX | |
cbd4be25 | 555 | wxImage::AddHandler( new wxPCXHandler ); |
6e47faf1 JS |
556 | #endif |
557 | ||
558 | #if wxUSE_PNM | |
6319afe3 | 559 | wxImage::AddHandler( new wxPNMHandler ); |
6e47faf1 | 560 | #endif |
e1929140 | 561 | |
a8d4e3ac VS |
562 | #if wxUSE_XPM |
563 | wxImage::AddHandler( new wxXPMHandler ); | |
564 | #endif | |
565 | ||
01111366 RR |
566 | wxFrame *frame = new MyFrame(); |
567 | frame->Show( TRUE ); | |
1d5b7a0b | 568 | |
01111366 RR |
569 | return TRUE; |
570 | } | |
571 |