no real change; just reorganize the sample splitting it in two source files
[wxWidgets.git] / samples / image / canvas.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: samples/image/canvas.cpp
3 // Purpose: sample showing operations with wxImage
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi
6 // Created: 1998
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998-2005 Robert Roebling
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22
23 #include "wx/image.h"
24 #include "wx/file.h"
25 #include "wx/filename.h"
26 #include "wx/mstream.h"
27 #include "wx/wfstream.h"
28 #include "wx/quantize.h"
29 #include "wx/stopwatch.h"
30
31 #if wxUSE_CLIPBOARD
32 #include "wx/dataobj.h"
33 #include "wx/clipbrd.h"
34 #endif // wxUSE_CLIPBOARD
35
36 #include "smile.xbm"
37 #include "smile.xpm"
38
39 #include "canvas.h"
40
41
42 //-----------------------------------------------------------------------------
43 // MyCanvas
44 //-----------------------------------------------------------------------------
45
46 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
47 EVT_PAINT(MyCanvas::OnPaint)
48 END_EVENT_TABLE()
49
50 MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
51 const wxPoint &pos, const wxSize &size )
52 : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER )
53 , m_bmpSmileXpm(smile_xpm)
54 , m_iconSmileXpm(smile_xpm)
55 {
56 my_horse_ani = NULL;
57 m_ani_images = 0 ;
58
59 SetBackgroundColour(* wxWHITE);
60
61 wxBitmap bitmap( 100, 100 );
62
63 wxMemoryDC dc;
64 dc.SelectObject( bitmap );
65 dc.SetBrush( wxBrush( wxT("orange"), wxSOLID ) );
66 dc.SetPen( *wxBLACK_PEN );
67 dc.DrawRectangle( 0, 0, 100, 100 );
68 dc.SetBrush( *wxWHITE_BRUSH );
69 dc.DrawRectangle( 20, 20, 60, 60 );
70 dc.SelectObject( wxNullBitmap );
71
72 // try to find the directory with our images
73 wxString dir;
74 if ( wxFile::Exists(wxT("./horse.png")) )
75 dir = wxT("./");
76 else if ( wxFile::Exists(wxT("../horse.png")) )
77 dir = wxT("../");
78 else
79 wxLogWarning(wxT("Can't find image files in either '.' or '..'!"));
80
81 wxImage image = bitmap.ConvertToImage();
82
83 #if wxUSE_LIBPNG
84 if ( !image.SaveFile( dir + _T("test.png"), wxBITMAP_TYPE_PNG ))
85 wxLogError(wxT("Can't save file"));
86
87 image.Destroy();
88
89 if ( image.LoadFile( dir + _T("test.png") ) )
90 my_square = wxBitmap( image );
91
92 image.Destroy();
93
94 if ( !image.LoadFile( dir + _T("horse.png")) )
95 wxLogError(wxT("Can't load PNG image"));
96 else
97 my_horse_png = wxBitmap( image );
98
99 if ( !image.LoadFile( dir + _T("toucan.png")) )
100 wxLogError(wxT("Can't load PNG image"));
101 else
102 my_toucan = wxBitmap(image);
103
104 my_toucan_flipped_horiz = wxBitmap(image.Mirror(true));
105 my_toucan_flipped_vert = wxBitmap(image.Mirror(false));
106 my_toucan_flipped_both = wxBitmap(image.Mirror(true).Mirror(false));
107 my_toucan_grey = wxBitmap(image.ConvertToGreyscale());
108 my_toucan_head = wxBitmap(image.GetSubImage(wxRect(40, 7, 80, 60)));
109 my_toucan_scaled_normal = wxBitmap(image.Scale(110,90,wxIMAGE_QUALITY_NORMAL));
110 my_toucan_scaled_high = wxBitmap(image.Scale(110,90,wxIMAGE_QUALITY_HIGH));
111 my_toucan_blur = wxBitmap(image.Blur(10));
112
113 #endif // wxUSE_LIBPNG
114
115 #if wxUSE_LIBJPEG
116 image.Destroy();
117
118 if ( !image.LoadFile( dir + _T("horse.jpg")) )
119 wxLogError(wxT("Can't load JPG image"));
120 else
121 {
122 my_horse_jpeg = wxBitmap( image );
123
124 // Colorize by rotating green hue to red
125 wxImage::HSVValue greenHSV = wxImage::RGBtoHSV(wxImage::RGBValue(0, 255, 0));
126 wxImage::HSVValue redHSV = wxImage::RGBtoHSV(wxImage::RGBValue(255, 0, 0));
127 image.RotateHue(redHSV.hue - greenHSV.hue);
128 colorized_horse_jpeg = wxBitmap( image );
129 }
130
131 if ( !image.LoadFile( dir + _T("cmyk.jpg")) )
132 wxLogError(_T("Can't load CMYK JPG image"));
133 else
134 my_cmyk_jpeg = wxBitmap(image);
135 #endif // wxUSE_LIBJPEG
136
137 #if wxUSE_GIF
138 image.Destroy();
139
140 if ( !image.LoadFile( dir + _T("horse.gif" )) )
141 wxLogError(wxT("Can't load GIF image"));
142 else
143 my_horse_gif = wxBitmap( image );
144 #endif
145
146 #if wxUSE_PCX
147 image.Destroy();
148
149 if ( !image.LoadFile( dir + _T("horse.pcx"), wxBITMAP_TYPE_PCX ) )
150 wxLogError(wxT("Can't load PCX image"));
151 else
152 my_horse_pcx = wxBitmap( image );
153 #endif
154
155 image.Destroy();
156
157 if ( !image.LoadFile( dir + _T("horse.bmp"), wxBITMAP_TYPE_BMP ) )
158 wxLogError(wxT("Can't load BMP image"));
159 else
160 my_horse_bmp = wxBitmap( image );
161
162 #if wxUSE_XPM
163 image.Destroy();
164
165 if ( !image.LoadFile( dir + _T("horse.xpm"), wxBITMAP_TYPE_XPM ) )
166 wxLogError(wxT("Can't load XPM image"));
167 else
168 my_horse_xpm = wxBitmap( image );
169
170 if ( !image.SaveFile( dir + _T("test.xpm"), wxBITMAP_TYPE_XPM ))
171 wxLogError(wxT("Can't save file"));
172 #endif
173
174 #if wxUSE_PNM
175 image.Destroy();
176
177 if ( !image.LoadFile( dir + _T("horse.pnm"), wxBITMAP_TYPE_PNM ) )
178 wxLogError(wxT("Can't load PNM image"));
179 else
180 my_horse_pnm = wxBitmap( image );
181
182 image.Destroy();
183
184 if ( !image.LoadFile( dir + _T("horse_ag.pnm"), wxBITMAP_TYPE_PNM ) )
185 wxLogError(wxT("Can't load PNM image"));
186 else
187 my_horse_asciigrey_pnm = wxBitmap( image );
188
189 image.Destroy();
190
191 if ( !image.LoadFile( dir + _T("horse_rg.pnm"), wxBITMAP_TYPE_PNM ) )
192 wxLogError(wxT("Can't load PNM image"));
193 else
194 my_horse_rawgrey_pnm = wxBitmap( image );
195 #endif
196
197 #if wxUSE_LIBTIFF
198 image.Destroy();
199
200 if ( !image.LoadFile( dir + _T("horse.tif"), wxBITMAP_TYPE_TIF ) )
201 wxLogError(wxT("Can't load TIFF image"));
202 else
203 my_horse_tiff = wxBitmap( image );
204 #endif
205
206 #if wxUSE_LIBTIFF
207 image.Destroy();
208
209 if ( !image.LoadFile( dir + _T("horse.tga"), wxBITMAP_TYPE_TGA ) )
210 wxLogError(wxT("Can't load TGA image"));
211 else
212 my_horse_tga = wxBitmap( image );
213 #endif
214
215 CreateAntiAliasedBitmap();
216
217 my_smile_xbm = wxBitmap( (const char*)smile_bits, smile_width,
218 smile_height, 1 );
219
220 // demonstrates XPM automatically using the mask when saving
221 if ( m_bmpSmileXpm.Ok() )
222 m_bmpSmileXpm.SaveFile(_T("saved.xpm"), wxBITMAP_TYPE_XPM);
223
224 #if wxUSE_ICO_CUR
225 image.Destroy();
226
227 if ( !image.LoadFile( dir + _T("horse.ico"), wxBITMAP_TYPE_ICO, 0 ) )
228 wxLogError(wxT("Can't load first ICO image"));
229 else
230 my_horse_ico32 = wxBitmap( image );
231
232 image.Destroy();
233
234 if ( !image.LoadFile( dir + _T("horse.ico"), wxBITMAP_TYPE_ICO, 1 ) )
235 wxLogError(wxT("Can't load second ICO image"));
236 else
237 my_horse_ico16 = wxBitmap( image );
238
239 image.Destroy();
240
241 if ( !image.LoadFile( dir + _T("horse.ico") ) )
242 wxLogError(wxT("Can't load best ICO image"));
243 else
244 my_horse_ico = wxBitmap( image );
245
246 image.Destroy();
247
248 if ( !image.LoadFile( dir + _T("horse.cur"), wxBITMAP_TYPE_CUR ) )
249 wxLogError(wxT("Can't load best ICO image"));
250 else
251 {
252 my_horse_cur = wxBitmap( image );
253 xH = 30 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X) ;
254 yH = 2420 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ;
255 }
256
257 m_ani_images = wxImage::GetImageCount ( dir + _T("horse3.ani"), wxBITMAP_TYPE_ANI );
258 if (m_ani_images==0)
259 wxLogError(wxT("No ANI-format images found"));
260 else
261 my_horse_ani = new wxBitmap [m_ani_images];
262
263 int i;
264 for (i=0; i < m_ani_images; i++)
265 {
266 image.Destroy();
267 if (!image.LoadFile( dir + _T("horse3.ani"), wxBITMAP_TYPE_ANI, i ))
268 {
269 wxString tmp = wxT("Can't load image number ");
270 tmp << i ;
271 wxLogError(tmp);
272 }
273 else
274 my_horse_ani [i] = wxBitmap( image );
275 }
276 #endif // wxUSE_ICO_CUR
277
278
279 image.Destroy();
280
281 // test image loading from stream
282 wxFile file(dir + _T("horse.bmp"));
283 if ( file.IsOpened() )
284 {
285 wxFileOffset len = file.Length();
286 size_t dataSize = (size_t)len;
287 void *data = malloc(dataSize);
288 if ( file.Read(data, dataSize) != len )
289 wxLogError(_T("Reading bitmap file failed"));
290 else
291 {
292 wxMemoryInputStream mis(data, dataSize);
293 if ( !image.LoadFile(mis) )
294 wxLogError(wxT("Can't load BMP image from stream"));
295 else
296 my_horse_bmp2 = wxBitmap( image );
297 }
298
299 free(data);
300 }
301 }
302
303 MyCanvas::~MyCanvas()
304 {
305 delete [] my_horse_ani;
306 }
307
308 void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
309 {
310 wxPaintDC dc( this );
311 PrepareDC( dc );
312
313 dc.DrawText( _T("Loaded image"), 30, 10 );
314 if (my_square.Ok())
315 dc.DrawBitmap( my_square, 30, 30 );
316
317 dc.DrawText( _T("Drawn directly"), 150, 10 );
318 dc.SetBrush( wxBrush( wxT("orange"), wxSOLID ) );
319 dc.SetPen( *wxBLACK_PEN );
320 dc.DrawRectangle( 150, 30, 100, 100 );
321 dc.SetBrush( *wxWHITE_BRUSH );
322 dc.DrawRectangle( 170, 50, 60, 60 );
323
324 if (my_anti.Ok())
325 dc.DrawBitmap( my_anti, 280, 30 );
326
327 dc.DrawText( _T("PNG handler"), 30, 135 );
328 if (my_horse_png.Ok())
329 {
330 dc.DrawBitmap( my_horse_png, 30, 150 );
331 wxRect rect(0,0,100,100);
332 wxBitmap sub( my_horse_png.GetSubBitmap(rect) );
333 dc.DrawText( _T("GetSubBitmap()"), 280, 175 );
334 dc.DrawBitmap( sub, 280, 195 );
335 }
336
337 dc.DrawText( _T("JPEG handler"), 30, 365 );
338 if (my_horse_jpeg.Ok())
339 dc.DrawBitmap( my_horse_jpeg, 30, 380 );
340
341 dc.DrawText( _T("Green rotated to red"), 280, 365 );
342 if (colorized_horse_jpeg.Ok())
343 dc.DrawBitmap( colorized_horse_jpeg, 280, 380 );
344
345 dc.DrawText( _T("CMYK JPEG image"), 530, 365 );
346 if (my_cmyk_jpeg.Ok())
347 dc.DrawBitmap( my_cmyk_jpeg, 530, 380 );
348
349 dc.DrawText( _T("GIF handler"), 30, 595 );
350 if (my_horse_gif.Ok())
351 dc.DrawBitmap( my_horse_gif, 30, 610 );
352
353 dc.DrawText( _T("PCX handler"), 30, 825 );
354 if (my_horse_pcx.Ok())
355 dc.DrawBitmap( my_horse_pcx, 30, 840 );
356
357 dc.DrawText( _T("BMP handler"), 30, 1055 );
358 if (my_horse_bmp.Ok())
359 dc.DrawBitmap( my_horse_bmp, 30, 1070 );
360
361 dc.DrawText( _T("BMP read from memory"), 280, 1055 );
362 if (my_horse_bmp2.Ok())
363 dc.DrawBitmap( my_horse_bmp2, 280, 1070 );
364
365 dc.DrawText( _T("PNM handler"), 30, 1285 );
366 if (my_horse_pnm.Ok())
367 dc.DrawBitmap( my_horse_pnm, 30, 1300 );
368
369 dc.DrawText( _T("PNM handler (ascii grey)"), 280, 1285 );
370 if (my_horse_asciigrey_pnm.Ok())
371 dc.DrawBitmap( my_horse_asciigrey_pnm, 280, 1300 );
372
373 dc.DrawText( _T("PNM handler (raw grey)"), 530, 1285 );
374 if (my_horse_rawgrey_pnm.Ok())
375 dc.DrawBitmap( my_horse_rawgrey_pnm, 530, 1300 );
376
377 dc.DrawText( _T("TIFF handler"), 30, 1515 );
378 if (my_horse_tiff.Ok())
379 dc.DrawBitmap( my_horse_tiff, 30, 1530 );
380
381 dc.DrawText( _T("TGA handler"), 30, 1745 );
382 if (my_horse_tga.Ok())
383 dc.DrawBitmap( my_horse_tga, 30, 1760 );
384
385 dc.DrawText( _T("XPM handler"), 30, 1975 );
386 if (my_horse_xpm.Ok())
387 dc.DrawBitmap( my_horse_xpm, 30, 2000 );
388
389 // toucans
390 {
391 int x = 750, y = 10, yy = 170;
392
393 dc.DrawText(wxT("Original toucan"), x+50, y);
394 dc.DrawBitmap(my_toucan, x, y+15, true);
395 y += yy;
396 dc.DrawText(wxT("Flipped horizontally"), x+50, y);
397 dc.DrawBitmap(my_toucan_flipped_horiz, x, y+15, true);
398 y += yy;
399 dc.DrawText(wxT("Flipped vertically"), x+50, y);
400 dc.DrawBitmap(my_toucan_flipped_vert, x, y+15, true);
401 y += yy;
402 dc.DrawText(wxT("Flipped both h&v"), x+50, y);
403 dc.DrawBitmap(my_toucan_flipped_both, x, y+15, true);
404
405 y += yy;
406 dc.DrawText(wxT("In greyscale"), x+50, y);
407 dc.DrawBitmap(my_toucan_grey, x, y+15, true);
408
409 y += yy;
410 dc.DrawText(wxT("Toucan's head"), x+50, y);
411 dc.DrawBitmap(my_toucan_head, x, y+15, true);
412
413 y += yy;
414 dc.DrawText(wxT("Scaled with normal quality"), x+50, y);
415 dc.DrawBitmap(my_toucan_scaled_normal, x, y+15, true);
416
417 y += yy;
418 dc.DrawText(wxT("Scaled with high quality"), x+50, y);
419 dc.DrawBitmap(my_toucan_scaled_high, x, y+15, true);
420
421 y += yy;
422 dc.DrawText(wxT("Blured"), x+50, y);
423 dc.DrawBitmap(my_toucan_blur, x, y+15, true);
424 }
425
426 if (my_smile_xbm.Ok())
427 {
428 int x = 300, y = 1800;
429
430 dc.DrawText( _T("XBM bitmap"), x, y );
431 dc.DrawText( _T("(green on red)"), x, y + 15 );
432 dc.SetTextForeground( _T("GREEN") );
433 dc.SetTextBackground( _T("RED") );
434 dc.DrawBitmap( my_smile_xbm, x, y + 30 );
435
436 dc.SetTextForeground( *wxBLACK );
437 dc.DrawText( _T("After wxImage conversion"), x + 120, y );
438 dc.DrawText( _T("(red on white)"), x + 120, y + 15 );
439 dc.SetTextForeground( wxT("RED") );
440 wxImage i = my_smile_xbm.ConvertToImage();
441 i.SetMaskColour( 255, 255, 255 );
442 i.Replace( 0, 0, 0,
443 wxRED_PEN->GetColour().Red(),
444 wxRED_PEN->GetColour().Green(),
445 wxRED_PEN->GetColour().Blue() );
446 dc.DrawBitmap( wxBitmap(i), x + 120, y + 30, true );
447 dc.SetTextForeground( *wxBLACK );
448 }
449
450
451 wxBitmap mono( 60,50,1 );
452 wxMemoryDC memdc;
453 memdc.SelectObject( mono );
454 memdc.SetPen( *wxBLACK_PEN );
455 memdc.SetBrush( *wxWHITE_BRUSH );
456 memdc.DrawRectangle( 0,0,60,50 );
457 memdc.SetTextForeground( *wxBLACK );
458 #ifndef __WXGTK20__
459 // I cannot convince GTK2 to draw into mono bitmaps
460 memdc.DrawText( _T("Hi!"), 5, 5 );
461 #endif
462 memdc.SetBrush( *wxBLACK_BRUSH );
463 memdc.DrawRectangle( 33,5,20,20 );
464 memdc.SetPen( *wxRED_PEN );
465 memdc.DrawLine( 5, 42, 50, 42 );
466 memdc.SelectObject( wxNullBitmap );
467
468 if (mono.Ok())
469 {
470 int x = 300, y = 1900;
471
472 dc.DrawText( _T("Mono bitmap"), x, y );
473 dc.DrawText( _T("(red on green)"), x, y + 15 );
474 dc.SetTextForeground( wxT("RED") );
475 dc.SetTextBackground( wxT("GREEN") );
476 dc.DrawBitmap( mono, x, y + 30 );
477
478 dc.SetTextForeground( *wxBLACK );
479 dc.DrawText( _T("After wxImage conversion"), x + 120, y );
480 dc.DrawText( _T("(red on white)"), x + 120, y + 15 );
481 dc.SetTextForeground( wxT("RED") );
482 wxImage i = mono.ConvertToImage();
483 i.SetMaskColour( 255,255,255 );
484 i.Replace( 0,0,0,
485 wxRED_PEN->GetColour().Red(),
486 wxRED_PEN->GetColour().Green(),
487 wxRED_PEN->GetColour().Blue() );
488 dc.DrawBitmap( wxBitmap(i), x + 120, y + 30, true );
489 dc.SetTextForeground( *wxBLACK );
490 }
491
492 // For testing transparency
493 dc.SetBrush( *wxRED_BRUSH );
494 dc.DrawRectangle( 20, 2220, 560, 68 );
495
496 dc.DrawText(_T("XPM bitmap"), 30, 2230 );
497 if ( m_bmpSmileXpm.Ok() )
498 dc.DrawBitmap(m_bmpSmileXpm, 30, 2250, true);
499
500 dc.DrawText(_T("XPM icon"), 110, 2230 );
501 if ( m_iconSmileXpm.Ok() )
502 dc.DrawIcon(m_iconSmileXpm, 110, 2250);
503
504 // testing icon -> bitmap conversion
505 wxBitmap to_blit( m_iconSmileXpm );
506 if (to_blit.Ok())
507 {
508 dc.DrawText( _T("SubBitmap"), 170, 2230 );
509 wxBitmap sub = to_blit.GetSubBitmap( wxRect(0,0,15,15) );
510 if (sub.Ok())
511 dc.DrawBitmap( sub, 170, 2250, true );
512
513 dc.DrawText( _T("Enlarged"), 250, 2230 );
514 dc.SetUserScale( 1.5, 1.5 );
515 dc.DrawBitmap( to_blit, (int)(250/1.5), (int)(2250/1.5), true );
516 dc.SetUserScale( 2, 2 );
517 dc.DrawBitmap( to_blit, (int)(300/2), (int)(2250/2), true );
518 dc.SetUserScale( 1.0, 1.0 );
519
520 dc.DrawText( _T("Blit"), 400, 2230);
521 wxMemoryDC blit_dc;
522 blit_dc.SelectObject( to_blit );
523 dc.Blit( 400, 2250, to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
524 dc.SetUserScale( 1.5, 1.5 );
525 dc.Blit( (int)(450/1.5), (int)(2250/1.5), to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
526 dc.SetUserScale( 2, 2 );
527 dc.Blit( (int)(500/2), (int)(2250/2), to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
528 dc.SetUserScale( 1.0, 1.0 );
529 }
530
531 dc.DrawText( _T("ICO handler (1st image)"), 30, 2290 );
532 if (my_horse_ico32.Ok())
533 dc.DrawBitmap( my_horse_ico32, 30, 2330, true );
534
535 dc.DrawText( _T("ICO handler (2nd image)"), 230, 2290 );
536 if (my_horse_ico16.Ok())
537 dc.DrawBitmap( my_horse_ico16, 230, 2330, true );
538
539 dc.DrawText( _T("ICO handler (best image)"), 430, 2290 );
540 if (my_horse_ico.Ok())
541 dc.DrawBitmap( my_horse_ico, 430, 2330, true );
542
543 dc.DrawText( _T("CUR handler"), 30, 2390 );
544 if (my_horse_cur.Ok())
545 {
546 dc.DrawBitmap( my_horse_cur, 30, 2420, true );
547 dc.SetPen (*wxRED_PEN);
548 dc.DrawLine (xH-10,yH,xH+10,yH);
549 dc.DrawLine (xH,yH-10,xH,yH+10);
550 }
551
552 dc.DrawText( _T("ANI handler"), 230, 2390 );
553 for ( int i=0; i < m_ani_images; i++ )
554 {
555 if (my_horse_ani[i].Ok())
556 {
557 dc.DrawBitmap( my_horse_ani[i], 230 + i * 2 * my_horse_ani[i].GetWidth() , 2420, true );
558 }
559 }
560 }
561
562 void MyCanvas::CreateAntiAliasedBitmap()
563 {
564 wxBitmap bitmap( 300, 300 );
565
566 wxMemoryDC dc;
567
568 dc.SelectObject( bitmap );
569
570 dc.Clear();
571
572 dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL) );
573 dc.SetTextForeground( wxT("RED") );
574 dc.DrawText( _T("This is anti-aliased Text."), 20, 5 );
575 dc.DrawText( _T("And a Rectangle."), 20, 45 );
576
577 dc.SetBrush( *wxRED_BRUSH );
578 dc.SetPen( *wxTRANSPARENT_PEN );
579 dc.DrawRoundedRectangle( 20, 85, 200, 180, 20 );
580
581 wxImage original= bitmap.ConvertToImage();
582 wxImage anti( 150, 150 );
583
584 /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */
585
586 for (int y = 1; y < 149; y++)
587 for (int x = 1; x < 149; x++)
588 {
589 int red = original.GetRed( x*2, y*2 ) +
590 original.GetRed( x*2-1, y*2 ) +
591 original.GetRed( x*2, y*2+1 ) +
592 original.GetRed( x*2+1, y*2+1 );
593 red = red/4;
594
595 int green = original.GetGreen( x*2, y*2 ) +
596 original.GetGreen( x*2-1, y*2 ) +
597 original.GetGreen( x*2, y*2+1 ) +
598 original.GetGreen( x*2+1, y*2+1 );
599 green = green/4;
600
601 int blue = original.GetBlue( x*2, y*2 ) +
602 original.GetBlue( x*2-1, y*2 ) +
603 original.GetBlue( x*2, y*2+1 ) +
604 original.GetBlue( x*2+1, y*2+1 );
605 blue = blue/4;
606 anti.SetRGB( x, y, (unsigned char)red, (unsigned char)green, (unsigned char)blue );
607 }
608
609 my_anti = wxBitmap(anti);
610 }