4 * Author: Robert Roebling
6 * Copyright: (C) 1998, Robert Roebling
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
23 #include "wx/mstream.h"
24 #include "wx/wfstream.h"
25 #include "wx/quantize.h"
29 #if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW
33 #define wxHAVE_RAW_BITMAP
42 class MyCanvas
: public wxScrolledWindow
46 MyCanvas( wxWindow
*parent
, wxWindowID
, const wxPoint
&pos
, const wxSize
&size
);
48 void OnPaint( wxPaintEvent
&event
);
49 void CreateAntiAliasedBitmap();
51 wxBitmap
*my_horse_png
;
52 wxBitmap
*my_horse_jpeg
;
53 wxBitmap
*my_horse_gif
;
54 wxBitmap
*my_horse_bmp
;
55 wxBitmap
*my_horse_bmp2
;
56 wxBitmap
*my_horse_pcx
;
57 wxBitmap
*my_horse_pnm
;
58 wxBitmap
*my_horse_tiff
;
59 wxBitmap
*my_horse_xpm
;
60 wxBitmap
*my_horse_ico32
;
61 wxBitmap
*my_horse_ico16
;
62 wxBitmap
*my_horse_ico
;
63 wxBitmap
*my_horse_cur
;
64 wxBitmap
*my_horse_ani
;
66 wxBitmap
*my_smile_xbm
;
74 wxBitmap m_bmpSmileXpm
;
75 wxIcon m_iconSmileXpm
;
78 DECLARE_DYNAMIC_CLASS(MyCanvas
)
83 const int nChoices
= 8 ;
84 static const wxString bppchoices
[nChoices
] =
90 _T("8 bpp greyscale"),
92 _T("8 bpp own palette"),
96 static const int bppvalues
[nChoices
] =
111 class MyFrame
: public wxFrame
116 void OnAbout( wxCommandEvent
&event
);
117 void OnNewFrame( wxCommandEvent
&event
);
118 #ifdef wxHAVE_RAW_BITMAP
119 void OnTestRawBitmap( wxCommandEvent
&event
);
120 #endif // wxHAVE_RAW_BITMAP
121 void OnQuit( wxCommandEvent
&event
);
126 DECLARE_DYNAMIC_CLASS(MyFrame
)
127 DECLARE_EVENT_TABLE()
130 class MyImageFrame
: public wxFrame
133 MyImageFrame(wxFrame
*parent
, const wxBitmap
& bitmap
)
134 : wxFrame(parent
, -1, _T("Double click to save"),
135 wxDefaultPosition
, wxDefaultSize
,
136 wxCAPTION
| wxSYSTEM_MENU
),
139 SetClientSize(bitmap
.GetWidth(), bitmap
.GetHeight());
142 void OnEraseBackground(wxEraseEvent
& WXUNUSED(event
))
144 // do nothing here to be able to see how transparent images are shown
147 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
149 wxPaintDC
dc( this );
150 dc
.DrawBitmap( m_bitmap
, 0, 0, TRUE
/* use mask */ );
153 void OnSave(wxMouseEvent
& WXUNUSED(event
))
155 wxImage image
= m_bitmap
.ConvertToImage();
157 int bppselection
= wxGetSingleChoiceIndex(_T("Set BMP BPP"),
162 if ( bppselection
== -1 )
168 image
.SetOption(wxIMAGE_OPTION_BMP_FORMAT
, bppvalues
[bppselection
]);
170 wxString deffilename
= bppchoices
[bppselection
];
171 deffilename
.Replace(wxT(" "), wxT("_"));
172 deffilename
+= wxT(".bmp");
173 wxString savefilename
= wxFileSelector( wxT("Save Image"),
176 (const wxChar
*)NULL
,
177 wxT("BMP files (*.bmp)|*.bmp|")
178 wxT("PNG files (*.png)|*.png|")
179 wxT("JPEG files (*.jpg)|*.jpg|")
180 wxT("GIF files (*.gif)|*.gif|")
181 wxT("TIFF files (*.tif)|*.tif|")
182 wxT("PCX files (*.pcx)|*.pcx|")
183 wxT("ICO files (*.ico)|*.ico|")
184 wxT("CUR files (*.cur)|*.cur"),
187 if ( savefilename
.empty() )
190 if ( image
.GetOptionInt(wxIMAGE_OPTION_BMP_FORMAT
) == wxBMP_8BPP_PALETTE
)
192 unsigned char *cmap
= new unsigned char [256];
193 for ( int i
= 0; i
< 256; i
++ )
195 image
.SetPalette(wxPalette(256, cmap
, cmap
, cmap
));
201 wxString extension
= savefilename
.AfterLast('.').Lower();
203 if (extension
== _T("cur"))
205 image
.Rescale(32,32);
206 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
, 0);
207 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
, 0);
208 // This shows how you can save an image with explicitly
209 // specified image format:
210 loaded
= image
.SaveFile(savefilename
, wxBITMAP_TYPE_CUR
);
214 // This one guesses image format from filename extension
215 // (it may fail if the extension is not recognized):
216 loaded
= image
.SaveFile(savefilename
);
220 wxMessageBox(_T("No handler for this file type."),
221 _T("File was not saved"),
222 wxOK
|wxCENTRE
, this);
228 DECLARE_EVENT_TABLE()
231 #ifdef wxHAVE_RAW_BITMAP
233 #include "wx/rawbmp.h"
235 class MyRawBitmapFrame
: public wxFrame
242 REAL_SIZE
= SIZE
- 2*BORDER
245 MyRawBitmapFrame(wxFrame
*parent
)
246 : wxFrame(parent
, -1, _T("Raw bitmaps (how exciting)")),
247 m_bitmap(SIZE
, SIZE
, 32)
249 SetClientSize(SIZE
, SIZE
);
251 wxRawBitmapData
data(m_bitmap
);
254 wxLogError(_T("Failed to gain raw access to bitmap data"));
258 wxRawBitmapIterator
p(data
);
260 p
.Offset(BORDER
, BORDER
);
262 for ( int y
= 0; y
< REAL_SIZE
; ++y
)
264 wxRawBitmapIterator rowStart
= p
;
266 int r
= y
< REAL_SIZE
/3 ?
255 : 0,
267 g
= (REAL_SIZE
/3 <= y
) && (y
< 2*(REAL_SIZE
/3)) ?
255 : 0,
268 b
= 2*(REAL_SIZE
/3) <= y ?
255 : 0;
270 for ( int x
= 0; x
< REAL_SIZE
; ++x
)
277 ++p
; // same as p.OffsetX(1)
285 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
287 wxPaintDC
dc( this );
288 dc
.DrawText(_T("This is alpha and raw bitmap test"), 0, BORDER
);
289 dc
.DrawText(_T("This is alpha and raw bitmap test"), 0, SIZE
/2 - BORDER
);
290 dc
.DrawText(_T("This is alpha and raw bitmap test"), 0, SIZE
- 2*BORDER
);
291 dc
.DrawBitmap( m_bitmap
, 0, 0, TRUE
/* use mask */ );
297 DECLARE_EVENT_TABLE()
300 #endif // wxHAVE_RAW_BITMAP
304 class MyApp
: public wxApp
307 virtual bool OnInit();
316 IMPLEMENT_DYNAMIC_CLASS(MyCanvas
, wxScrolledWindow
)
318 BEGIN_EVENT_TABLE(MyImageFrame
, wxFrame
)
319 EVT_ERASE_BACKGROUND(MyImageFrame
::OnEraseBackground
)
320 EVT_PAINT(MyImageFrame
::OnPaint
)
321 EVT_LEFT_DCLICK(MyImageFrame
::OnSave
)
324 #ifdef wxHAVE_RAW_BITMAP
326 BEGIN_EVENT_TABLE(MyRawBitmapFrame
, wxFrame
)
327 EVT_PAINT(MyRawBitmapFrame
::OnPaint
)
330 #endif // wxHAVE_RAW_BITMAP
332 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
333 EVT_PAINT(MyCanvas
::OnPaint
)
336 MyCanvas
::MyCanvas( wxWindow
*parent
, wxWindowID id
,
337 const wxPoint
&pos
, const wxSize
&size
)
338 : wxScrolledWindow( parent
, id
, pos
, size
, wxSUNKEN_BORDER
)
339 #if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW
340 , m_bmpSmileXpm((const char **) smile_xpm
)
341 , m_iconSmileXpm((const char **) smile_xpm
)
344 my_horse_png
= (wxBitmap
*) NULL
;
345 my_horse_jpeg
= (wxBitmap
*) NULL
;
346 my_horse_gif
= (wxBitmap
*) NULL
;
347 my_horse_bmp
= (wxBitmap
*) NULL
;
348 my_horse_bmp2
= (wxBitmap
*) NULL
;
349 my_horse_pcx
= (wxBitmap
*) NULL
;
350 my_horse_pnm
= (wxBitmap
*) NULL
;
351 my_horse_tiff
= (wxBitmap
*) NULL
;
352 my_horse_xpm
= (wxBitmap
*) NULL
;
353 my_horse_ico32
= (wxBitmap
*) NULL
;
354 my_horse_ico16
= (wxBitmap
*) NULL
;
355 my_horse_ico
= (wxBitmap
*) NULL
;
356 my_horse_cur
= (wxBitmap
*) NULL
;
357 my_horse_ani
= (wxBitmap
*) NULL
;
359 my_smile_xbm
= (wxBitmap
*) NULL
;
360 my_square
= (wxBitmap
*) NULL
;
361 my_anti
= (wxBitmap
*) NULL
;
365 SetBackgroundColour(* wxWHITE
);
367 wxBitmap
bitmap( 100, 100 );
370 dc
.SelectObject( bitmap
);
371 dc
.SetBrush( wxBrush( wxT("orange"), wxSOLID
) );
372 dc
.SetPen( *wxBLACK_PEN
);
373 dc
.DrawRectangle( 0, 0, 100, 100 );
374 dc
.SetBrush( *wxWHITE_BRUSH
);
375 dc
.DrawRectangle( 20, 20, 60, 60 );
376 dc
.SelectObject( wxNullBitmap
);
378 // try to find the directory with our images
380 if ( wxFile
::Exists(wxT("./horse.png")) )
382 else if ( wxFile
::Exists(wxT("../horse.png")) )
385 wxLogWarning(wxT("Can't find image files in either '.' or '..'!"));
387 wxImage image
= bitmap
.ConvertToImage();
390 if ( !image
.SaveFile( dir
+ _T("test.png"), wxBITMAP_TYPE_PNG
))
391 wxLogError(wxT("Can't save file"));
395 image
.LoadFile( dir
+ _T("test.png") );
396 my_square
= new wxBitmap( image
);
400 if ( !image
.LoadFile( dir
+ _T("horse.png")) )
401 wxLogError(wxT("Can't load PNG image"));
403 my_horse_png
= new wxBitmap( image
);
404 #endif // wxUSE_LIBPNG
409 if ( !image
.LoadFile( dir
+ _T("horse.jpg")) )
410 wxLogError(wxT("Can't load JPG image"));
412 my_horse_jpeg
= new wxBitmap( image
);
413 #endif // wxUSE_LIBJPEG
418 if ( !image
.LoadFile( dir
+ _T("horse.gif" )) )
419 wxLogError(wxT("Can't load GIF image"));
421 my_horse_gif
= new wxBitmap( image
);
427 if ( !image
.LoadFile( dir
+ _T("horse.pcx"), wxBITMAP_TYPE_PCX
) )
428 wxLogError(wxT("Can't load PCX image"));
430 my_horse_pcx
= new wxBitmap( image
);
435 if ( !image
.LoadFile( dir
+ _T("horse.bmp"), wxBITMAP_TYPE_BMP
) )
436 wxLogError(wxT("Can't load BMP image"));
438 my_horse_bmp
= new wxBitmap( image
);
443 if ( !image
.LoadFile( dir
+ _T("horse.xpm"), wxBITMAP_TYPE_XPM
) )
444 wxLogError(wxT("Can't load XPM image"));
446 my_horse_xpm
= new wxBitmap( image
);
448 if ( !image
.SaveFile( dir
+ _T("test.xpm"), wxBITMAP_TYPE_XPM
))
449 wxLogError(wxT("Can't save file"));
455 if ( !image
.LoadFile( dir
+ _T("horse.pnm"), wxBITMAP_TYPE_PNM
) )
456 wxLogError(wxT("Can't load PNM image"));
458 my_horse_pnm
= new wxBitmap( image
);
464 if ( !image
.LoadFile( dir
+ _T("horse.tif"), wxBITMAP_TYPE_TIF
) )
465 wxLogError(wxT("Can't load TIFF image"));
467 my_horse_tiff
= new wxBitmap( image
);
470 CreateAntiAliasedBitmap();
472 my_smile_xbm
= new wxBitmap( (const char*)smile_bits
, smile_width
,
475 #if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW
476 // demonstrates XPM automatically using the mask when saving
477 if ( m_bmpSmileXpm
.Ok() )
478 m_bmpSmileXpm
.SaveFile(_T("saved.xpm"), wxBITMAP_TYPE_XPM
);
484 if ( !image
.LoadFile( dir
+ _T("horse.ico"), wxBITMAP_TYPE_ICO
, 0 ) )
485 wxLogError(wxT("Can't load first ICO image"));
487 my_horse_ico32
= new wxBitmap( image
);
491 if ( !image
.LoadFile( dir
+ _T("horse.ico"), wxBITMAP_TYPE_ICO
, 1 ) )
492 wxLogError(wxT("Can't load second ICO image"));
494 my_horse_ico16
= new wxBitmap( image
);
498 if ( !image
.LoadFile( dir
+ _T("horse.ico") ) )
499 wxLogError(wxT("Can't load best ICO image"));
501 my_horse_ico
= new wxBitmap( image
);
505 if ( !image
.LoadFile( dir
+ _T("horse.cur"), wxBITMAP_TYPE_CUR
) )
506 wxLogError(wxT("Can't load best ICO image"));
509 my_horse_cur
= new wxBitmap( image
);
510 xH
= 30 + image
.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X
) ;
511 yH
= 2420 + image
.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y
) ;
514 m_ani_images
= wxImage
::GetImageCount ( dir
+ _T("horse3.ani"), wxBITMAP_TYPE_ANI
);
516 wxLogError(wxT("No ANI-format images found"));
518 my_horse_ani
= new wxBitmap
[m_ani_images
];
520 for (i
=0; i
< m_ani_images
; i
++)
523 if (!image
.LoadFile( dir
+ _T("horse3.ani"), wxBITMAP_TYPE_ANI
, i
))
525 wxString tmp
= wxT("Can't load image number ");
530 my_horse_ani
[i
] = wxBitmap( image
);
538 // test image loading from stream
539 wxFile
file(dir
+ _T("horse.bmp"));
540 off_t len
= file
.Length();
541 void *data
= malloc(len
);
542 if ( file
.Read(data
, len
) != len
)
543 wxLogError(_T("Reading bitmap file failed"));
546 wxMemoryInputStream
mis(data
, len
);
547 if ( !image
.LoadFile(mis
) )
548 wxLogError(wxT("Can't load BMP image from stream"));
550 my_horse_bmp2
= new wxBitmap( image
);
556 MyCanvas
::~MyCanvas()
560 delete my_horse_jpeg
;
563 delete my_horse_bmp2
;
565 delete my_horse_tiff
;
567 delete my_horse_ico32
;
568 delete my_horse_ico16
;
571 delete [] my_horse_ani
;
577 void MyCanvas
::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
579 wxPaintDC
dc( this );
582 dc
.DrawText( _T("Loaded image"), 30, 10 );
583 if (my_square
&& my_square
->Ok()) dc
.DrawBitmap( *my_square
, 30, 30 );
585 dc
.DrawText( _T("Drawn directly"), 150, 10 );
586 dc
.SetBrush( wxBrush( wxT("orange"), wxSOLID
) );
587 dc
.SetPen( *wxBLACK_PEN
);
588 dc
.DrawRectangle( 150, 30, 100, 100 );
589 dc
.SetBrush( *wxWHITE_BRUSH
);
590 dc
.DrawRectangle( 170, 50, 60, 60 );
592 if (my_anti
&& my_anti
->Ok())
593 dc
.DrawBitmap( *my_anti
, 280, 30 );
595 dc
.DrawText( _T("PNG handler"), 30, 135 );
596 if (my_horse_png
&& my_horse_png
->Ok())
598 dc
.DrawBitmap( *my_horse_png
, 30, 150 );
599 wxRect
rect(0,0,100,100);
600 wxBitmap
sub( my_horse_png
->GetSubBitmap(rect
) );
601 dc
.DrawText( _T("GetSubBitmap()"), 280, 190 );
602 dc
.DrawBitmap( sub
, 280, 210 );
605 dc
.DrawText( _T("JPEG handler"), 30, 365 );
606 if (my_horse_jpeg
&& my_horse_jpeg
->Ok())
607 dc
.DrawBitmap( *my_horse_jpeg
, 30, 380 );
609 dc
.DrawText( _T("GIF handler"), 30, 595 );
610 if (my_horse_gif
&& my_horse_gif
->Ok())
611 dc
.DrawBitmap( *my_horse_gif
, 30, 610 );
613 dc
.DrawText( _T("PCX handler"), 30, 825 );
614 if (my_horse_pcx
&& my_horse_pcx
->Ok())
615 dc
.DrawBitmap( *my_horse_pcx
, 30, 840 );
617 dc
.DrawText( _T("BMP handler"), 30, 1055 );
618 if (my_horse_bmp
&& my_horse_bmp
->Ok())
619 dc
.DrawBitmap( *my_horse_bmp
, 30, 1070 );
621 dc
.DrawText( _T("BMP read from memory"), 280, 1055 );
622 if (my_horse_bmp2
&& my_horse_bmp2
->Ok())
623 dc
.DrawBitmap( *my_horse_bmp2
, 280, 1070 );
625 dc
.DrawText( _T("PNM handler"), 30, 1285 );
626 if (my_horse_pnm
&& my_horse_pnm
->Ok())
627 dc
.DrawBitmap( *my_horse_pnm
, 30, 1300 );
629 dc
.DrawText( _T("TIFF handler"), 30, 1515 );
630 if (my_horse_tiff
&& my_horse_tiff
->Ok())
631 dc
.DrawBitmap( *my_horse_tiff
, 30, 1530 );
633 dc
.DrawText( _T("XPM handler"), 30, 1745 );
634 if (my_horse_xpm
&& my_horse_xpm
->Ok())
635 dc
.DrawBitmap( *my_horse_xpm
, 30, 1760 );
638 if (my_smile_xbm
&& my_smile_xbm
->Ok())
640 dc
.DrawText( _T("XBM bitmap"), 30, 1975 );
641 dc
.DrawText( _T("(green on red)"), 30, 1990 );
642 dc
.SetTextForeground( _T("GREEN") );
643 dc
.SetTextBackground( _T("RED") );
644 dc
.DrawBitmap( *my_smile_xbm
, 30, 2010 );
646 dc
.SetTextForeground( wxT("BLACK") );
647 dc
.DrawText( _T("After wxImage conversion"), 150, 1975 );
648 dc
.DrawText( _T("(red on white)"), 150, 1990 );
649 dc
.SetTextForeground( wxT("RED") );
650 wxImage i
= my_smile_xbm
->ConvertToImage();
651 i
.SetMaskColour( 255, 255, 255 );
653 wxRED_PEN
->GetColour().Red(),
654 wxRED_PEN
->GetColour().Green(),
655 wxRED_PEN
->GetColour().Blue() );
656 dc
.DrawBitmap( wxBitmap(i
), 150, 2010, TRUE
);
657 dc
.SetTextForeground( wxT("BLACK") );
661 wxBitmap
mono( 60,50,1 );
663 memdc
.SelectObject( mono
);
664 memdc
.SetPen( *wxBLACK_PEN
);
665 memdc
.SetBrush( *wxWHITE_BRUSH
);
666 memdc
.DrawRectangle( 0,0,60,50 );
667 memdc
.SetTextForeground( *wxBLACK
);
668 memdc
.DrawText( _T("Hi!"), 5, 5 );
669 memdc
.SetBrush( *wxBLACK_BRUSH
);
670 memdc
.DrawRectangle( 33,5,20,20 );
671 memdc
.SetPen( *wxRED_PEN
);
672 memdc
.DrawLine( 5, 42, 50, 42 );
673 memdc
.SelectObject( wxNullBitmap
);
677 dc
.DrawText( _T("Mono bitmap"), 30, 2095 );
678 dc
.DrawText( _T("(red on green)"), 30, 2110 );
679 dc
.SetTextForeground( wxT("RED") );
680 dc
.SetTextBackground( wxT("GREEN") );
681 dc
.DrawBitmap( mono
, 30, 2130 );
683 dc
.SetTextForeground( wxT("BLACK") );
684 dc
.DrawText( _T("After wxImage conversion"), 150, 2095 );
685 dc
.DrawText( _T("(red on white)"), 150, 2110 );
686 dc
.SetTextForeground( wxT("RED") );
687 wxImage i
= mono
.ConvertToImage();
688 i
.SetMaskColour( 255,255,255 );
690 wxRED_PEN
->GetColour().Red(),
691 wxRED_PEN
->GetColour().Green(),
692 wxRED_PEN
->GetColour().Blue() );
693 dc
.DrawBitmap( wxBitmap(i
), 150, 2130, TRUE
);
694 dc
.SetTextForeground( wxT("BLACK") );
697 dc
.DrawText(_T("XPM bitmap"), 30, 2230);
698 if ( m_bmpSmileXpm
.Ok() )
700 dc
.DrawBitmap(m_bmpSmileXpm
, 30, 2250, TRUE
);
703 dc
.DrawText(_T("XPM icon"), 150, 2230);
704 if ( m_iconSmileXpm
.Ok() )
706 dc
.DrawIcon(m_iconSmileXpm
, 150, 2250);
709 dc
.DrawText( _T("ICO handler (1st image)"), 30, 2290 );
710 if (my_horse_ico32
&& my_horse_ico32
->Ok())
711 dc
.DrawBitmap( *my_horse_ico32
, 30, 2330, TRUE
);
713 dc
.DrawText( _T("ICO handler (2nd image)"), 230, 2290 );
714 if (my_horse_ico16
&& my_horse_ico16
->Ok())
715 dc
.DrawBitmap( *my_horse_ico16
, 230, 2330, TRUE
);
717 dc
.DrawText( _T("ICO handler (best image)"), 430, 2290 );
718 if (my_horse_ico
&& my_horse_ico
->Ok())
719 dc
.DrawBitmap( *my_horse_ico
, 430, 2330, TRUE
);
721 dc
.DrawText( _T("CUR handler"), 30, 2390 );
722 if (my_horse_cur
&& my_horse_cur
->Ok())
724 dc
.DrawBitmap( *my_horse_cur
, 30, 2420, TRUE
);
725 dc
.SetPen (*wxRED_PEN
);
726 dc
.DrawLine (xH
-10,yH
,xH
+10,yH
);
727 dc
.DrawLine (xH
,yH
-10,xH
,yH
+10);
729 dc
.DrawText( _T("ANI handler"), 230, 2390 );
731 for (i
=0; i
< m_ani_images
; i
++)
732 if (my_horse_ani
[i
].Ok())
734 dc
.DrawBitmap( my_horse_ani
[i
], 230 + i
* 2 * my_horse_ani
[i
].GetWidth() , 2420, TRUE
);
738 void MyCanvas
::CreateAntiAliasedBitmap()
740 wxBitmap
bitmap( 300, 300 );
744 dc
.SelectObject( bitmap
);
748 dc
.SetFont( wxFont( 24, wxDECORATIVE
, wxNORMAL
, wxNORMAL
) );
749 dc
.SetTextForeground( wxT("RED") );
750 dc
.DrawText( _T("This is anti-aliased Text."), 20, 20 );
751 dc
.DrawText( _T("And a Rectangle."), 20, 60 );
753 dc
.SetBrush( *wxRED_BRUSH
);
754 dc
.SetPen( *wxTRANSPARENT_PEN
);
755 dc
.DrawRoundedRectangle( 20, 100, 200, 180, 20 );
757 wxImage original
= bitmap
.ConvertToImage();
758 wxImage
anti( 150, 150 );
760 /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */
762 for (int y
= 1; y
< 149; y
++)
763 for (int x
= 1; x
< 149; x
++)
765 int red
= original
.GetRed( x
*2, y
*2 ) +
766 original
.GetRed( x
*2-1, y
*2 ) +
767 original
.GetRed( x
*2, y
*2+1 ) +
768 original
.GetRed( x
*2+1, y
*2+1 );
771 int green
= original
.GetGreen( x
*2, y
*2 ) +
772 original
.GetGreen( x
*2-1, y
*2 ) +
773 original
.GetGreen( x
*2, y
*2+1 ) +
774 original
.GetGreen( x
*2+1, y
*2+1 );
777 int blue
= original
.GetBlue( x
*2, y
*2 ) +
778 original
.GetBlue( x
*2-1, y
*2 ) +
779 original
.GetBlue( x
*2, y
*2+1 ) +
780 original
.GetBlue( x
*2+1, y
*2+1 );
782 anti
.SetRGB( x
, y
, red
, green
, blue
);
784 my_anti
= new wxBitmap(anti
);
797 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
799 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
800 EVT_MENU (ID_ABOUT
, MyFrame
::OnAbout
)
801 EVT_MENU (ID_QUIT
, MyFrame
::OnQuit
)
802 EVT_MENU (ID_NEW
, MyFrame
::OnNewFrame
)
803 #ifdef wxHAVE_RAW_BITMAP
804 EVT_MENU (ID_SHOWRAW
, MyFrame
::OnTestRawBitmap
)
809 : wxFrame( (wxFrame
*)NULL
, -1, _T("wxImage sample"),
810 wxPoint(20,20), wxSize(470,360) )
812 wxMenu
*file_menu
= new wxMenu();
813 file_menu
->Append( ID_NEW
, _T("&Show image...\tCtrl-O"));
814 #ifdef wxHAVE_RAW_BITMAP
815 file_menu
->Append( ID_SHOWRAW
, _T("Test &raw bitmap...\tCtrl-R"));
817 file_menu
->AppendSeparator();
818 file_menu
->Append( ID_ABOUT
, _T("&About..."));
819 file_menu
->AppendSeparator();
820 file_menu
->Append( ID_QUIT
, _T("E&xit\tCtrl-Q"));
822 wxMenuBar
*menu_bar
= new wxMenuBar();
823 menu_bar
->Append(file_menu
, _T("&File"));
825 SetMenuBar( menu_bar
);
828 int widths
[] = { -1, 100 };
829 SetStatusWidths( 2, widths
);
831 m_canvas
= new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
833 // 500 width * 2500 height
834 m_canvas
->SetScrollbars( 10, 10, 50, 250 );
837 void MyFrame
::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
842 void MyFrame
::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
844 (void)wxMessageBox( _T("wxImage demo\n")
845 _T("Robert Roebling (c) 1998,2000"),
846 _T("About wxImage Demo"), wxICON_INFORMATION
| wxOK
);
849 void MyFrame
::OnNewFrame( wxCommandEvent
&WXUNUSED(event
) )
851 wxString filename
= wxFileSelector(_T("Select image file"));
856 if ( !image
.LoadFile(filename
) )
858 wxLogError(_T("Couldn't load image from '%s'."), filename
.c_str());
863 (new MyImageFrame(this, wxBitmap(image
)))->Show();
866 #ifdef wxHAVE_RAW_BITMAP
868 void MyFrame
::OnTestRawBitmap( wxCommandEvent
&event
)
870 (new MyRawBitmapFrame(this))->Show();
873 #endif // wxHAVE_RAW_BITMAP
875 //-----------------------------------------------------------------------------
877 //-----------------------------------------------------------------------------
882 wxImage
::AddHandler( new wxPNGHandler
);
886 wxImage
::AddHandler( new wxJPEGHandler
);
890 wxImage
::AddHandler( new wxTIFFHandler
);
894 wxImage
::AddHandler( new wxGIFHandler
);
898 wxImage
::AddHandler( new wxPCXHandler
);
902 wxImage
::AddHandler( new wxPNMHandler
);
906 wxImage
::AddHandler( new wxXPMHandler
);
910 wxImage
::AddHandler( new wxICOHandler
);
911 wxImage
::AddHandler( new wxCURHandler
);
912 wxImage
::AddHandler( new wxANIHandler
);
915 wxFrame
*frame
= new MyFrame();