1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: samples/image/image.cpp
3 // Purpose: sample showing operations with wxImage
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi
8 // Copyright: (c) 1998-2005 Robert Roebling
9 // (c) 2005-2009 Vadim Zeitlin
10 // Licence: wxWindows licence
11 ///////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
26 #include "wx/filename.h"
27 #include "wx/mstream.h"
28 #include "wx/wfstream.h"
29 #include "wx/quantize.h"
30 #include "wx/stopwatch.h"
31 #include "wx/versioninfo.h"
34 #include "wx/dataobj.h"
35 #include "wx/clipbrd.h"
36 #endif // wxUSE_CLIPBOARD
38 #if defined(__WXMSW__)
39 #ifdef wxHAVE_RAW_BITMAP
40 #include "wx/rawbmp.h"
44 #if defined(__WXMAC__) || defined(__WXGTK__)
45 #define wxHAVE_RAW_BITMAP
46 #include "wx/rawbmp.h"
52 #include "../sample.xpm"
55 // ============================================================================
57 // ============================================================================
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 class MyApp
: public wxApp
66 virtual bool OnInit();
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 class MyFrame
: public wxFrame
78 void OnAbout( wxCommandEvent
&event
);
79 void OnNewFrame( wxCommandEvent
&event
);
80 void OnImageInfo( wxCommandEvent
&event
);
81 void OnThumbnail( wxCommandEvent
&event
);
83 #ifdef wxHAVE_RAW_BITMAP
84 void OnTestRawBitmap( wxCommandEvent
&event
);
85 #endif // wxHAVE_RAW_BITMAP
86 void OnQuit( wxCommandEvent
&event
);
89 void OnCopy(wxCommandEvent
& event
);
90 void OnPaste(wxCommandEvent
& event
);
91 #endif // wxUSE_CLIPBOARD
96 // ask user for the file name and try to load an image from it
98 // return the file path on success, empty string if we failed to load the
99 // image or were cancelled by user
100 static wxString
LoadUserImage(wxImage
& image
);
103 DECLARE_DYNAMIC_CLASS(MyFrame
)
104 DECLARE_EVENT_TABLE()
107 // ----------------------------------------------------------------------------
108 // Frame used for showing a standalone image
109 // ----------------------------------------------------------------------------
113 ID_ROTATE_LEFT
= wxID_HIGHEST
+1,
119 class MyImageFrame
: public wxFrame
122 MyImageFrame(wxFrame
*parent
, const wxString
& desc
, const wxImage
& image
)
124 Create(parent
, desc
, wxBitmap(image
), image
.GetImageCount(desc
));
127 MyImageFrame(wxFrame
*parent
, const wxString
& desc
, const wxBitmap
& bitmap
)
129 Create(parent
, desc
, bitmap
);
133 bool Create(wxFrame
*parent
,
134 const wxString
& desc
,
135 const wxBitmap
& bitmap
,
138 if ( !wxFrame::Create(parent
, wxID_ANY
,
139 wxString::Format(wxT("Image from %s"), desc
),
140 wxDefaultPosition
, wxDefaultSize
,
141 wxDEFAULT_FRAME_STYLE
| wxFULL_REPAINT_ON_RESIZE
) )
147 wxMenu
*menu
= new wxMenu
;
148 menu
->Append(wxID_SAVE
);
149 menu
->AppendSeparator();
150 menu
->AppendCheckItem(ID_PAINT_BG
, wxT("&Paint background"),
151 "Uncheck this for transparent images");
152 menu
->AppendSeparator();
153 menu
->Append(ID_RESIZE
, wxT("&Fit to window\tCtrl-F"));
154 menu
->Append(wxID_ZOOM_IN
, "Zoom &in\tCtrl-+");
155 menu
->Append(wxID_ZOOM_OUT
, "Zoom &out\tCtrl--");
156 menu
->Append(wxID_ZOOM_100
, "Reset zoom to &100%\tCtrl-1");
157 menu
->AppendSeparator();
158 menu
->Append(ID_ROTATE_LEFT
, wxT("Rotate &left\tCtrl-L"));
159 menu
->Append(ID_ROTATE_RIGHT
, wxT("Rotate &right\tCtrl-R"));
161 wxMenuBar
*mbar
= new wxMenuBar
;
162 mbar
->Append(menu
, wxT("&Image"));
165 mbar
->Check(ID_PAINT_BG
, true);
168 if ( numImages
!= 1 )
169 SetStatusText(wxString::Format("%d images", numImages
), 1);
171 SetClientSize(bitmap
.GetWidth(), bitmap
.GetHeight());
180 void OnEraseBackground(wxEraseEvent
& WXUNUSED(event
))
182 // do nothing here to be able to see how transparent images are shown
185 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
189 if ( GetMenuBar()->IsChecked(ID_PAINT_BG
) )
192 dc
.SetUserScale(m_zoom
, m_zoom
);
194 const wxSize size
= GetClientSize();
198 dc
.DeviceToLogicalX((size
.x
- m_zoom
*m_bitmap
.GetWidth())/2),
199 dc
.DeviceToLogicalY((size
.y
- m_zoom
*m_bitmap
.GetHeight())/2),
204 void OnSave(wxCommandEvent
& WXUNUSED(event
))
207 wxImage image
= m_bitmap
.ConvertToImage();
209 wxString savefilename
= wxFileSelector( wxT("Save Image"),
212 (const wxChar
*)NULL
,
213 wxT("BMP files (*.bmp)|*.bmp|")
215 wxT("PNG files (*.png)|*.png|")
218 wxT("JPEG files (*.jpg)|*.jpg|")
221 wxT("GIF files (*.gif)|*.gif|")
224 wxT("TIFF files (*.tif)|*.tif|")
227 wxT("PCX files (*.pcx)|*.pcx|")
229 wxT("ICO files (*.ico)|*.ico|")
230 wxT("CUR files (*.cur)|*.cur"),
234 if ( savefilename
.empty() )
238 wxFileName::SplitPath(savefilename
, NULL
, NULL
, &extension
);
241 if ( extension
== wxT("bmp") )
243 static const int bppvalues
[] =
255 const wxString bppchoices
[] =
261 wxT("8 bpp greyscale"),
263 wxT("8 bpp own palette"),
267 int bppselection
= wxGetSingleChoiceIndex(wxT("Set BMP BPP"),
268 wxT("Image sample: save file"),
269 WXSIZEOF(bppchoices
),
272 if ( bppselection
!= -1 )
274 int format
= bppvalues
[bppselection
];
275 image
.SetOption(wxIMAGE_OPTION_BMP_FORMAT
, format
);
277 if ( format
== wxBMP_8BPP_PALETTE
)
279 unsigned char *cmap
= new unsigned char [256];
280 for ( int i
= 0; i
< 256; i
++ )
281 cmap
[i
] = (unsigned char)i
;
282 image
.SetPalette(wxPalette(256, cmap
, cmap
, cmap
));
289 else if ( extension
== wxT("png") )
291 static const int pngvalues
[] =
301 const wxString pngchoices
[] =
307 wxT("Grey red 8bpp"),
308 wxT("Grey red 16bpp"),
311 int sel
= wxGetSingleChoiceIndex(wxT("Set PNG format"),
312 wxT("Image sample: save file"),
313 WXSIZEOF(pngchoices
),
318 image
.SetOption(wxIMAGE_OPTION_PNG_FORMAT
, pngvalues
[sel
]);
319 image
.SetOption(wxIMAGE_OPTION_PNG_BITDEPTH
, sel
% 2 ? 16 : 8);
321 // these values are taken from OptiPNG with -o3 switch
322 const wxString compressionChoices
[] =
324 wxT("compression = 9, memory = 8, strategy = 0, filter = 0"),
325 wxT("compression = 9, memory = 9, strategy = 0, filter = 0"),
326 wxT("compression = 9, memory = 8, strategy = 1, filter = 0"),
327 wxT("compression = 9, memory = 9, strategy = 1, filter = 0"),
328 wxT("compression = 1, memory = 8, strategy = 2, filter = 0"),
329 wxT("compression = 1, memory = 9, strategy = 2, filter = 0"),
330 wxT("compression = 9, memory = 8, strategy = 0, filter = 5"),
331 wxT("compression = 9, memory = 9, strategy = 0, filter = 5"),
332 wxT("compression = 9, memory = 8, strategy = 1, filter = 5"),
333 wxT("compression = 9, memory = 9, strategy = 1, filter = 5"),
334 wxT("compression = 1, memory = 8, strategy = 2, filter = 5"),
335 wxT("compression = 1, memory = 9, strategy = 2, filter = 5"),
338 int sel
= wxGetSingleChoiceIndex(wxT("Select compression option (Cancel to use default)\n"),
339 wxT("PNG Compression Options"),
340 WXSIZEOF(compressionChoices
),
345 const int zc
[] = {9, 9, 9, 9, 1, 1, 9, 9, 9, 9, 1, 1};
346 const int zm
[] = {8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9};
347 const int zs
[] = {0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2};
348 const int f
[] = {0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
349 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8};
351 image
.SetOption(wxIMAGE_OPTION_PNG_COMPRESSION_LEVEL
, zc
[sel
]);
352 image
.SetOption(wxIMAGE_OPTION_PNG_COMPRESSION_MEM_LEVEL
, zm
[sel
]);
353 image
.SetOption(wxIMAGE_OPTION_PNG_COMPRESSION_STRATEGY
, zs
[sel
]);
354 image
.SetOption(wxIMAGE_OPTION_PNG_FILTER
, f
[sel
]);
355 image
.SetOption(wxIMAGE_OPTION_PNG_COMPRESSION_BUFFER_SIZE
, 1048576); // 1 MB
359 #endif // wxUSE_LIBPNG
360 else if ( extension
== wxT("cur") )
362 image
.Rescale(32,32);
363 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
, 0);
364 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
, 0);
365 // This shows how you can save an image with explicitly
366 // specified image format:
367 saved
= image
.SaveFile(savefilename
, wxBITMAP_TYPE_CUR
);
372 // This one guesses image format from filename extension
373 // (it may fail if the extension is not recognized):
374 image
.SaveFile(savefilename
);
376 #endif // wxUSE_FILEDLG
379 void OnResize(wxCommandEvent
& WXUNUSED(event
))
381 wxImage
img(m_bitmap
.ConvertToImage());
383 const wxSize size
= GetClientSize();
384 img
.Rescale(size
.x
, size
.y
, wxIMAGE_QUALITY_HIGH
);
385 m_bitmap
= wxBitmap(img
);
390 void OnZoom(wxCommandEvent
& event
)
392 if ( event
.GetId() == wxID_ZOOM_IN
)
394 else if ( event
.GetId() == wxID_ZOOM_OUT
)
396 else // wxID_ZOOM_100
402 void OnRotate(wxCommandEvent
& event
)
405 if ( event
.GetId() == ID_ROTATE_LEFT
)
408 wxImage
img(m_bitmap
.ConvertToImage());
409 img
= img
.Rotate(angle
, wxPoint(img
.GetWidth() / 2, img
.GetHeight() / 2));
412 wxLogWarning(wxT("Rotation failed"));
416 m_bitmap
= wxBitmap(img
);
421 void UpdateStatusBar()
423 wxLogStatus(this, wxT("Image size: (%d, %d), zoom %.2f"),
425 m_bitmap
.GetHeight(),
433 DECLARE_EVENT_TABLE()
436 #ifdef wxHAVE_RAW_BITMAP
438 #include "wx/rawbmp.h"
440 class MyRawBitmapFrame
: public wxFrame
447 REAL_SIZE
= SIZE
- 2*BORDER
450 MyRawBitmapFrame(wxFrame
*parent
)
451 : wxFrame(parent
, wxID_ANY
, wxT("Raw bitmaps (how exciting)")),
452 m_bitmap(SIZE
, SIZE
, 24),
453 m_alphaBitmap(SIZE
, SIZE
, 32)
455 SetClientSize(SIZE
, SIZE
*2+25);
462 void InitAlphaBitmap()
464 // First, clear the whole bitmap by making it alpha
466 wxAlphaPixelData
data( m_alphaBitmap
, wxPoint(0,0), wxSize(SIZE
, SIZE
) );
469 wxLogError(wxT("Failed to gain raw access to bitmap data"));
472 wxAlphaPixelData::Iterator
p(data
);
473 for ( int y
= 0; y
< SIZE
; ++y
)
475 wxAlphaPixelData::Iterator rowStart
= p
;
476 for ( int x
= 0; x
< SIZE
; ++x
)
479 ++p
; // same as p.OffsetX(1)
486 // Then, draw colourful alpha-blended stripes
487 wxAlphaPixelData
data(m_alphaBitmap
, wxPoint(BORDER
, BORDER
),
488 wxSize(REAL_SIZE
, REAL_SIZE
));
491 wxLogError(wxT("Failed to gain raw access to bitmap data"));
495 wxAlphaPixelData::Iterator
p(data
);
497 for ( int y
= 0; y
< REAL_SIZE
; ++y
)
499 wxAlphaPixelData::Iterator rowStart
= p
;
501 int r
= y
< REAL_SIZE
/3 ? 255 : 0,
502 g
= (REAL_SIZE
/3 <= y
) && (y
< 2*(REAL_SIZE
/3)) ? 255 : 0,
503 b
= 2*(REAL_SIZE
/3) <= y
? 255 : 0;
505 for ( int x
= 0; x
< REAL_SIZE
; ++x
)
507 // note that RGB must be premultiplied by alpha
508 unsigned a
= (wxAlphaPixelData::Iterator::ChannelType
)((x
*255.)/REAL_SIZE
);
509 p
.Red() = r
* a
/ 256;
510 p
.Green() = g
* a
/ 256;
511 p
.Blue() = b
* a
/ 256;
514 ++p
; // same as p.OffsetX(1)
524 // draw some colourful stripes without alpha
525 wxNativePixelData
data(m_bitmap
);
528 wxLogError(wxT("Failed to gain raw access to bitmap data"));
532 wxNativePixelData::Iterator
p(data
);
533 for ( int y
= 0; y
< SIZE
; ++y
)
535 wxNativePixelData::Iterator rowStart
= p
;
537 int r
= y
< SIZE
/3 ? 255 : 0,
538 g
= (SIZE
/3 <= y
) && (y
< 2*(SIZE
/3)) ? 255 : 0,
539 b
= 2*(SIZE
/3) <= y
? 255 : 0;
541 for ( int x
= 0; x
< SIZE
; ++x
)
546 ++p
; // same as p.OffsetX(1)
554 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
556 wxPaintDC
dc( this );
557 dc
.DrawText(wxT("This is alpha and raw bitmap test"), 0, BORDER
);
558 dc
.DrawText(wxT("This is alpha and raw bitmap test"), 0, SIZE
/2 - BORDER
);
559 dc
.DrawText(wxT("This is alpha and raw bitmap test"), 0, SIZE
- 2*BORDER
);
560 dc
.DrawBitmap( m_alphaBitmap
, 0, 0, true /* use mask */ );
562 dc
.DrawText(wxT("Raw bitmap access without alpha"), 0, SIZE
+5);
563 dc
.DrawBitmap( m_bitmap
, 0, SIZE
+5+dc
.GetCharHeight());
568 wxBitmap m_alphaBitmap
;
570 DECLARE_EVENT_TABLE()
573 #endif // wxHAVE_RAW_BITMAP
576 // ============================================================================
578 // ============================================================================
580 //-----------------------------------------------------------------------------
582 //-----------------------------------------------------------------------------
584 BEGIN_EVENT_TABLE(MyImageFrame
, wxFrame
)
585 EVT_ERASE_BACKGROUND(MyImageFrame::OnEraseBackground
)
586 EVT_PAINT(MyImageFrame::OnPaint
)
588 EVT_MENU(wxID_SAVE
, MyImageFrame::OnSave
)
589 EVT_MENU_RANGE(ID_ROTATE_LEFT
, ID_ROTATE_RIGHT
, MyImageFrame::OnRotate
)
590 EVT_MENU(ID_RESIZE
, MyImageFrame::OnResize
)
592 EVT_MENU(wxID_ZOOM_IN
, MyImageFrame::OnZoom
)
593 EVT_MENU(wxID_ZOOM_OUT
, MyImageFrame::OnZoom
)
594 EVT_MENU(wxID_ZOOM_100
, MyImageFrame::OnZoom
)
597 //-----------------------------------------------------------------------------
599 //-----------------------------------------------------------------------------
601 #ifdef wxHAVE_RAW_BITMAP
603 BEGIN_EVENT_TABLE(MyRawBitmapFrame
, wxFrame
)
604 EVT_PAINT(MyRawBitmapFrame::OnPaint
)
607 #endif // wxHAVE_RAW_BITMAP
609 //-----------------------------------------------------------------------------
611 //-----------------------------------------------------------------------------
616 ID_ABOUT
= wxID_ABOUT
,
623 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
624 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
625 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
626 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
627 EVT_MENU (ID_NEW
, MyFrame::OnNewFrame
)
628 EVT_MENU (ID_INFO
, MyFrame::OnImageInfo
)
629 EVT_MENU (ID_SHOWTHUMBNAIL
, MyFrame::OnThumbnail
)
630 #ifdef wxHAVE_RAW_BITMAP
631 EVT_MENU (ID_SHOWRAW
, MyFrame::OnTestRawBitmap
)
634 EVT_MENU(wxID_COPY
, MyFrame::OnCopy
)
635 EVT_MENU(wxID_PASTE
, MyFrame::OnPaste
)
636 #endif // wxUSE_CLIPBOARD
640 : wxFrame( (wxFrame
*)NULL
, wxID_ANY
, wxT("wxImage sample"),
641 wxPoint(20, 20), wxSize(950, 700) )
643 SetIcon(wxICON(sample
));
645 wxMenuBar
*menu_bar
= new wxMenuBar();
647 wxMenu
*menuImage
= new wxMenu
;
648 menuImage
->Append( ID_NEW
, wxT("&Show any image...\tCtrl-O"));
649 menuImage
->Append( ID_INFO
, wxT("Show image &information...\tCtrl-I"));
650 #ifdef wxHAVE_RAW_BITMAP
651 menuImage
->AppendSeparator();
652 menuImage
->Append( ID_SHOWRAW
, wxT("Test &raw bitmap...\tCtrl-R"));
654 menuImage
->AppendSeparator();
655 menuImage
->Append( ID_SHOWTHUMBNAIL
, wxT("Test &thumbnail...\tCtrl-T"),
656 "Test scaling the image during load (try with JPEG)");
657 menuImage
->AppendSeparator();
658 menuImage
->Append( ID_ABOUT
, wxT("&About...\tF1"));
659 menuImage
->AppendSeparator();
660 menuImage
->Append( ID_QUIT
, wxT("E&xit\tCtrl-Q"));
661 menu_bar
->Append(menuImage
, wxT("&Image"));
664 wxMenu
*menuClipboard
= new wxMenu
;
665 menuClipboard
->Append(wxID_COPY
, wxT("&Copy test image\tCtrl-C"));
666 menuClipboard
->Append(wxID_PASTE
, wxT("&Paste image\tCtrl-V"));
667 menu_bar
->Append(menuClipboard
, wxT("&Clipboard"));
668 #endif // wxUSE_CLIPBOARD
670 SetMenuBar( menu_bar
);
674 int widths
[] = { -1, 100 };
675 SetStatusWidths( 2, widths
);
676 #endif // wxUSE_STATUSBAR
678 m_canvas
= new MyCanvas( this, wxID_ANY
, wxPoint(0,0), wxSize(10,10) );
680 // 500 width * 2750 height
681 m_canvas
->SetScrollbars( 10, 10, 50, 275 );
682 m_canvas
->SetCursor(wxImage("cursor.png"));
685 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
690 #if wxUSE_ZLIB && wxUSE_STREAMS
691 #include "wx/zstream.h"
694 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
698 array
.Add("wxImage demo");
699 array
.Add("(c) Robert Roebling 1998-2005");
700 array
.Add("(c) Vadim Zeitlin 2005-2009");
702 array
.Add(wxEmptyString
);
703 array
.Add("Version of the libraries used:");
706 array
.Add(wxPNGHandler::GetLibraryVersionInfo().ToString());
709 array
.Add(wxJPEGHandler::GetLibraryVersionInfo().ToString());
712 array
.Add(wxTIFFHandler::GetLibraryVersionInfo().ToString());
714 #if wxUSE_ZLIB && wxUSE_STREAMS
715 // zlib is used by libpng
716 array
.Add(wxGetZlibVersionInfo().ToString());
718 (void)wxMessageBox( wxJoin(array
, '\n'),
719 "About wxImage Demo",
720 wxICON_INFORMATION
| wxOK
);
723 wxString
MyFrame::LoadUserImage(wxImage
& image
)
728 filename
= wxLoadFileSelector(wxT("image"), wxEmptyString
);
729 if ( !filename
.empty() )
731 if ( !image
.LoadFile(filename
) )
733 wxLogError(wxT("Couldn't load image from '%s'."), filename
.c_str());
735 return wxEmptyString
;
738 #endif // wxUSE_FILEDLG
743 void MyFrame::OnNewFrame( wxCommandEvent
&WXUNUSED(event
) )
746 wxString filename
= LoadUserImage(image
);
747 if ( !filename
.empty() )
748 new MyImageFrame(this, filename
, image
);
751 void MyFrame::OnImageInfo( wxCommandEvent
&WXUNUSED(event
) )
754 if ( !LoadUserImage(image
).empty() )
756 // TODO: show more information about the file
757 wxString info
= wxString::Format("Image size: %dx%d",
761 int xres
= image
.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONX
),
762 yres
= image
.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONY
);
765 info
+= wxString::Format("\nResolution: %dx%d", xres
, yres
);
766 switch ( image
.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONUNIT
) )
769 wxFAIL_MSG( "unknown image resolution units" );
772 case wxIMAGE_RESOLUTION_NONE
:
773 info
+= " in default units";
776 case wxIMAGE_RESOLUTION_INCHES
:
780 case wxIMAGE_RESOLUTION_CM
:
786 wxLogMessage("%s", info
);
790 #ifdef wxHAVE_RAW_BITMAP
792 void MyFrame::OnTestRawBitmap( wxCommandEvent
&WXUNUSED(event
) )
794 (new MyRawBitmapFrame(this))->Show();
797 #endif // wxHAVE_RAW_BITMAP
801 void MyFrame::OnCopy(wxCommandEvent
& WXUNUSED(event
))
803 wxBitmapDataObject
*dobjBmp
= new wxBitmapDataObject
;
804 dobjBmp
->SetBitmap(m_canvas
->my_horse_png
);
806 wxTheClipboard
->Open();
808 if ( !wxTheClipboard
->SetData(dobjBmp
) )
810 wxLogError(wxT("Failed to copy bitmap to clipboard"));
813 wxTheClipboard
->Close();
816 void MyFrame::OnPaste(wxCommandEvent
& WXUNUSED(event
))
818 wxBitmapDataObject dobjBmp
;
820 wxTheClipboard
->Open();
821 if ( !wxTheClipboard
->GetData(dobjBmp
) )
823 wxLogMessage(wxT("No bitmap data in the clipboard"));
827 new MyImageFrame(this, wxT("Clipboard"), dobjBmp
.GetBitmap());
829 wxTheClipboard
->Close();
832 #endif // wxUSE_CLIPBOARD
834 void MyFrame::OnThumbnail( wxCommandEvent
&WXUNUSED(event
) )
837 wxString filename
= wxLoadFileSelector(wxT("image"), wxEmptyString
, wxEmptyString
, this);
838 if ( filename
.empty() )
841 static const int THUMBNAIL_WIDTH
= 320;
842 static const int THUMBNAIL_HEIGHT
= 240;
845 image
.SetOption(wxIMAGE_OPTION_MAX_WIDTH
, THUMBNAIL_WIDTH
);
846 image
.SetOption(wxIMAGE_OPTION_MAX_HEIGHT
, THUMBNAIL_HEIGHT
);
849 if ( !image
.LoadFile(filename
) )
851 wxLogError(wxT("Couldn't load image from '%s'."), filename
.c_str());
855 const long loadTime
= sw
.Time();
857 MyImageFrame
* const frame
= new MyImageFrame(this, filename
, image
);
858 wxLogStatus(frame
, "Loaded \"%s\" in %ldms", filename
, loadTime
);
860 wxLogError( wxT("Couldn't create file selector dialog") );
862 #endif // wxUSE_FILEDLG
865 //-----------------------------------------------------------------------------
867 //-----------------------------------------------------------------------------
873 if ( !wxApp::OnInit() )
876 wxInitAllImageHandlers();
878 wxFrame
*frame
= new MyFrame();