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