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