]> git.saurik.com Git - wxWidgets.git/blame - samples/image/image.cpp
remove extraneous commas and semicolons (patch 1537792)
[wxWidgets.git] / samples / image / image.cpp
CommitLineData
5a566d89
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: samples/image/image.cpp
3// Purpose: sample showing operations with wxImage
4// Author: Robert Roebling
5// Modified by:
6// Created: 1998
7// RCS-ID: $Id$
8// Copyright: (c) 1998-2005 Robert Roebling
9// License: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
01111366 11
3d05544e
JS
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
9061c15c 20 #include "wx/wx.h"
3d05544e
JS
21#endif
22
01111366 23#include "wx/image.h"
a23fd0e1 24#include "wx/file.h"
5a566d89 25#include "wx/filename.h"
a8d4e3ac
VS
26#include "wx/mstream.h"
27#include "wx/wfstream.h"
1971d23c 28#include "wx/quantize.h"
a23fd0e1 29
da9df1f5
VZ
30#if wxUSE_CLIPBOARD
31 #include "wx/dataobj.h"
32 #include "wx/clipbrd.h"
33#endif // wxUSE_CLIPBOARD
34
dc1dbfc6 35#include "smile.xbm"
3ef37e7f 36#include "smile.xpm"
dc1dbfc6 37
284f2b59 38#if defined(__WXMSW__)
481721e8 39 #ifdef wxHAVE_RAW_BITMAP
9b24b388 40 #include "wx/rawbmp.h"
481721e8 41 #endif
c698eae5 42#endif
a8d4e3ac 43
284f2b59
RR
44#if defined(__WXMAC__) || defined(__WXGTK__)
45 #define wxHAVE_RAW_BITMAP
46 #include "wx/rawbmp.h"
47#endif
48
01111366
RR
49// derived classes
50
51class MyFrame;
52class MyApp;
53
54// MyCanvas
55
56class MyCanvas: public wxScrolledWindow
57{
1d5b7a0b 58public:
01111366 59 MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size );
1d5b7a0b 60 ~MyCanvas();
01111366 61 void OnPaint( wxPaintEvent &event );
9390a202 62 void CreateAntiAliasedBitmap();
1d5b7a0b 63
bd981f27
VZ
64 wxBitmap my_horse_png;
65 wxBitmap my_horse_jpeg;
66 wxBitmap my_horse_gif;
67 wxBitmap my_horse_bmp;
68 wxBitmap my_horse_bmp2;
69 wxBitmap my_horse_pcx;
70 wxBitmap my_horse_pnm;
71 wxBitmap my_horse_tiff;
72 wxBitmap my_horse_xpm;
73 wxBitmap my_horse_ico32;
74 wxBitmap my_horse_ico16;
75 wxBitmap my_horse_ico;
76 wxBitmap my_horse_cur;
77
78 wxBitmap my_smile_xbm;
79 wxBitmap my_square;
80 wxBitmap my_anti;
81
82 wxBitmap my_horse_asciigrey_pnm;
83 wxBitmap my_horse_rawgrey_pnm;
84
85 wxBitmap colorized_horse_jpeg;
234fedd2 86 wxBitmap my_cmyk_jpeg;
978d3d36 87
66df4ec6
VZ
88 wxBitmap my_toucan;
89 wxBitmap my_toucan_flipped_horiz;
90 wxBitmap my_toucan_flipped_vert;
91 wxBitmap my_toucan_flipped_both;
9061c15c 92 wxBitmap my_toucan_grey;
66df4ec6
VZ
93 wxBitmap my_toucan_head;
94
bf504f98 95 int xH, yH ;
bd981f27
VZ
96 int m_ani_images;
97 wxBitmap *my_horse_ani;
bf504f98 98
bd981f27 99private:
bea56879
VZ
100 wxBitmap m_bmpSmileXpm;
101 wxIcon m_iconSmileXpm;
102
1d5b7a0b 103 DECLARE_EVENT_TABLE()
01111366
RR
104};
105
18134a1c 106
01111366
RR
107// MyFrame
108
18134a1c 109
01111366
RR
110class MyFrame: public wxFrame
111{
1d5b7a0b
VZ
112public:
113 MyFrame();
01111366 114
01111366 115 void OnAbout( wxCommandEvent &event );
ab0f0386 116 void OnNewFrame( wxCommandEvent &event );
b3f04dc2
VZ
117#ifdef wxHAVE_RAW_BITMAP
118 void OnTestRawBitmap( wxCommandEvent &event );
119#endif // wxHAVE_RAW_BITMAP
01111366 120 void OnQuit( wxCommandEvent &event );
1d5b7a0b 121
dd38c875 122#if wxUSE_CLIPBOARD
da9df1f5
VZ
123 void OnCopy(wxCommandEvent& event);
124 void OnPaste(wxCommandEvent& event);
125#endif // wxUSE_CLIPBOARD
126
01111366 127 MyCanvas *m_canvas;
1d5b7a0b 128
60a41aee 129private:
1d5b7a0b
VZ
130 DECLARE_DYNAMIC_CLASS(MyFrame)
131 DECLARE_EVENT_TABLE()
01111366
RR
132};
133
ab0f0386
VZ
134class MyImageFrame : public wxFrame
135{
136public:
137 MyImageFrame(wxFrame *parent, const wxBitmap& bitmap)
47f797bd 138 : wxFrame(parent, wxID_ANY, _T("Double click to save"),
ab0f0386 139 wxDefaultPosition, wxDefaultSize,
40c79fab 140 wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX),
1971d23c 141 m_bitmap(bitmap)
ab0f0386
VZ
142 {
143 SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
144 }
145
0c543b7a
VZ
146 void OnEraseBackground(wxEraseEvent& WXUNUSED(event))
147 {
148 // do nothing here to be able to see how transparent images are shown
149 }
150
ab0f0386
VZ
151 void OnPaint(wxPaintEvent& WXUNUSED(event))
152 {
153 wxPaintDC dc( this );
47f797bd 154 dc.DrawBitmap( m_bitmap, 0, 0, true /* use mask */ );
ab0f0386
VZ
155 }
156
c5c843e0 157 void OnSave(wxMouseEvent& WXUNUSED(event))
1971d23c 158 {
71307412 159#if wxUSE_FILEDLG
368d59f0 160 wxImage image = m_bitmap.ConvertToImage();
1971d23c 161
4693b20c 162 wxString savefilename = wxFileSelector( wxT("Save Image"),
71307412
WS
163 wxEmptyString,
164 wxEmptyString,
4693b20c 165 (const wxChar *)NULL,
d0ee33f5
WS
166 wxT("BMP files (*.bmp)|*.bmp|")
167 wxT("PNG files (*.png)|*.png|")
168 wxT("JPEG files (*.jpg)|*.jpg|")
169 wxT("GIF files (*.gif)|*.gif|")
170 wxT("TIFF files (*.tif)|*.tif|")
171 wxT("PCX files (*.pcx)|*.pcx|")
172 wxT("ICO files (*.ico)|*.ico|")
173 wxT("CUR files (*.cur)|*.cur"),
ff3e84ff 174 wxFD_SAVE,
47f797bd 175 this);
1971d23c
VZ
176
177 if ( savefilename.empty() )
178 return;
179
5a566d89
VZ
180 wxString extension;
181 wxFileName::SplitPath(savefilename, NULL, NULL, &extension);
1971d23c 182
5a566d89
VZ
183 bool saved = false;
184 if ( extension == _T("bpp") )
185 {
186 static const int bppvalues[] =
187 {
188 wxBMP_1BPP,
189 wxBMP_1BPP_BW,
190 wxBMP_4BPP,
191 wxBMP_8BPP,
192 wxBMP_8BPP_GREY,
193 wxBMP_8BPP_RED,
194 wxBMP_8BPP_PALETTE,
195 wxBMP_24BPP
196 };
197
24207dfc 198 const wxString bppchoices[] =
5a566d89
VZ
199 {
200 _T("1 bpp color"),
201 _T("1 bpp B&W"),
202 _T("4 bpp color"),
203 _T("8 bpp color"),
204 _T("8 bpp greyscale"),
205 _T("8 bpp red"),
206 _T("8 bpp own palette"),
207 _T("24 bpp")
208 };
209
210 int bppselection = wxGetSingleChoiceIndex(_T("Set BMP BPP"),
211 _T("Image sample: save file"),
212 WXSIZEOF(bppchoices),
213 bppchoices,
214 this);
215 if ( bppselection != -1 )
216 {
217 int format = bppvalues[bppselection];
218 image.SetOption(wxIMAGE_OPTION_BMP_FORMAT, format);
219
220 if ( format == wxBMP_8BPP_PALETTE )
221 {
222 unsigned char *cmap = new unsigned char [256];
223 for ( int i = 0; i < 256; i++ )
224 cmap[i] = (unsigned char)i;
225 image.SetPalette(wxPalette(256, cmap, cmap, cmap));
226
d0ee33f5 227 delete[] cmap;
5a566d89
VZ
228 }
229 }
1971d23c 230 }
5a566d89
VZ
231 else if ( extension == _T("png") )
232 {
233 static const int pngvalues[] =
234 {
235 wxPNG_TYPE_COLOUR,
236 wxPNG_TYPE_COLOUR,
237 wxPNG_TYPE_GREY,
238 wxPNG_TYPE_GREY,
239 wxPNG_TYPE_GREY_RED,
240 wxPNG_TYPE_GREY_RED,
241 };
242
24207dfc 243 const wxString pngchoices[] =
5a566d89
VZ
244 {
245 _T("Colour 8bpp"),
246 _T("Colour 16bpp"),
247 _T("Grey 8bpp"),
248 _T("Grey 16bpp"),
249 _T("Grey red 8bpp"),
250 _T("Grey red 16bpp"),
251 };
252
253 int sel = wxGetSingleChoiceIndex(_T("Set PNG format"),
254 _T("Image sample: save file"),
255 WXSIZEOF(pngchoices),
256 pngchoices,
257 this);
258 if ( sel != -1 )
259 {
260 image.SetOption(wxIMAGE_OPTION_PNG_FORMAT, pngvalues[sel]);
261 image.SetOption(wxIMAGE_OPTION_PNG_BITDEPTH, sel % 2 ? 16 : 8);
262 }
263 }
264 else if ( extension == _T("cur") )
45647dcf 265 {
51b07644
VZ
266 image.Rescale(32,32);
267 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 0);
45647dcf
VS
268 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 0);
269 // This shows how you can save an image with explicitly
270 // specified image format:
5a566d89 271 saved = image.SaveFile(savefilename, wxBITMAP_TYPE_CUR);
45647dcf 272 }
5a566d89
VZ
273
274 if ( !saved )
45647dcf
VS
275 {
276 // This one guesses image format from filename extension
277 // (it may fail if the extension is not recognized):
5a566d89 278 image.SaveFile(savefilename);
45647dcf 279 }
71307412 280#endif // wxUSE_FILEDLG
1971d23c
VZ
281 }
282
ab0f0386
VZ
283private:
284 wxBitmap m_bitmap;
285
286 DECLARE_EVENT_TABLE()
287};
288
b3f04dc2
VZ
289#ifdef wxHAVE_RAW_BITMAP
290
291#include "wx/rawbmp.h"
292
293class MyRawBitmapFrame : public wxFrame
294{
295public:
296 enum
297 {
298 BORDER = 15,
299 SIZE = 150,
300 REAL_SIZE = SIZE - 2*BORDER
301 };
302
303 MyRawBitmapFrame(wxFrame *parent)
47f797bd 304 : wxFrame(parent, wxID_ANY, _T("Raw bitmaps (how exciting)")),
b3f04dc2
VZ
305 m_bitmap(SIZE, SIZE, 32)
306 {
307 SetClientSize(SIZE, SIZE);
308
095980e1
VZ
309 // another possibility: wxNativePixelData (don't forget to remove code
310 // setting alpha in the loop below then)
311 typedef wxAlphaPixelData Data;
6e5551ad 312 // typedef wxNativePixelData Data;
66df4ec6 313
6e5551ad
RR
314 // First, clear the whole bitmap by making it alpha
315 {
316 Data data( m_bitmap, wxPoint(0,0), wxSize(SIZE, SIZE) );
317 if ( !data )
318 {
319 wxLogError(_T("Failed to gain raw access to bitmap data"));
320 return;
321 }
322 data.UseAlpha();
323 Data::Iterator p(data);
324 for ( int y = 0; y < SIZE; ++y )
325 {
326 Data::Iterator rowStart = p;
327 for ( int x = 0; x < SIZE; ++x )
328 {
329 p.Alpha() = 0;
330 ++p; // same as p.OffsetX(1)
331 }
332 p = rowStart;
333 p.OffsetY(data, 1);
334 }
335 }
095980e1 336
6e5551ad
RR
337 // Then, draw colourful alpha-blended stripes
338 Data data(m_bitmap, wxPoint(BORDER, BORDER) , wxSize(REAL_SIZE, REAL_SIZE));
b3f04dc2
VZ
339 if ( !data )
340 {
341 wxLogError(_T("Failed to gain raw access to bitmap data"));
342 return;
343 }
344
4a101327 345 data.UseAlpha();
10b41b53 346
095980e1 347 Data::Iterator p(data);
b3f04dc2 348
b3f04dc2
VZ
349 for ( int y = 0; y < REAL_SIZE; ++y )
350 {
095980e1 351 Data::Iterator rowStart = p;
b3f04dc2
VZ
352
353 int r = y < REAL_SIZE/3 ? 255 : 0,
354 g = (REAL_SIZE/3 <= y) && (y < 2*(REAL_SIZE/3)) ? 255 : 0,
355 b = 2*(REAL_SIZE/3) <= y ? 255 : 0;
356
357 for ( int x = 0; x < REAL_SIZE; ++x )
358 {
b068dfe2
VZ
359 // note that RGB must be premultiplied by alpha
360 unsigned a = (Data::Iterator::ChannelType)((x*255.)/REAL_SIZE);
5c99abbe
MW
361 p.Red() = r * a / 256;
362 p.Green() = g * a / 256;
363 p.Blue() = b * a / 256;
b068dfe2 364 p.Alpha() = a;
b3f04dc2
VZ
365
366 ++p; // same as p.OffsetX(1)
367 }
368
369 p = rowStart;
1d2f48b6 370 p.OffsetY(data, 1);
b3f04dc2
VZ
371 }
372 }
373
374 void OnPaint(wxPaintEvent& WXUNUSED(event))
375 {
376 wxPaintDC dc( this );
377 dc.DrawText(_T("This is alpha and raw bitmap test"), 0, BORDER);
378 dc.DrawText(_T("This is alpha and raw bitmap test"), 0, SIZE/2 - BORDER);
379 dc.DrawText(_T("This is alpha and raw bitmap test"), 0, SIZE - 2*BORDER);
47f797bd 380 dc.DrawBitmap( m_bitmap, 0, 0, true /* use mask */ );
b3f04dc2
VZ
381 }
382
383private:
384 wxBitmap m_bitmap;
385
386 DECLARE_EVENT_TABLE()
387};
388
389#endif // wxHAVE_RAW_BITMAP
390
01111366
RR
391// MyApp
392
393class MyApp: public wxApp
394{
1d5b7a0b
VZ
395public:
396 virtual bool OnInit();
01111366
RR
397};
398
399// main program
400
401IMPLEMENT_APP(MyApp)
402
403// MyCanvas
404
ab0f0386 405BEGIN_EVENT_TABLE(MyImageFrame, wxFrame)
0c543b7a
VZ
406 EVT_ERASE_BACKGROUND(MyImageFrame::OnEraseBackground)
407 EVT_PAINT(MyImageFrame::OnPaint)
408 EVT_LEFT_DCLICK(MyImageFrame::OnSave)
ab0f0386
VZ
409END_EVENT_TABLE()
410
b3f04dc2
VZ
411#ifdef wxHAVE_RAW_BITMAP
412
413BEGIN_EVENT_TABLE(MyRawBitmapFrame, wxFrame)
414 EVT_PAINT(MyRawBitmapFrame::OnPaint)
415END_EVENT_TABLE()
416
417#endif // wxHAVE_RAW_BITMAP
418
1d5b7a0b
VZ
419BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
420 EVT_PAINT(MyCanvas::OnPaint)
01111366
RR
421END_EVENT_TABLE()
422
acbd13a3 423MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
1d5b7a0b 424 const wxPoint &pos, const wxSize &size )
81278df2 425 : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER )
81278df2
VZ
426 , m_bmpSmileXpm((const char **) smile_xpm)
427 , m_iconSmileXpm((const char **) smile_xpm)
01111366 428{
bd981f27 429 my_horse_ani = NULL;
2b5f62a0
VZ
430 m_ani_images = 0 ;
431
60a41aee
RR
432 SetBackgroundColour(* wxWHITE);
433
434 wxBitmap bitmap( 100, 100 );
435
436 wxMemoryDC dc;
437 dc.SelectObject( bitmap );
a60b1f5d 438 dc.SetBrush( wxBrush( wxT("orange"), wxSOLID ) );
cf3da716 439 dc.SetPen( *wxBLACK_PEN );
60a41aee 440 dc.DrawRectangle( 0, 0, 100, 100 );
cf3da716
RR
441 dc.SetBrush( *wxWHITE_BRUSH );
442 dc.DrawRectangle( 20, 20, 60, 60 );
60a41aee
RR
443 dc.SelectObject( wxNullBitmap );
444
445 // try to find the directory with our images
446 wxString dir;
4693b20c 447 if ( wxFile::Exists(wxT("./horse.png")) )
2b5f62a0 448 dir = wxT("./");
4693b20c 449 else if ( wxFile::Exists(wxT("../horse.png")) )
2b5f62a0 450 dir = wxT("../");
60a41aee 451 else
4693b20c 452 wxLogWarning(wxT("Can't find image files in either '.' or '..'!"));
60a41aee 453
a8d4e3ac 454 wxImage image = bitmap.ConvertToImage();
60a41aee 455
bea56879 456#if wxUSE_LIBPNG
51b07644 457 if ( !image.SaveFile( dir + _T("test.png"), wxBITMAP_TYPE_PNG ))
4693b20c 458 wxLogError(wxT("Can't save file"));
f6bcfd97 459
176fe5af 460 image.Destroy();
60a41aee 461
30ad0a14 462 if ( image.LoadFile( dir + _T("test.png") ) )
bd981f27 463 my_square = wxBitmap( image );
f6bcfd97 464
176fe5af 465 image.Destroy();
cc977e5f 466
51b07644 467 if ( !image.LoadFile( dir + _T("horse.png")) )
4693b20c 468 wxLogError(wxT("Can't load PNG image"));
60a41aee 469 else
bd981f27 470 my_horse_png = wxBitmap( image );
66df4ec6 471
9061c15c
WS
472 if ( !image.LoadFile( dir + _T("toucan.png")) )
473 wxLogError(wxT("Can't load PNG image"));
474 else
475 my_toucan = wxBitmap(image);
476
66df4ec6
VZ
477 my_toucan_flipped_horiz = wxBitmap(image.Mirror(true));
478 my_toucan_flipped_vert = wxBitmap(image.Mirror(false));
479 my_toucan_flipped_both = wxBitmap(image.Mirror(true).Mirror(false));
9061c15c 480 my_toucan_grey = wxBitmap(image.ConvertToGreyscale());
66df4ec6
VZ
481 my_toucan_head = wxBitmap(image.GetSubImage(wxRect(40, 7, 80, 60)));
482
bea56879 483#endif // wxUSE_LIBPNG
60a41aee 484
bea56879 485#if wxUSE_LIBJPEG
176fe5af 486 image.Destroy();
279ababf 487
51b07644 488 if ( !image.LoadFile( dir + _T("horse.jpg")) )
4693b20c 489 wxLogError(wxT("Can't load JPG image"));
60a41aee 490 else
978d3d36 491 {
bd981f27 492 my_horse_jpeg = wxBitmap( image );
234fedd2 493
978d3d36
VZ
494 // Colorize by rotating green hue to red
495 wxImage::HSVValue greenHSV = wxImage::RGBtoHSV(wxImage::RGBValue(0, 255, 0));
496 wxImage::HSVValue redHSV = wxImage::RGBtoHSV(wxImage::RGBValue(255, 0, 0));
497 image.RotateHue(redHSV.hue - greenHSV.hue);
bd981f27 498 colorized_horse_jpeg = wxBitmap( image );
978d3d36 499 }
234fedd2
VZ
500
501 if ( !image.LoadFile( dir + _T("cmyk.jpg")) )
502 wxLogError(_T("Can't load CMYK JPG image"));
503 else
504 my_cmyk_jpeg = wxBitmap(image);
bea56879 505#endif // wxUSE_LIBJPEG
6e47faf1
JS
506
507#if wxUSE_GIF
176fe5af 508 image.Destroy();
279ababf 509
2b5f62a0 510 if ( !image.LoadFile( dir + _T("horse.gif" )) )
4693b20c 511 wxLogError(wxT("Can't load GIF image"));
60a41aee 512 else
bd981f27 513 my_horse_gif = wxBitmap( image );
6e47faf1 514#endif
cbd4be25 515
6e47faf1 516#if wxUSE_PCX
176fe5af 517 image.Destroy();
279ababf 518
51b07644 519 if ( !image.LoadFile( dir + _T("horse.pcx"), wxBITMAP_TYPE_PCX ) )
4693b20c 520 wxLogError(wxT("Can't load PCX image"));
60a41aee 521 else
bd981f27 522 my_horse_pcx = wxBitmap( image );
6e47faf1 523#endif
cbd4be25 524
176fe5af 525 image.Destroy();
279ababf 526
51b07644 527 if ( !image.LoadFile( dir + _T("horse.bmp"), wxBITMAP_TYPE_BMP ) )
4693b20c 528 wxLogError(wxT("Can't load BMP image"));
60a41aee 529 else
bd981f27 530 my_horse_bmp = wxBitmap( image );
6319afe3 531
a8d4e3ac 532#if wxUSE_XPM
9d8bdf2d
VS
533 image.Destroy();
534
51b07644 535 if ( !image.LoadFile( dir + _T("horse.xpm"), wxBITMAP_TYPE_XPM ) )
4693b20c 536 wxLogError(wxT("Can't load XPM image"));
9d8bdf2d 537 else
bd981f27 538 my_horse_xpm = wxBitmap( image );
9d8bdf2d 539
51b07644 540 if ( !image.SaveFile( dir + _T("test.xpm"), wxBITMAP_TYPE_XPM ))
4693b20c 541 wxLogError(wxT("Can't save file"));
a8d4e3ac
VS
542#endif
543
6e47faf1 544#if wxUSE_PNM
176fe5af 545 image.Destroy();
279ababf 546
51b07644 547 if ( !image.LoadFile( dir + _T("horse.pnm"), wxBITMAP_TYPE_PNM ) )
4693b20c 548 wxLogError(wxT("Can't load PNM image"));
60a41aee 549 else
bd981f27 550 my_horse_pnm = wxBitmap( image );
3e8711ce
JS
551
552 image.Destroy();
553
554 if ( !image.LoadFile( dir + _T("horse_ag.pnm"), wxBITMAP_TYPE_PNM ) )
555 wxLogError(wxT("Can't load PNM image"));
556 else
bd981f27 557 my_horse_asciigrey_pnm = wxBitmap( image );
3e8711ce
JS
558
559 image.Destroy();
560
561 if ( !image.LoadFile( dir + _T("horse_rg.pnm"), wxBITMAP_TYPE_PNM ) )
562 wxLogError(wxT("Can't load PNM image"));
563 else
bd981f27 564 my_horse_rawgrey_pnm = wxBitmap( image );
6e47faf1 565#endif
f048e32f 566
60a41aee 567#if wxUSE_LIBTIFF
176fe5af 568 image.Destroy();
279ababf 569
51b07644 570 if ( !image.LoadFile( dir + _T("horse.tif"), wxBITMAP_TYPE_TIF ) )
4693b20c 571 wxLogError(wxT("Can't load TIFF image"));
60a41aee 572 else
bd981f27 573 my_horse_tiff = wxBitmap( image );
60a41aee
RR
574#endif
575
60a41aee 576 CreateAntiAliasedBitmap();
dc1dbfc6 577
bd981f27 578 my_smile_xbm = wxBitmap( (const char*)smile_bits, smile_width,
dc1dbfc6 579 smile_height, 1 );
bfef20bf
GRG
580
581 // demonstrates XPM automatically using the mask when saving
582 if ( m_bmpSmileXpm.Ok() )
51b07644 583 m_bmpSmileXpm.SaveFile(_T("saved.xpm"), wxBITMAP_TYPE_XPM);
bf504f98
VS
584
585#if wxUSE_ICO_CUR
586 image.Destroy();
587
51b07644 588 if ( !image.LoadFile( dir + _T("horse.ico"), wxBITMAP_TYPE_ICO, 0 ) )
bf504f98
VS
589 wxLogError(wxT("Can't load first ICO image"));
590 else
bd981f27 591 my_horse_ico32 = wxBitmap( image );
51b07644 592
bf504f98
VS
593 image.Destroy();
594
51b07644 595 if ( !image.LoadFile( dir + _T("horse.ico"), wxBITMAP_TYPE_ICO, 1 ) )
bf504f98
VS
596 wxLogError(wxT("Can't load second ICO image"));
597 else
bd981f27 598 my_horse_ico16 = wxBitmap( image );
bf504f98
VS
599
600 image.Destroy();
601
51b07644 602 if ( !image.LoadFile( dir + _T("horse.ico") ) )
bf504f98
VS
603 wxLogError(wxT("Can't load best ICO image"));
604 else
bd981f27 605 my_horse_ico = wxBitmap( image );
bf504f98
VS
606
607 image.Destroy();
608
51b07644 609 if ( !image.LoadFile( dir + _T("horse.cur"), wxBITMAP_TYPE_CUR ) )
bf504f98
VS
610 wxLogError(wxT("Can't load best ICO image"));
611 else
51b07644 612 {
bd981f27 613 my_horse_cur = wxBitmap( image );
fd94e8aa
VS
614 xH = 30 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X) ;
615 yH = 2420 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ;
51b07644 616 }
2b5f62a0 617
08811762 618 m_ani_images = wxImage::GetImageCount ( dir + _T("horse3.ani"), wxBITMAP_TYPE_ANI );
2b5f62a0
VZ
619 if (m_ani_images==0)
620 wxLogError(wxT("No ANI-format images found"));
621 else
622 my_horse_ani = new wxBitmap [m_ani_images];
623 int i ;
624 for (i=0; i < m_ani_images; i++)
625 {
626 image.Destroy();
08811762 627 if (!image.LoadFile( dir + _T("horse3.ani"), wxBITMAP_TYPE_ANI, i ))
2b5f62a0
VZ
628 {
629 wxString tmp = wxT("Can't load image number ");
630 tmp << i ;
631 wxLogError(tmp);
632 }
925e9792 633 else
2b5f62a0
VZ
634 my_horse_ani [i] = wxBitmap( image );
635 }
da9df1f5 636#endif // wxUSE_ICO_CUR
bf504f98 637
51b07644
VZ
638 image.Destroy();
639
640 // test image loading from stream
641 wxFile file(dir + _T("horse.bmp"));
30ad0a14 642 if ( file.IsOpened() )
51b07644 643 {
9386cb75
WS
644 wxFileOffset len = file.Length();
645 size_t dataSize = (size_t)len;
646 void *data = malloc(dataSize);
647 if ( file.Read(data, dataSize) != len )
30ad0a14 648 wxLogError(_T("Reading bitmap file failed"));
51b07644 649 else
30ad0a14 650 {
9386cb75 651 wxMemoryInputStream mis(data, dataSize);
30ad0a14
VZ
652 if ( !image.LoadFile(mis) )
653 wxLogError(wxT("Can't load BMP image from stream"));
654 else
bd981f27 655 my_horse_bmp2 = wxBitmap( image );
30ad0a14 656 }
51b07644 657
30ad0a14
VZ
658 free(data);
659 }
01111366
RR
660}
661
1d5b7a0b 662MyCanvas::~MyCanvas()
01111366 663{
2b5f62a0 664 delete [] my_horse_ani;
01111366
RR
665}
666
667void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
668{
be25e480
RR
669 wxPaintDC dc( this );
670 PrepareDC( dc );
a91b47e8 671
51b07644 672 dc.DrawText( _T("Loaded image"), 30, 10 );
bd981f27
VZ
673 if (my_square.Ok())
674 dc.DrawBitmap( my_square, 30, 30 );
f048e32f 675
51b07644 676 dc.DrawText( _T("Drawn directly"), 150, 10 );
a60b1f5d 677 dc.SetBrush( wxBrush( wxT("orange"), wxSOLID ) );
cf3da716 678 dc.SetPen( *wxBLACK_PEN );
be25e480 679 dc.DrawRectangle( 150, 30, 100, 100 );
cf3da716
RR
680 dc.SetBrush( *wxWHITE_BRUSH );
681 dc.DrawRectangle( 170, 50, 60, 60 );
be25e480 682
bd981f27
VZ
683 if (my_anti.Ok())
684 dc.DrawBitmap( my_anti, 280, 30 );
be25e480 685
51b07644 686 dc.DrawText( _T("PNG handler"), 30, 135 );
bd981f27 687 if (my_horse_png.Ok())
408b4168 688 {
bd981f27 689 dc.DrawBitmap( my_horse_png, 30, 150 );
be25e480 690 wxRect rect(0,0,100,100);
bd981f27 691 wxBitmap sub( my_horse_png.GetSubBitmap(rect) );
66df4ec6
VZ
692 dc.DrawText( _T("GetSubBitmap()"), 280, 175 );
693 dc.DrawBitmap( sub, 280, 195 );
be25e480
RR
694 }
695
51b07644 696 dc.DrawText( _T("JPEG handler"), 30, 365 );
bd981f27
VZ
697 if (my_horse_jpeg.Ok())
698 dc.DrawBitmap( my_horse_jpeg, 30, 380 );
be25e480 699
234fedd2
VZ
700 dc.DrawText( _T("Green rotated to red"), 280, 365 );
701 if (colorized_horse_jpeg.Ok())
702 dc.DrawBitmap( colorized_horse_jpeg, 280, 380 );
703
704 dc.DrawText( _T("CMYK JPEG image"), 530, 365 );
705 if (my_cmyk_jpeg.Ok())
706 dc.DrawBitmap( my_cmyk_jpeg, 530, 380 );
707
51b07644 708 dc.DrawText( _T("GIF handler"), 30, 595 );
bd981f27
VZ
709 if (my_horse_gif.Ok())
710 dc.DrawBitmap( my_horse_gif, 30, 610 );
be25e480 711
51b07644 712 dc.DrawText( _T("PCX handler"), 30, 825 );
bd981f27
VZ
713 if (my_horse_pcx.Ok())
714 dc.DrawBitmap( my_horse_pcx, 30, 840 );
be25e480 715
51b07644 716 dc.DrawText( _T("BMP handler"), 30, 1055 );
bd981f27
VZ
717 if (my_horse_bmp.Ok())
718 dc.DrawBitmap( my_horse_bmp, 30, 1070 );
be25e480 719
51b07644 720 dc.DrawText( _T("BMP read from memory"), 280, 1055 );
bd981f27
VZ
721 if (my_horse_bmp2.Ok())
722 dc.DrawBitmap( my_horse_bmp2, 280, 1070 );
51b07644
VZ
723
724 dc.DrawText( _T("PNM handler"), 30, 1285 );
bd981f27
VZ
725 if (my_horse_pnm.Ok())
726 dc.DrawBitmap( my_horse_pnm, 30, 1300 );
d0ee33f5 727
3e8711ce 728 dc.DrawText( _T("PNM handler (ascii grey)"), 280, 1285 );
bd981f27
VZ
729 if (my_horse_asciigrey_pnm.Ok())
730 dc.DrawBitmap( my_horse_asciigrey_pnm, 280, 1300 );
3e8711ce
JS
731
732 dc.DrawText( _T("PNM handler (raw grey)"), 530, 1285 );
bd981f27
VZ
733 if (my_horse_rawgrey_pnm.Ok())
734 dc.DrawBitmap( my_horse_rawgrey_pnm, 530, 1300 );
408b4168 735
51b07644 736 dc.DrawText( _T("TIFF handler"), 30, 1515 );
bd981f27
VZ
737 if (my_horse_tiff.Ok())
738 dc.DrawBitmap( my_horse_tiff, 30, 1530 );
be25e480 739
51b07644 740 dc.DrawText( _T("XPM handler"), 30, 1745 );
bd981f27
VZ
741 if (my_horse_xpm.Ok())
742 dc.DrawBitmap( my_horse_xpm, 30, 1760 );
9d8bdf2d 743
234fedd2 744 // toucans
66df4ec6 745 {
234fedd2 746 int x = 750, y = 10, yy = 170;
66df4ec6
VZ
747
748 dc.DrawText(wxT("Original toucan"), x+50, y);
749 dc.DrawBitmap(my_toucan, x, y+15);
750 y += yy;
751 dc.DrawText(wxT("Flipped horizontally"), x+50, y);
752 dc.DrawBitmap(my_toucan_flipped_horiz, x, y+15);
753 y += yy;
754 dc.DrawText(wxT("Flipped vertically"), x+50, y);
755 dc.DrawBitmap(my_toucan_flipped_vert, x, y+15);
756 y += yy;
757 dc.DrawText(wxT("Flipped both h&v"), x+50, y);
758 dc.DrawBitmap(my_toucan_flipped_both, x, y+15);
759
9061c15c
WS
760 y += yy;
761 dc.DrawText(wxT("In greyscale"), x+50, y);
762 dc.DrawBitmap(my_toucan_grey, x, y+15);
763
66df4ec6
VZ
764 y += yy;
765 dc.DrawText(wxT("Toucan's head"), x+50, y);
766 dc.DrawBitmap(my_toucan_head, x, y+15);
767 }
bf504f98 768
bd981f27 769 if (my_smile_xbm.Ok())
be25e480 770 {
51b07644
VZ
771 dc.DrawText( _T("XBM bitmap"), 30, 1975 );
772 dc.DrawText( _T("(green on red)"), 30, 1990 );
773 dc.SetTextForeground( _T("GREEN") );
774 dc.SetTextBackground( _T("RED") );
bd981f27 775 dc.DrawBitmap( my_smile_xbm, 30, 2010 );
408b4168 776
19bc1514 777 dc.SetTextForeground( *wxBLACK );
51b07644
VZ
778 dc.DrawText( _T("After wxImage conversion"), 150, 1975 );
779 dc.DrawText( _T("(red on white)"), 150, 1990 );
a60b1f5d 780 dc.SetTextForeground( wxT("RED") );
bd981f27 781 wxImage i = my_smile_xbm.ConvertToImage();
176fe5af
GRG
782 i.SetMaskColour( 255, 255, 255 );
783 i.Replace( 0, 0, 0,
be25e480
RR
784 wxRED_PEN->GetColour().Red(),
785 wxRED_PEN->GetColour().Green(),
786 wxRED_PEN->GetColour().Blue() );
47f797bd 787 dc.DrawBitmap( wxBitmap(i), 150, 2010, true );
19bc1514 788 dc.SetTextForeground( *wxBLACK );
be25e480 789 }
176fe5af 790
408b4168 791
41fbc841 792 wxBitmap mono( 60,50,1 );
82ea63e6
RR
793 wxMemoryDC memdc;
794 memdc.SelectObject( mono );
bfef20bf 795 memdc.SetPen( *wxBLACK_PEN );
82ea63e6 796 memdc.SetBrush( *wxWHITE_BRUSH );
41fbc841
RR
797 memdc.DrawRectangle( 0,0,60,50 );
798 memdc.SetTextForeground( *wxBLACK );
9fe7d430
RR
799#ifndef __WXGTK20__
800 // I cannot convince GTK2 to draw into mono bitmaps
51b07644 801 memdc.DrawText( _T("Hi!"), 5, 5 );
9fe7d430 802#endif
41fbc841
RR
803 memdc.SetBrush( *wxBLACK_BRUSH );
804 memdc.DrawRectangle( 33,5,20,20 );
805 memdc.SetPen( *wxRED_PEN );
806 memdc.DrawLine( 5, 42, 50, 42 );
82ea63e6 807 memdc.SelectObject( wxNullBitmap );
176fe5af 808
408b4168 809 if (mono.Ok())
82ea63e6 810 {
51b07644
VZ
811 dc.DrawText( _T("Mono bitmap"), 30, 2095 );
812 dc.DrawText( _T("(red on green)"), 30, 2110 );
a60b1f5d
MB
813 dc.SetTextForeground( wxT("RED") );
814 dc.SetTextBackground( wxT("GREEN") );
9d8bdf2d 815 dc.DrawBitmap( mono, 30, 2130 );
408b4168 816
19bc1514 817 dc.SetTextForeground( *wxBLACK );
51b07644
VZ
818 dc.DrawText( _T("After wxImage conversion"), 150, 2095 );
819 dc.DrawText( _T("(red on white)"), 150, 2110 );
a60b1f5d 820 dc.SetTextForeground( wxT("RED") );
a8d4e3ac 821 wxImage i = mono.ConvertToImage();
408b4168
VZ
822 i.SetMaskColour( 255,255,255 );
823 i.Replace( 0,0,0,
82ea63e6
RR
824 wxRED_PEN->GetColour().Red(),
825 wxRED_PEN->GetColour().Green(),
826 wxRED_PEN->GetColour().Blue() );
47f797bd 827 dc.DrawBitmap( wxBitmap(i), 150, 2130, true );
19bc1514 828 dc.SetTextForeground( *wxBLACK );
bea56879
VZ
829 }
830
f9ebac93
RR
831 // For testing transparency
832 dc.SetBrush( *wxRED_BRUSH );
833 dc.DrawRectangle( 20, 2220, 560, 68 );
925e9792 834
f9ebac93 835 dc.DrawText(_T("XPM bitmap"), 30, 2230 );
bea56879 836 if ( m_bmpSmileXpm.Ok() )
47f797bd 837 dc.DrawBitmap(m_bmpSmileXpm, 30, 2250, true);
bea56879 838
f9ebac93 839 dc.DrawText(_T("XPM icon"), 110, 2230 );
bea56879 840 if ( m_iconSmileXpm.Ok() )
f9ebac93 841 dc.DrawIcon(m_iconSmileXpm, 110, 2250);
925e9792
WS
842
843 // testing icon -> bitmap conversion
f9ebac93 844 wxBitmap to_blit( m_iconSmileXpm );
3ef37e7f
JS
845 if (to_blit.Ok())
846 {
847 dc.DrawText( _T("SubBitmap"), 170, 2230 );
848 wxBitmap sub = to_blit.GetSubBitmap( wxRect(0,0,15,15) );
849 if (sub.Ok())
47f797bd 850 dc.DrawBitmap( sub, 170, 2250, true );
3ef37e7f
JS
851
852 dc.DrawText( _T("Enlarged"), 250, 2230 );
853 dc.SetUserScale( 1.5, 1.5 );
47f797bd 854 dc.DrawBitmap( to_blit, (int)(250/1.5), (int)(2250/1.5), true );
3ef37e7f 855 dc.SetUserScale( 2, 2 );
47f797bd 856 dc.DrawBitmap( to_blit, (int)(300/2), (int)(2250/2), true );
3ef37e7f 857 dc.SetUserScale( 1.0, 1.0 );
925e9792 858
3ef37e7f
JS
859 dc.DrawText( _T("Blit"), 400, 2230);
860 wxMemoryDC blit_dc;
861 blit_dc.SelectObject( to_blit );
47f797bd 862 dc.Blit( 400, 2250, to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
3ef37e7f 863 dc.SetUserScale( 1.5, 1.5 );
47f797bd 864 dc.Blit( (int)(450/1.5), (int)(2250/1.5), to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
3ef37e7f 865 dc.SetUserScale( 2, 2 );
47f797bd 866 dc.Blit( (int)(500/2), (int)(2250/2), to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
3ef37e7f
JS
867 dc.SetUserScale( 1.0, 1.0 );
868 }
bf504f98 869
51b07644 870 dc.DrawText( _T("ICO handler (1st image)"), 30, 2290 );
bd981f27
VZ
871 if (my_horse_ico32.Ok())
872 dc.DrawBitmap( my_horse_ico32, 30, 2330, true );
bf504f98 873
51b07644 874 dc.DrawText( _T("ICO handler (2nd image)"), 230, 2290 );
bd981f27
VZ
875 if (my_horse_ico16.Ok())
876 dc.DrawBitmap( my_horse_ico16, 230, 2330, true );
51b07644
VZ
877
878 dc.DrawText( _T("ICO handler (best image)"), 430, 2290 );
bd981f27
VZ
879 if (my_horse_ico.Ok())
880 dc.DrawBitmap( my_horse_ico, 430, 2330, true );
bf504f98 881
51b07644 882 dc.DrawText( _T("CUR handler"), 30, 2390 );
bd981f27 883 if (my_horse_cur.Ok())
51b07644 884 {
bd981f27 885 dc.DrawBitmap( my_horse_cur, 30, 2420, true );
bf504f98
VS
886 dc.SetPen (*wxRED_PEN);
887 dc.DrawLine (xH-10,yH,xH+10,yH);
888 dc.DrawLine (xH,yH-10,xH,yH+10);
51b07644 889 }
bd981f27 890
2b5f62a0 891 dc.DrawText( _T("ANI handler"), 230, 2390 );
bd981f27
VZ
892 for ( int i=0; i < m_ani_images; i++ )
893 {
2b5f62a0
VZ
894 if (my_horse_ani[i].Ok())
895 {
47f797bd 896 dc.DrawBitmap( my_horse_ani[i], 230 + i * 2 * my_horse_ani[i].GetWidth() , 2420, true );
2b5f62a0 897 }
bd981f27 898 }
9390a202 899}
1d5b7a0b 900
9390a202
RR
901void MyCanvas::CreateAntiAliasedBitmap()
902{
903 wxBitmap bitmap( 300, 300 );
a91b47e8 904
9390a202 905 wxMemoryDC dc;
a91b47e8 906
9390a202 907 dc.SelectObject( bitmap );
a91b47e8 908
9390a202 909 dc.Clear();
f048e32f 910
6e47faf1 911 dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL) );
a60b1f5d 912 dc.SetTextForeground( wxT("RED") );
66df4ec6
VZ
913 dc.DrawText( _T("This is anti-aliased Text."), 20, 5 );
914 dc.DrawText( _T("And a Rectangle."), 20, 45 );
f048e32f 915
9390a202 916 dc.SetBrush( *wxRED_BRUSH );
91b8de8d 917 dc.SetPen( *wxTRANSPARENT_PEN );
66df4ec6 918 dc.DrawRoundedRectangle( 20, 85, 200, 180, 20 );
f048e32f 919
a8d4e3ac 920 wxImage original= bitmap.ConvertToImage();
9390a202 921 wxImage anti( 150, 150 );
a91b47e8 922
9390a202 923 /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */
f048e32f 924
9390a202
RR
925 for (int y = 1; y < 149; y++)
926 for (int x = 1; x < 149; x++)
927 {
928 int red = original.GetRed( x*2, y*2 ) +
f048e32f
VZ
929 original.GetRed( x*2-1, y*2 ) +
930 original.GetRed( x*2, y*2+1 ) +
9390a202 931 original.GetRed( x*2+1, y*2+1 );
f048e32f
VZ
932 red = red/4;
933
9390a202 934 int green = original.GetGreen( x*2, y*2 ) +
f048e32f
VZ
935 original.GetGreen( x*2-1, y*2 ) +
936 original.GetGreen( x*2, y*2+1 ) +
9390a202 937 original.GetGreen( x*2+1, y*2+1 );
f048e32f
VZ
938 green = green/4;
939
9390a202 940 int blue = original.GetBlue( x*2, y*2 ) +
f048e32f
VZ
941 original.GetBlue( x*2-1, y*2 ) +
942 original.GetBlue( x*2, y*2+1 ) +
9390a202 943 original.GetBlue( x*2+1, y*2+1 );
f048e32f 944 blue = blue/4;
925e9792 945 anti.SetRGB( x, y, (unsigned char)red, (unsigned char)green, (unsigned char)blue );
9390a202 946 }
bd981f27 947 my_anti = wxBitmap(anti);
01111366
RR
948}
949
950// MyFrame
951
b3f04dc2
VZ
952enum
953{
91b07357
JS
954 ID_QUIT = wxID_EXIT,
955 ID_ABOUT = wxID_ABOUT,
956 ID_NEW = 100,
957 ID_SHOWRAW = 101
b3f04dc2 958};
01111366
RR
959
960IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
961
962BEGIN_EVENT_TABLE(MyFrame,wxFrame)
963 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
964 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
ab0f0386 965 EVT_MENU (ID_NEW, MyFrame::OnNewFrame)
b3f04dc2
VZ
966#ifdef wxHAVE_RAW_BITMAP
967 EVT_MENU (ID_SHOWRAW, MyFrame::OnTestRawBitmap)
968#endif
da9df1f5 969
dd38c875 970#if wxUSE_CLIPBOARD
da9df1f5
VZ
971 EVT_MENU(wxID_COPY, MyFrame::OnCopy)
972 EVT_MENU(wxID_PASTE, MyFrame::OnPaste)
973#endif // wxUSE_CLIPBOARD
01111366
RR
974END_EVENT_TABLE()
975
1d5b7a0b 976MyFrame::MyFrame()
47f797bd 977 : wxFrame( (wxFrame *)NULL, wxID_ANY, _T("wxImage sample"),
234fedd2 978 wxPoint(20, 20), wxSize(950, 700) )
01111366 979{
da9df1f5
VZ
980 wxMenuBar *menu_bar = new wxMenuBar();
981
982 wxMenu *menuImage = new wxMenu;
983 menuImage->Append( ID_NEW, _T("&Show any image...\tCtrl-O"));
1e3c12d7 984
b3f04dc2 985#ifdef wxHAVE_RAW_BITMAP
da9df1f5 986 menuImage->Append( ID_SHOWRAW, _T("Test &raw bitmap...\tCtrl-R"));
b3f04dc2 987#endif
da9df1f5
VZ
988 menuImage->AppendSeparator();
989 menuImage->Append( ID_ABOUT, _T("&About..."));
990 menuImage->AppendSeparator();
991 menuImage->Append( ID_QUIT, _T("E&xit\tCtrl-Q"));
992 menu_bar->Append(menuImage, _T("&Image"));
993
dd38c875 994#if wxUSE_CLIPBOARD
da9df1f5
VZ
995 wxMenu *menuClipboard = new wxMenu;
996 menuClipboard->Append(wxID_COPY, _T("&Copy test image\tCtrl-C"));
997 menuClipboard->Append(wxID_PASTE, _T("&Paste image\tCtrl-V"));
998 menu_bar->Append(menuClipboard, _T("&Clipboard"));
999#endif // wxUSE_CLIPBOARD
3d05544e 1000
01111366 1001 SetMenuBar( menu_bar );
1d5b7a0b 1002
8520f137 1003#if wxUSE_STATUSBAR
917e533b
RR
1004 CreateStatusBar(2);
1005 int widths[] = { -1, 100 };
1006 SetStatusWidths( 2, widths );
8520f137 1007#endif // wxUSE_STATUSBAR
1d5b7a0b 1008
47f797bd 1009 m_canvas = new MyCanvas( this, wxID_ANY, wxPoint(0,0), wxSize(10,10) );
cbd4be25 1010
978d3d36
VZ
1011 // 500 width * 2750 height
1012 m_canvas->SetScrollbars( 10, 10, 50, 275 );
01111366
RR
1013}
1014
1015void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
1016{
47f797bd 1017 Close( true );
01111366
RR
1018}
1019
1020void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
1021{
51b07644
VZ
1022 (void)wxMessageBox( _T("wxImage demo\n")
1023 _T("Robert Roebling (c) 1998,2000"),
1024 _T("About wxImage Demo"), wxICON_INFORMATION | wxOK );
fb1585ae
RR
1025}
1026
ab0f0386
VZ
1027void MyFrame::OnNewFrame( wxCommandEvent &WXUNUSED(event) )
1028{
71307412 1029#if wxUSE_FILEDLG
f6bcfd97
BP
1030 wxString filename = wxFileSelector(_T("Select image file"));
1031 if ( !filename )
1032 return;
1033
1034 wxImage image;
1035 if ( !image.LoadFile(filename) )
1036 {
1037 wxLogError(_T("Couldn't load image from '%s'."), filename.c_str());
1038
1039 return;
1040 }
1041
368d59f0 1042 (new MyImageFrame(this, wxBitmap(image)))->Show();
71307412 1043#endif // wxUSE_FILEDLG
ab0f0386
VZ
1044}
1045
b3f04dc2
VZ
1046#ifdef wxHAVE_RAW_BITMAP
1047
481721e8 1048void MyFrame::OnTestRawBitmap( wxCommandEvent &WXUNUSED(event) )
b3f04dc2
VZ
1049{
1050 (new MyRawBitmapFrame(this))->Show();
1051}
1052
1053#endif // wxHAVE_RAW_BITMAP
1054
dd38c875 1055#if wxUSE_CLIPBOARD
da9df1f5
VZ
1056
1057void MyFrame::OnCopy(wxCommandEvent& WXUNUSED(event))
1058{
1059 wxBitmapDataObject *dobjBmp = new wxBitmapDataObject;
bd981f27 1060 dobjBmp->SetBitmap(m_canvas->my_horse_png);
da9df1f5 1061
dd38c875
MB
1062 wxTheClipboard->Open();
1063
da9df1f5
VZ
1064 if ( !wxTheClipboard->SetData(dobjBmp) )
1065 {
1066 wxLogError(_T("Failed to copy bitmap to clipboard"));
1067 }
dd38c875
MB
1068
1069 wxTheClipboard->Close();
da9df1f5
VZ
1070}
1071
1072void MyFrame::OnPaste(wxCommandEvent& WXUNUSED(event))
1073{
1074 wxBitmapDataObject dobjBmp;
dd38c875
MB
1075
1076 wxTheClipboard->Open();
da9df1f5
VZ
1077 if ( !wxTheClipboard->GetData(dobjBmp) )
1078 {
1079 wxLogMessage(_T("No bitmap data in the clipboard"));
1080 }
1081 else
1082 {
1083 (new MyImageFrame(this, dobjBmp.GetBitmap()))->Show();
1084 }
dd38c875 1085 wxTheClipboard->Close();
da9df1f5
VZ
1086}
1087
1088#endif // wxUSE_CLIPBOARD
1089
01111366
RR
1090//-----------------------------------------------------------------------------
1091// MyApp
1092//-----------------------------------------------------------------------------
1093
1d5b7a0b 1094bool MyApp::OnInit()
01111366 1095{
e9c4b1a2
JS
1096#if wxUSE_LIBPNG
1097 wxImage::AddHandler( new wxPNGHandler );
1098#endif
1099
1100#if wxUSE_LIBJPEG
1101 wxImage::AddHandler( new wxJPEGHandler );
1102#endif
1103
60a41aee
RR
1104#if wxUSE_LIBTIFF
1105 wxImage::AddHandler( new wxTIFFHandler );
1106#endif
1107
6e47faf1 1108#if wxUSE_GIF
e1929140 1109 wxImage::AddHandler( new wxGIFHandler );
6e47faf1
JS
1110#endif
1111
1112#if wxUSE_PCX
cbd4be25 1113 wxImage::AddHandler( new wxPCXHandler );
6e47faf1
JS
1114#endif
1115
1116#if wxUSE_PNM
6319afe3 1117 wxImage::AddHandler( new wxPNMHandler );
6e47faf1 1118#endif
e1929140 1119
a8d4e3ac
VS
1120#if wxUSE_XPM
1121 wxImage::AddHandler( new wxXPMHandler );
1122#endif
1123
bf504f98
VS
1124#if wxUSE_ICO_CUR
1125 wxImage::AddHandler( new wxICOHandler );
1126 wxImage::AddHandler( new wxCURHandler );
2b5f62a0 1127 wxImage::AddHandler( new wxANIHandler );
bf504f98
VS
1128#endif
1129
01111366 1130 wxFrame *frame = new MyFrame();
47f797bd 1131 frame->Show( true );
1d5b7a0b 1132
47f797bd 1133 return true;
01111366 1134}