]> git.saurik.com Git - wxWidgets.git/blame - samples/image/image.cpp
removed unneeded header
[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)")),
8ef08948
RD
305 m_bitmap(SIZE, SIZE, 24),
306 m_alphaBitmap(SIZE, SIZE, 32)
b3f04dc2 307 {
8ef08948 308 SetClientSize(SIZE, SIZE*2+25);
b3f04dc2 309
8ef08948
RD
310 InitAlphaBitmap();
311 InitBitmap();
66df4ec6 312
8ef08948
RD
313 }
314
315 void InitAlphaBitmap()
316 {
6e5551ad
RR
317 // First, clear the whole bitmap by making it alpha
318 {
8ef08948 319 wxAlphaPixelData data( m_alphaBitmap, wxPoint(0,0), wxSize(SIZE, SIZE) );
6e5551ad
RR
320 if ( !data )
321 {
322 wxLogError(_T("Failed to gain raw access to bitmap data"));
323 return;
324 }
325 data.UseAlpha();
8ef08948 326 wxAlphaPixelData::Iterator p(data);
6e5551ad
RR
327 for ( int y = 0; y < SIZE; ++y )
328 {
8ef08948 329 wxAlphaPixelData::Iterator rowStart = p;
6e5551ad
RR
330 for ( int x = 0; x < SIZE; ++x )
331 {
332 p.Alpha() = 0;
333 ++p; // same as p.OffsetX(1)
334 }
335 p = rowStart;
336 p.OffsetY(data, 1);
337 }
338 }
095980e1 339
6e5551ad 340 // Then, draw colourful alpha-blended stripes
8ef08948
RD
341 wxAlphaPixelData data(m_alphaBitmap, wxPoint(BORDER, BORDER),
342 wxSize(REAL_SIZE, REAL_SIZE));
b3f04dc2
VZ
343 if ( !data )
344 {
345 wxLogError(_T("Failed to gain raw access to bitmap data"));
346 return;
347 }
348
4a101327 349 data.UseAlpha();
8ef08948 350 wxAlphaPixelData::Iterator p(data);
b3f04dc2 351
b3f04dc2
VZ
352 for ( int y = 0; y < REAL_SIZE; ++y )
353 {
8ef08948 354 wxAlphaPixelData::Iterator rowStart = p;
b3f04dc2
VZ
355
356 int r = y < REAL_SIZE/3 ? 255 : 0,
357 g = (REAL_SIZE/3 <= y) && (y < 2*(REAL_SIZE/3)) ? 255 : 0,
358 b = 2*(REAL_SIZE/3) <= y ? 255 : 0;
359
360 for ( int x = 0; x < REAL_SIZE; ++x )
361 {
b068dfe2 362 // note that RGB must be premultiplied by alpha
8ef08948 363 unsigned a = (wxAlphaPixelData::Iterator::ChannelType)((x*255.)/REAL_SIZE);
5c99abbe
MW
364 p.Red() = r * a / 256;
365 p.Green() = g * a / 256;
366 p.Blue() = b * a / 256;
b068dfe2 367 p.Alpha() = a;
b3f04dc2
VZ
368
369 ++p; // same as p.OffsetX(1)
370 }
371
372 p = rowStart;
1d2f48b6 373 p.OffsetY(data, 1);
b3f04dc2
VZ
374 }
375 }
376
8ef08948
RD
377 void InitBitmap()
378 {
379 // draw some colourful stripes without alpha
380 wxNativePixelData data(m_bitmap);
381 if ( !data )
382 {
383 wxLogError(_T("Failed to gain raw access to bitmap data"));
384 return;
385 }
386
387 wxNativePixelData::Iterator p(data);
388 for ( int y = 0; y < SIZE; ++y )
389 {
390 wxNativePixelData::Iterator rowStart = p;
391
392 int r = y < SIZE/3 ? 255 : 0,
393 g = (SIZE/3 <= y) && (y < 2*(SIZE/3)) ? 255 : 0,
394 b = 2*(SIZE/3) <= y ? 255 : 0;
395
396 for ( int x = 0; x < SIZE; ++x )
397 {
398 p.Red() = r;
399 p.Green() = g;
400 p.Blue() = b;
401 ++p; // same as p.OffsetX(1)
402 }
403
404 p = rowStart;
405 p.OffsetY(data, 1);
406 }
407 }
408
b3f04dc2
VZ
409 void OnPaint(wxPaintEvent& WXUNUSED(event))
410 {
411 wxPaintDC dc( this );
412 dc.DrawText(_T("This is alpha and raw bitmap test"), 0, BORDER);
413 dc.DrawText(_T("This is alpha and raw bitmap test"), 0, SIZE/2 - BORDER);
414 dc.DrawText(_T("This is alpha and raw bitmap test"), 0, SIZE - 2*BORDER);
8ef08948
RD
415 dc.DrawBitmap( m_alphaBitmap, 0, 0, true /* use mask */ );
416
417 dc.DrawText(_T("Raw bitmap access without alpha"), 0, SIZE+5);
418 dc.DrawBitmap( m_bitmap, 0, SIZE+5+dc.GetCharHeight());
b3f04dc2
VZ
419 }
420
421private:
422 wxBitmap m_bitmap;
8ef08948 423 wxBitmap m_alphaBitmap;
b3f04dc2
VZ
424
425 DECLARE_EVENT_TABLE()
426};
427
428#endif // wxHAVE_RAW_BITMAP
429
01111366
RR
430// MyApp
431
432class MyApp: public wxApp
433{
1d5b7a0b
VZ
434public:
435 virtual bool OnInit();
01111366
RR
436};
437
438// main program
439
440IMPLEMENT_APP(MyApp)
441
442// MyCanvas
443
ab0f0386 444BEGIN_EVENT_TABLE(MyImageFrame, wxFrame)
0c543b7a
VZ
445 EVT_ERASE_BACKGROUND(MyImageFrame::OnEraseBackground)
446 EVT_PAINT(MyImageFrame::OnPaint)
447 EVT_LEFT_DCLICK(MyImageFrame::OnSave)
ab0f0386
VZ
448END_EVENT_TABLE()
449
b3f04dc2
VZ
450#ifdef wxHAVE_RAW_BITMAP
451
452BEGIN_EVENT_TABLE(MyRawBitmapFrame, wxFrame)
453 EVT_PAINT(MyRawBitmapFrame::OnPaint)
454END_EVENT_TABLE()
455
456#endif // wxHAVE_RAW_BITMAP
457
1d5b7a0b
VZ
458BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
459 EVT_PAINT(MyCanvas::OnPaint)
01111366
RR
460END_EVENT_TABLE()
461
acbd13a3 462MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
1d5b7a0b 463 const wxPoint &pos, const wxSize &size )
81278df2 464 : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER )
81278df2
VZ
465 , m_bmpSmileXpm((const char **) smile_xpm)
466 , m_iconSmileXpm((const char **) smile_xpm)
01111366 467{
bd981f27 468 my_horse_ani = NULL;
2b5f62a0
VZ
469 m_ani_images = 0 ;
470
60a41aee
RR
471 SetBackgroundColour(* wxWHITE);
472
473 wxBitmap bitmap( 100, 100 );
474
475 wxMemoryDC dc;
476 dc.SelectObject( bitmap );
a60b1f5d 477 dc.SetBrush( wxBrush( wxT("orange"), wxSOLID ) );
cf3da716 478 dc.SetPen( *wxBLACK_PEN );
60a41aee 479 dc.DrawRectangle( 0, 0, 100, 100 );
cf3da716
RR
480 dc.SetBrush( *wxWHITE_BRUSH );
481 dc.DrawRectangle( 20, 20, 60, 60 );
60a41aee
RR
482 dc.SelectObject( wxNullBitmap );
483
484 // try to find the directory with our images
485 wxString dir;
4693b20c 486 if ( wxFile::Exists(wxT("./horse.png")) )
2b5f62a0 487 dir = wxT("./");
4693b20c 488 else if ( wxFile::Exists(wxT("../horse.png")) )
2b5f62a0 489 dir = wxT("../");
60a41aee 490 else
4693b20c 491 wxLogWarning(wxT("Can't find image files in either '.' or '..'!"));
60a41aee 492
a8d4e3ac 493 wxImage image = bitmap.ConvertToImage();
60a41aee 494
bea56879 495#if wxUSE_LIBPNG
51b07644 496 if ( !image.SaveFile( dir + _T("test.png"), wxBITMAP_TYPE_PNG ))
4693b20c 497 wxLogError(wxT("Can't save file"));
f6bcfd97 498
176fe5af 499 image.Destroy();
60a41aee 500
30ad0a14 501 if ( image.LoadFile( dir + _T("test.png") ) )
bd981f27 502 my_square = wxBitmap( image );
f6bcfd97 503
176fe5af 504 image.Destroy();
cc977e5f 505
51b07644 506 if ( !image.LoadFile( dir + _T("horse.png")) )
4693b20c 507 wxLogError(wxT("Can't load PNG image"));
60a41aee 508 else
bd981f27 509 my_horse_png = wxBitmap( image );
66df4ec6 510
9061c15c
WS
511 if ( !image.LoadFile( dir + _T("toucan.png")) )
512 wxLogError(wxT("Can't load PNG image"));
513 else
514 my_toucan = wxBitmap(image);
515
66df4ec6
VZ
516 my_toucan_flipped_horiz = wxBitmap(image.Mirror(true));
517 my_toucan_flipped_vert = wxBitmap(image.Mirror(false));
518 my_toucan_flipped_both = wxBitmap(image.Mirror(true).Mirror(false));
9061c15c 519 my_toucan_grey = wxBitmap(image.ConvertToGreyscale());
66df4ec6
VZ
520 my_toucan_head = wxBitmap(image.GetSubImage(wxRect(40, 7, 80, 60)));
521
bea56879 522#endif // wxUSE_LIBPNG
60a41aee 523
bea56879 524#if wxUSE_LIBJPEG
176fe5af 525 image.Destroy();
279ababf 526
51b07644 527 if ( !image.LoadFile( dir + _T("horse.jpg")) )
4693b20c 528 wxLogError(wxT("Can't load JPG image"));
60a41aee 529 else
978d3d36 530 {
bd981f27 531 my_horse_jpeg = wxBitmap( image );
234fedd2 532
978d3d36
VZ
533 // Colorize by rotating green hue to red
534 wxImage::HSVValue greenHSV = wxImage::RGBtoHSV(wxImage::RGBValue(0, 255, 0));
535 wxImage::HSVValue redHSV = wxImage::RGBtoHSV(wxImage::RGBValue(255, 0, 0));
536 image.RotateHue(redHSV.hue - greenHSV.hue);
bd981f27 537 colorized_horse_jpeg = wxBitmap( image );
978d3d36 538 }
234fedd2
VZ
539
540 if ( !image.LoadFile( dir + _T("cmyk.jpg")) )
541 wxLogError(_T("Can't load CMYK JPG image"));
542 else
543 my_cmyk_jpeg = wxBitmap(image);
bea56879 544#endif // wxUSE_LIBJPEG
6e47faf1
JS
545
546#if wxUSE_GIF
176fe5af 547 image.Destroy();
279ababf 548
2b5f62a0 549 if ( !image.LoadFile( dir + _T("horse.gif" )) )
4693b20c 550 wxLogError(wxT("Can't load GIF image"));
60a41aee 551 else
bd981f27 552 my_horse_gif = wxBitmap( image );
6e47faf1 553#endif
cbd4be25 554
6e47faf1 555#if wxUSE_PCX
176fe5af 556 image.Destroy();
279ababf 557
51b07644 558 if ( !image.LoadFile( dir + _T("horse.pcx"), wxBITMAP_TYPE_PCX ) )
4693b20c 559 wxLogError(wxT("Can't load PCX image"));
60a41aee 560 else
bd981f27 561 my_horse_pcx = wxBitmap( image );
6e47faf1 562#endif
cbd4be25 563
176fe5af 564 image.Destroy();
279ababf 565
51b07644 566 if ( !image.LoadFile( dir + _T("horse.bmp"), wxBITMAP_TYPE_BMP ) )
4693b20c 567 wxLogError(wxT("Can't load BMP image"));
60a41aee 568 else
bd981f27 569 my_horse_bmp = wxBitmap( image );
6319afe3 570
a8d4e3ac 571#if wxUSE_XPM
9d8bdf2d
VS
572 image.Destroy();
573
51b07644 574 if ( !image.LoadFile( dir + _T("horse.xpm"), wxBITMAP_TYPE_XPM ) )
4693b20c 575 wxLogError(wxT("Can't load XPM image"));
9d8bdf2d 576 else
bd981f27 577 my_horse_xpm = wxBitmap( image );
9d8bdf2d 578
51b07644 579 if ( !image.SaveFile( dir + _T("test.xpm"), wxBITMAP_TYPE_XPM ))
4693b20c 580 wxLogError(wxT("Can't save file"));
a8d4e3ac
VS
581#endif
582
6e47faf1 583#if wxUSE_PNM
176fe5af 584 image.Destroy();
279ababf 585
51b07644 586 if ( !image.LoadFile( dir + _T("horse.pnm"), wxBITMAP_TYPE_PNM ) )
4693b20c 587 wxLogError(wxT("Can't load PNM image"));
60a41aee 588 else
bd981f27 589 my_horse_pnm = wxBitmap( image );
3e8711ce
JS
590
591 image.Destroy();
592
593 if ( !image.LoadFile( dir + _T("horse_ag.pnm"), wxBITMAP_TYPE_PNM ) )
594 wxLogError(wxT("Can't load PNM image"));
595 else
bd981f27 596 my_horse_asciigrey_pnm = wxBitmap( image );
3e8711ce
JS
597
598 image.Destroy();
599
600 if ( !image.LoadFile( dir + _T("horse_rg.pnm"), wxBITMAP_TYPE_PNM ) )
601 wxLogError(wxT("Can't load PNM image"));
602 else
bd981f27 603 my_horse_rawgrey_pnm = wxBitmap( image );
6e47faf1 604#endif
f048e32f 605
60a41aee 606#if wxUSE_LIBTIFF
176fe5af 607 image.Destroy();
279ababf 608
51b07644 609 if ( !image.LoadFile( dir + _T("horse.tif"), wxBITMAP_TYPE_TIF ) )
4693b20c 610 wxLogError(wxT("Can't load TIFF image"));
60a41aee 611 else
bd981f27 612 my_horse_tiff = wxBitmap( image );
60a41aee
RR
613#endif
614
60a41aee 615 CreateAntiAliasedBitmap();
dc1dbfc6 616
bd981f27 617 my_smile_xbm = wxBitmap( (const char*)smile_bits, smile_width,
dc1dbfc6 618 smile_height, 1 );
bfef20bf
GRG
619
620 // demonstrates XPM automatically using the mask when saving
621 if ( m_bmpSmileXpm.Ok() )
51b07644 622 m_bmpSmileXpm.SaveFile(_T("saved.xpm"), wxBITMAP_TYPE_XPM);
bf504f98
VS
623
624#if wxUSE_ICO_CUR
625 image.Destroy();
626
51b07644 627 if ( !image.LoadFile( dir + _T("horse.ico"), wxBITMAP_TYPE_ICO, 0 ) )
bf504f98
VS
628 wxLogError(wxT("Can't load first ICO image"));
629 else
bd981f27 630 my_horse_ico32 = wxBitmap( image );
51b07644 631
bf504f98
VS
632 image.Destroy();
633
51b07644 634 if ( !image.LoadFile( dir + _T("horse.ico"), wxBITMAP_TYPE_ICO, 1 ) )
bf504f98
VS
635 wxLogError(wxT("Can't load second ICO image"));
636 else
bd981f27 637 my_horse_ico16 = wxBitmap( image );
bf504f98
VS
638
639 image.Destroy();
640
51b07644 641 if ( !image.LoadFile( dir + _T("horse.ico") ) )
bf504f98
VS
642 wxLogError(wxT("Can't load best ICO image"));
643 else
bd981f27 644 my_horse_ico = wxBitmap( image );
bf504f98
VS
645
646 image.Destroy();
647
51b07644 648 if ( !image.LoadFile( dir + _T("horse.cur"), wxBITMAP_TYPE_CUR ) )
bf504f98
VS
649 wxLogError(wxT("Can't load best ICO image"));
650 else
51b07644 651 {
bd981f27 652 my_horse_cur = wxBitmap( image );
fd94e8aa
VS
653 xH = 30 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X) ;
654 yH = 2420 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ;
51b07644 655 }
2b5f62a0 656
08811762 657 m_ani_images = wxImage::GetImageCount ( dir + _T("horse3.ani"), wxBITMAP_TYPE_ANI );
2b5f62a0
VZ
658 if (m_ani_images==0)
659 wxLogError(wxT("No ANI-format images found"));
660 else
661 my_horse_ani = new wxBitmap [m_ani_images];
662 int i ;
663 for (i=0; i < m_ani_images; i++)
664 {
665 image.Destroy();
08811762 666 if (!image.LoadFile( dir + _T("horse3.ani"), wxBITMAP_TYPE_ANI, i ))
2b5f62a0
VZ
667 {
668 wxString tmp = wxT("Can't load image number ");
669 tmp << i ;
670 wxLogError(tmp);
671 }
925e9792 672 else
2b5f62a0
VZ
673 my_horse_ani [i] = wxBitmap( image );
674 }
da9df1f5 675#endif // wxUSE_ICO_CUR
bf504f98 676
51b07644
VZ
677 image.Destroy();
678
679 // test image loading from stream
680 wxFile file(dir + _T("horse.bmp"));
30ad0a14 681 if ( file.IsOpened() )
51b07644 682 {
9386cb75
WS
683 wxFileOffset len = file.Length();
684 size_t dataSize = (size_t)len;
685 void *data = malloc(dataSize);
686 if ( file.Read(data, dataSize) != len )
30ad0a14 687 wxLogError(_T("Reading bitmap file failed"));
51b07644 688 else
30ad0a14 689 {
9386cb75 690 wxMemoryInputStream mis(data, dataSize);
30ad0a14
VZ
691 if ( !image.LoadFile(mis) )
692 wxLogError(wxT("Can't load BMP image from stream"));
693 else
bd981f27 694 my_horse_bmp2 = wxBitmap( image );
30ad0a14 695 }
51b07644 696
30ad0a14
VZ
697 free(data);
698 }
01111366
RR
699}
700
1d5b7a0b 701MyCanvas::~MyCanvas()
01111366 702{
2b5f62a0 703 delete [] my_horse_ani;
01111366
RR
704}
705
706void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
707{
be25e480
RR
708 wxPaintDC dc( this );
709 PrepareDC( dc );
a91b47e8 710
51b07644 711 dc.DrawText( _T("Loaded image"), 30, 10 );
bd981f27
VZ
712 if (my_square.Ok())
713 dc.DrawBitmap( my_square, 30, 30 );
f048e32f 714
51b07644 715 dc.DrawText( _T("Drawn directly"), 150, 10 );
a60b1f5d 716 dc.SetBrush( wxBrush( wxT("orange"), wxSOLID ) );
cf3da716 717 dc.SetPen( *wxBLACK_PEN );
be25e480 718 dc.DrawRectangle( 150, 30, 100, 100 );
cf3da716
RR
719 dc.SetBrush( *wxWHITE_BRUSH );
720 dc.DrawRectangle( 170, 50, 60, 60 );
be25e480 721
bd981f27
VZ
722 if (my_anti.Ok())
723 dc.DrawBitmap( my_anti, 280, 30 );
be25e480 724
51b07644 725 dc.DrawText( _T("PNG handler"), 30, 135 );
bd981f27 726 if (my_horse_png.Ok())
408b4168 727 {
bd981f27 728 dc.DrawBitmap( my_horse_png, 30, 150 );
be25e480 729 wxRect rect(0,0,100,100);
bd981f27 730 wxBitmap sub( my_horse_png.GetSubBitmap(rect) );
66df4ec6
VZ
731 dc.DrawText( _T("GetSubBitmap()"), 280, 175 );
732 dc.DrawBitmap( sub, 280, 195 );
be25e480
RR
733 }
734
51b07644 735 dc.DrawText( _T("JPEG handler"), 30, 365 );
bd981f27
VZ
736 if (my_horse_jpeg.Ok())
737 dc.DrawBitmap( my_horse_jpeg, 30, 380 );
be25e480 738
234fedd2
VZ
739 dc.DrawText( _T("Green rotated to red"), 280, 365 );
740 if (colorized_horse_jpeg.Ok())
741 dc.DrawBitmap( colorized_horse_jpeg, 280, 380 );
742
743 dc.DrawText( _T("CMYK JPEG image"), 530, 365 );
744 if (my_cmyk_jpeg.Ok())
745 dc.DrawBitmap( my_cmyk_jpeg, 530, 380 );
746
51b07644 747 dc.DrawText( _T("GIF handler"), 30, 595 );
bd981f27
VZ
748 if (my_horse_gif.Ok())
749 dc.DrawBitmap( my_horse_gif, 30, 610 );
be25e480 750
51b07644 751 dc.DrawText( _T("PCX handler"), 30, 825 );
bd981f27
VZ
752 if (my_horse_pcx.Ok())
753 dc.DrawBitmap( my_horse_pcx, 30, 840 );
be25e480 754
51b07644 755 dc.DrawText( _T("BMP handler"), 30, 1055 );
bd981f27
VZ
756 if (my_horse_bmp.Ok())
757 dc.DrawBitmap( my_horse_bmp, 30, 1070 );
be25e480 758
51b07644 759 dc.DrawText( _T("BMP read from memory"), 280, 1055 );
bd981f27
VZ
760 if (my_horse_bmp2.Ok())
761 dc.DrawBitmap( my_horse_bmp2, 280, 1070 );
51b07644
VZ
762
763 dc.DrawText( _T("PNM handler"), 30, 1285 );
bd981f27
VZ
764 if (my_horse_pnm.Ok())
765 dc.DrawBitmap( my_horse_pnm, 30, 1300 );
d0ee33f5 766
3e8711ce 767 dc.DrawText( _T("PNM handler (ascii grey)"), 280, 1285 );
bd981f27
VZ
768 if (my_horse_asciigrey_pnm.Ok())
769 dc.DrawBitmap( my_horse_asciigrey_pnm, 280, 1300 );
3e8711ce
JS
770
771 dc.DrawText( _T("PNM handler (raw grey)"), 530, 1285 );
bd981f27
VZ
772 if (my_horse_rawgrey_pnm.Ok())
773 dc.DrawBitmap( my_horse_rawgrey_pnm, 530, 1300 );
408b4168 774
51b07644 775 dc.DrawText( _T("TIFF handler"), 30, 1515 );
bd981f27
VZ
776 if (my_horse_tiff.Ok())
777 dc.DrawBitmap( my_horse_tiff, 30, 1530 );
be25e480 778
51b07644 779 dc.DrawText( _T("XPM handler"), 30, 1745 );
bd981f27
VZ
780 if (my_horse_xpm.Ok())
781 dc.DrawBitmap( my_horse_xpm, 30, 1760 );
9d8bdf2d 782
234fedd2 783 // toucans
66df4ec6 784 {
234fedd2 785 int x = 750, y = 10, yy = 170;
66df4ec6
VZ
786
787 dc.DrawText(wxT("Original toucan"), x+50, y);
59b7a280 788 dc.DrawBitmap(my_toucan, x, y+15, true);
66df4ec6
VZ
789 y += yy;
790 dc.DrawText(wxT("Flipped horizontally"), x+50, y);
59b7a280 791 dc.DrawBitmap(my_toucan_flipped_horiz, x, y+15, true);
66df4ec6
VZ
792 y += yy;
793 dc.DrawText(wxT("Flipped vertically"), x+50, y);
59b7a280 794 dc.DrawBitmap(my_toucan_flipped_vert, x, y+15, true);
66df4ec6
VZ
795 y += yy;
796 dc.DrawText(wxT("Flipped both h&v"), x+50, y);
59b7a280 797 dc.DrawBitmap(my_toucan_flipped_both, x, y+15, true);
66df4ec6 798
9061c15c
WS
799 y += yy;
800 dc.DrawText(wxT("In greyscale"), x+50, y);
59b7a280 801 dc.DrawBitmap(my_toucan_grey, x, y+15, true);
9061c15c 802
66df4ec6
VZ
803 y += yy;
804 dc.DrawText(wxT("Toucan's head"), x+50, y);
59b7a280 805 dc.DrawBitmap(my_toucan_head, x, y+15, true);
66df4ec6 806 }
bf504f98 807
bd981f27 808 if (my_smile_xbm.Ok())
be25e480 809 {
51b07644
VZ
810 dc.DrawText( _T("XBM bitmap"), 30, 1975 );
811 dc.DrawText( _T("(green on red)"), 30, 1990 );
812 dc.SetTextForeground( _T("GREEN") );
813 dc.SetTextBackground( _T("RED") );
bd981f27 814 dc.DrawBitmap( my_smile_xbm, 30, 2010 );
408b4168 815
19bc1514 816 dc.SetTextForeground( *wxBLACK );
51b07644
VZ
817 dc.DrawText( _T("After wxImage conversion"), 150, 1975 );
818 dc.DrawText( _T("(red on white)"), 150, 1990 );
a60b1f5d 819 dc.SetTextForeground( wxT("RED") );
bd981f27 820 wxImage i = my_smile_xbm.ConvertToImage();
176fe5af
GRG
821 i.SetMaskColour( 255, 255, 255 );
822 i.Replace( 0, 0, 0,
be25e480
RR
823 wxRED_PEN->GetColour().Red(),
824 wxRED_PEN->GetColour().Green(),
825 wxRED_PEN->GetColour().Blue() );
47f797bd 826 dc.DrawBitmap( wxBitmap(i), 150, 2010, true );
19bc1514 827 dc.SetTextForeground( *wxBLACK );
be25e480 828 }
176fe5af 829
408b4168 830
41fbc841 831 wxBitmap mono( 60,50,1 );
82ea63e6
RR
832 wxMemoryDC memdc;
833 memdc.SelectObject( mono );
bfef20bf 834 memdc.SetPen( *wxBLACK_PEN );
82ea63e6 835 memdc.SetBrush( *wxWHITE_BRUSH );
41fbc841
RR
836 memdc.DrawRectangle( 0,0,60,50 );
837 memdc.SetTextForeground( *wxBLACK );
9fe7d430
RR
838#ifndef __WXGTK20__
839 // I cannot convince GTK2 to draw into mono bitmaps
51b07644 840 memdc.DrawText( _T("Hi!"), 5, 5 );
9fe7d430 841#endif
41fbc841
RR
842 memdc.SetBrush( *wxBLACK_BRUSH );
843 memdc.DrawRectangle( 33,5,20,20 );
844 memdc.SetPen( *wxRED_PEN );
845 memdc.DrawLine( 5, 42, 50, 42 );
82ea63e6 846 memdc.SelectObject( wxNullBitmap );
176fe5af 847
408b4168 848 if (mono.Ok())
82ea63e6 849 {
51b07644
VZ
850 dc.DrawText( _T("Mono bitmap"), 30, 2095 );
851 dc.DrawText( _T("(red on green)"), 30, 2110 );
a60b1f5d
MB
852 dc.SetTextForeground( wxT("RED") );
853 dc.SetTextBackground( wxT("GREEN") );
9d8bdf2d 854 dc.DrawBitmap( mono, 30, 2130 );
408b4168 855
19bc1514 856 dc.SetTextForeground( *wxBLACK );
51b07644
VZ
857 dc.DrawText( _T("After wxImage conversion"), 150, 2095 );
858 dc.DrawText( _T("(red on white)"), 150, 2110 );
a60b1f5d 859 dc.SetTextForeground( wxT("RED") );
a8d4e3ac 860 wxImage i = mono.ConvertToImage();
408b4168
VZ
861 i.SetMaskColour( 255,255,255 );
862 i.Replace( 0,0,0,
82ea63e6
RR
863 wxRED_PEN->GetColour().Red(),
864 wxRED_PEN->GetColour().Green(),
865 wxRED_PEN->GetColour().Blue() );
47f797bd 866 dc.DrawBitmap( wxBitmap(i), 150, 2130, true );
19bc1514 867 dc.SetTextForeground( *wxBLACK );
bea56879
VZ
868 }
869
f9ebac93
RR
870 // For testing transparency
871 dc.SetBrush( *wxRED_BRUSH );
872 dc.DrawRectangle( 20, 2220, 560, 68 );
925e9792 873
f9ebac93 874 dc.DrawText(_T("XPM bitmap"), 30, 2230 );
bea56879 875 if ( m_bmpSmileXpm.Ok() )
47f797bd 876 dc.DrawBitmap(m_bmpSmileXpm, 30, 2250, true);
bea56879 877
f9ebac93 878 dc.DrawText(_T("XPM icon"), 110, 2230 );
bea56879 879 if ( m_iconSmileXpm.Ok() )
f9ebac93 880 dc.DrawIcon(m_iconSmileXpm, 110, 2250);
925e9792
WS
881
882 // testing icon -> bitmap conversion
f9ebac93 883 wxBitmap to_blit( m_iconSmileXpm );
3ef37e7f
JS
884 if (to_blit.Ok())
885 {
886 dc.DrawText( _T("SubBitmap"), 170, 2230 );
887 wxBitmap sub = to_blit.GetSubBitmap( wxRect(0,0,15,15) );
888 if (sub.Ok())
47f797bd 889 dc.DrawBitmap( sub, 170, 2250, true );
3ef37e7f
JS
890
891 dc.DrawText( _T("Enlarged"), 250, 2230 );
892 dc.SetUserScale( 1.5, 1.5 );
47f797bd 893 dc.DrawBitmap( to_blit, (int)(250/1.5), (int)(2250/1.5), true );
3ef37e7f 894 dc.SetUserScale( 2, 2 );
47f797bd 895 dc.DrawBitmap( to_blit, (int)(300/2), (int)(2250/2), true );
3ef37e7f 896 dc.SetUserScale( 1.0, 1.0 );
925e9792 897
3ef37e7f
JS
898 dc.DrawText( _T("Blit"), 400, 2230);
899 wxMemoryDC blit_dc;
900 blit_dc.SelectObject( to_blit );
47f797bd 901 dc.Blit( 400, 2250, to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
3ef37e7f 902 dc.SetUserScale( 1.5, 1.5 );
47f797bd 903 dc.Blit( (int)(450/1.5), (int)(2250/1.5), to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
3ef37e7f 904 dc.SetUserScale( 2, 2 );
47f797bd 905 dc.Blit( (int)(500/2), (int)(2250/2), to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
3ef37e7f
JS
906 dc.SetUserScale( 1.0, 1.0 );
907 }
bf504f98 908
51b07644 909 dc.DrawText( _T("ICO handler (1st image)"), 30, 2290 );
bd981f27
VZ
910 if (my_horse_ico32.Ok())
911 dc.DrawBitmap( my_horse_ico32, 30, 2330, true );
bf504f98 912
51b07644 913 dc.DrawText( _T("ICO handler (2nd image)"), 230, 2290 );
bd981f27
VZ
914 if (my_horse_ico16.Ok())
915 dc.DrawBitmap( my_horse_ico16, 230, 2330, true );
51b07644
VZ
916
917 dc.DrawText( _T("ICO handler (best image)"), 430, 2290 );
bd981f27
VZ
918 if (my_horse_ico.Ok())
919 dc.DrawBitmap( my_horse_ico, 430, 2330, true );
bf504f98 920
51b07644 921 dc.DrawText( _T("CUR handler"), 30, 2390 );
bd981f27 922 if (my_horse_cur.Ok())
51b07644 923 {
bd981f27 924 dc.DrawBitmap( my_horse_cur, 30, 2420, true );
bf504f98
VS
925 dc.SetPen (*wxRED_PEN);
926 dc.DrawLine (xH-10,yH,xH+10,yH);
927 dc.DrawLine (xH,yH-10,xH,yH+10);
51b07644 928 }
bd981f27 929
2b5f62a0 930 dc.DrawText( _T("ANI handler"), 230, 2390 );
bd981f27
VZ
931 for ( int i=0; i < m_ani_images; i++ )
932 {
2b5f62a0
VZ
933 if (my_horse_ani[i].Ok())
934 {
47f797bd 935 dc.DrawBitmap( my_horse_ani[i], 230 + i * 2 * my_horse_ani[i].GetWidth() , 2420, true );
2b5f62a0 936 }
bd981f27 937 }
9390a202 938}
1d5b7a0b 939
9390a202
RR
940void MyCanvas::CreateAntiAliasedBitmap()
941{
942 wxBitmap bitmap( 300, 300 );
a91b47e8 943
9390a202 944 wxMemoryDC dc;
a91b47e8 945
9390a202 946 dc.SelectObject( bitmap );
a91b47e8 947
9390a202 948 dc.Clear();
f048e32f 949
6e47faf1 950 dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL) );
a60b1f5d 951 dc.SetTextForeground( wxT("RED") );
66df4ec6
VZ
952 dc.DrawText( _T("This is anti-aliased Text."), 20, 5 );
953 dc.DrawText( _T("And a Rectangle."), 20, 45 );
f048e32f 954
9390a202 955 dc.SetBrush( *wxRED_BRUSH );
91b8de8d 956 dc.SetPen( *wxTRANSPARENT_PEN );
66df4ec6 957 dc.DrawRoundedRectangle( 20, 85, 200, 180, 20 );
f048e32f 958
a8d4e3ac 959 wxImage original= bitmap.ConvertToImage();
9390a202 960 wxImage anti( 150, 150 );
a91b47e8 961
9390a202 962 /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */
f048e32f 963
9390a202
RR
964 for (int y = 1; y < 149; y++)
965 for (int x = 1; x < 149; x++)
966 {
967 int red = original.GetRed( x*2, y*2 ) +
f048e32f
VZ
968 original.GetRed( x*2-1, y*2 ) +
969 original.GetRed( x*2, y*2+1 ) +
9390a202 970 original.GetRed( x*2+1, y*2+1 );
f048e32f
VZ
971 red = red/4;
972
9390a202 973 int green = original.GetGreen( x*2, y*2 ) +
f048e32f
VZ
974 original.GetGreen( x*2-1, y*2 ) +
975 original.GetGreen( x*2, y*2+1 ) +
9390a202 976 original.GetGreen( x*2+1, y*2+1 );
f048e32f
VZ
977 green = green/4;
978
9390a202 979 int blue = original.GetBlue( x*2, y*2 ) +
f048e32f
VZ
980 original.GetBlue( x*2-1, y*2 ) +
981 original.GetBlue( x*2, y*2+1 ) +
9390a202 982 original.GetBlue( x*2+1, y*2+1 );
f048e32f 983 blue = blue/4;
925e9792 984 anti.SetRGB( x, y, (unsigned char)red, (unsigned char)green, (unsigned char)blue );
9390a202 985 }
bd981f27 986 my_anti = wxBitmap(anti);
01111366
RR
987}
988
989// MyFrame
990
b3f04dc2
VZ
991enum
992{
91b07357
JS
993 ID_QUIT = wxID_EXIT,
994 ID_ABOUT = wxID_ABOUT,
995 ID_NEW = 100,
996 ID_SHOWRAW = 101
b3f04dc2 997};
01111366
RR
998
999IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
1000
1001BEGIN_EVENT_TABLE(MyFrame,wxFrame)
1002 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
1003 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
ab0f0386 1004 EVT_MENU (ID_NEW, MyFrame::OnNewFrame)
b3f04dc2
VZ
1005#ifdef wxHAVE_RAW_BITMAP
1006 EVT_MENU (ID_SHOWRAW, MyFrame::OnTestRawBitmap)
1007#endif
da9df1f5 1008
dd38c875 1009#if wxUSE_CLIPBOARD
da9df1f5
VZ
1010 EVT_MENU(wxID_COPY, MyFrame::OnCopy)
1011 EVT_MENU(wxID_PASTE, MyFrame::OnPaste)
1012#endif // wxUSE_CLIPBOARD
01111366
RR
1013END_EVENT_TABLE()
1014
1d5b7a0b 1015MyFrame::MyFrame()
47f797bd 1016 : wxFrame( (wxFrame *)NULL, wxID_ANY, _T("wxImage sample"),
234fedd2 1017 wxPoint(20, 20), wxSize(950, 700) )
01111366 1018{
da9df1f5
VZ
1019 wxMenuBar *menu_bar = new wxMenuBar();
1020
1021 wxMenu *menuImage = new wxMenu;
1022 menuImage->Append( ID_NEW, _T("&Show any image...\tCtrl-O"));
1e3c12d7 1023
b3f04dc2 1024#ifdef wxHAVE_RAW_BITMAP
da9df1f5 1025 menuImage->Append( ID_SHOWRAW, _T("Test &raw bitmap...\tCtrl-R"));
b3f04dc2 1026#endif
da9df1f5
VZ
1027 menuImage->AppendSeparator();
1028 menuImage->Append( ID_ABOUT, _T("&About..."));
1029 menuImage->AppendSeparator();
1030 menuImage->Append( ID_QUIT, _T("E&xit\tCtrl-Q"));
1031 menu_bar->Append(menuImage, _T("&Image"));
1032
dd38c875 1033#if wxUSE_CLIPBOARD
da9df1f5
VZ
1034 wxMenu *menuClipboard = new wxMenu;
1035 menuClipboard->Append(wxID_COPY, _T("&Copy test image\tCtrl-C"));
1036 menuClipboard->Append(wxID_PASTE, _T("&Paste image\tCtrl-V"));
1037 menu_bar->Append(menuClipboard, _T("&Clipboard"));
1038#endif // wxUSE_CLIPBOARD
3d05544e 1039
01111366 1040 SetMenuBar( menu_bar );
1d5b7a0b 1041
8520f137 1042#if wxUSE_STATUSBAR
917e533b
RR
1043 CreateStatusBar(2);
1044 int widths[] = { -1, 100 };
1045 SetStatusWidths( 2, widths );
8520f137 1046#endif // wxUSE_STATUSBAR
1d5b7a0b 1047
47f797bd 1048 m_canvas = new MyCanvas( this, wxID_ANY, wxPoint(0,0), wxSize(10,10) );
cbd4be25 1049
978d3d36
VZ
1050 // 500 width * 2750 height
1051 m_canvas->SetScrollbars( 10, 10, 50, 275 );
01111366
RR
1052}
1053
1054void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
1055{
47f797bd 1056 Close( true );
01111366
RR
1057}
1058
1059void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
1060{
51b07644
VZ
1061 (void)wxMessageBox( _T("wxImage demo\n")
1062 _T("Robert Roebling (c) 1998,2000"),
1063 _T("About wxImage Demo"), wxICON_INFORMATION | wxOK );
fb1585ae
RR
1064}
1065
ab0f0386
VZ
1066void MyFrame::OnNewFrame( wxCommandEvent &WXUNUSED(event) )
1067{
71307412 1068#if wxUSE_FILEDLG
f6bcfd97
BP
1069 wxString filename = wxFileSelector(_T("Select image file"));
1070 if ( !filename )
1071 return;
1072
1073 wxImage image;
1074 if ( !image.LoadFile(filename) )
1075 {
1076 wxLogError(_T("Couldn't load image from '%s'."), filename.c_str());
1077
1078 return;
1079 }
1080
368d59f0 1081 (new MyImageFrame(this, wxBitmap(image)))->Show();
71307412 1082#endif // wxUSE_FILEDLG
ab0f0386
VZ
1083}
1084
b3f04dc2
VZ
1085#ifdef wxHAVE_RAW_BITMAP
1086
481721e8 1087void MyFrame::OnTestRawBitmap( wxCommandEvent &WXUNUSED(event) )
b3f04dc2
VZ
1088{
1089 (new MyRawBitmapFrame(this))->Show();
1090}
1091
1092#endif // wxHAVE_RAW_BITMAP
1093
dd38c875 1094#if wxUSE_CLIPBOARD
da9df1f5
VZ
1095
1096void MyFrame::OnCopy(wxCommandEvent& WXUNUSED(event))
1097{
1098 wxBitmapDataObject *dobjBmp = new wxBitmapDataObject;
bd981f27 1099 dobjBmp->SetBitmap(m_canvas->my_horse_png);
da9df1f5 1100
dd38c875
MB
1101 wxTheClipboard->Open();
1102
da9df1f5
VZ
1103 if ( !wxTheClipboard->SetData(dobjBmp) )
1104 {
1105 wxLogError(_T("Failed to copy bitmap to clipboard"));
1106 }
dd38c875
MB
1107
1108 wxTheClipboard->Close();
da9df1f5
VZ
1109}
1110
1111void MyFrame::OnPaste(wxCommandEvent& WXUNUSED(event))
1112{
1113 wxBitmapDataObject dobjBmp;
dd38c875
MB
1114
1115 wxTheClipboard->Open();
da9df1f5
VZ
1116 if ( !wxTheClipboard->GetData(dobjBmp) )
1117 {
1118 wxLogMessage(_T("No bitmap data in the clipboard"));
1119 }
1120 else
1121 {
1122 (new MyImageFrame(this, dobjBmp.GetBitmap()))->Show();
1123 }
dd38c875 1124 wxTheClipboard->Close();
da9df1f5
VZ
1125}
1126
1127#endif // wxUSE_CLIPBOARD
1128
01111366
RR
1129//-----------------------------------------------------------------------------
1130// MyApp
1131//-----------------------------------------------------------------------------
1132
1d5b7a0b 1133bool MyApp::OnInit()
01111366 1134{
e9c4b1a2
JS
1135#if wxUSE_LIBPNG
1136 wxImage::AddHandler( new wxPNGHandler );
1137#endif
1138
1139#if wxUSE_LIBJPEG
1140 wxImage::AddHandler( new wxJPEGHandler );
1141#endif
1142
60a41aee
RR
1143#if wxUSE_LIBTIFF
1144 wxImage::AddHandler( new wxTIFFHandler );
1145#endif
1146
6e47faf1 1147#if wxUSE_GIF
e1929140 1148 wxImage::AddHandler( new wxGIFHandler );
6e47faf1
JS
1149#endif
1150
1151#if wxUSE_PCX
cbd4be25 1152 wxImage::AddHandler( new wxPCXHandler );
6e47faf1
JS
1153#endif
1154
1155#if wxUSE_PNM
6319afe3 1156 wxImage::AddHandler( new wxPNMHandler );
6e47faf1 1157#endif
e1929140 1158
a8d4e3ac
VS
1159#if wxUSE_XPM
1160 wxImage::AddHandler( new wxXPMHandler );
1161#endif
1162
bf504f98
VS
1163#if wxUSE_ICO_CUR
1164 wxImage::AddHandler( new wxICOHandler );
1165 wxImage::AddHandler( new wxCURHandler );
2b5f62a0 1166 wxImage::AddHandler( new wxANIHandler );
bf504f98
VS
1167#endif
1168
01111366 1169 wxFrame *frame = new MyFrame();
47f797bd 1170 frame->Show( true );
1d5b7a0b 1171
47f797bd 1172 return true;
01111366 1173}