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 #if !defined(__WXMOTIF__)
34 #define wxHAVE_RAW_BITMAP
44 class MyCanvas
: public wxScrolledWindow
48 MyCanvas( wxWindow
*parent
, wxWindowID
, const wxPoint
&pos
, const wxSize
&size
);
50 void OnPaint( wxPaintEvent
&event
);
51 void CreateAntiAliasedBitmap();
53 wxBitmap
*my_horse_png
;
54 wxBitmap
*my_horse_jpeg
;
55 wxBitmap
*my_horse_gif
;
56 wxBitmap
*my_horse_bmp
;
57 wxBitmap
*my_horse_bmp2
;
58 wxBitmap
*my_horse_pcx
;
59 wxBitmap
*my_horse_pnm
;
60 wxBitmap
*my_horse_tiff
;
61 wxBitmap
*my_horse_xpm
;
62 wxBitmap
*my_horse_ico32
;
63 wxBitmap
*my_horse_ico16
;
64 wxBitmap
*my_horse_ico
;
65 wxBitmap
*my_horse_cur
;
66 wxBitmap
*my_horse_ani
;
68 wxBitmap
*my_smile_xbm
;
76 wxBitmap m_bmpSmileXpm
;
77 wxIcon m_iconSmileXpm
;
80 DECLARE_DYNAMIC_CLASS(MyCanvas
)
85 const int nChoices
= 8 ;
86 static const wxString bppchoices
[nChoices
] =
92 _T("8 bpp greyscale"),
94 _T("8 bpp own palette"),
98 static const int bppvalues
[nChoices
] =
113 class MyFrame
: public wxFrame
118 void OnAbout( wxCommandEvent
&event
);
119 void OnNewFrame( wxCommandEvent
&event
);
120 #ifdef wxHAVE_RAW_BITMAP
121 void OnTestRawBitmap( wxCommandEvent
&event
);
122 #endif // wxHAVE_RAW_BITMAP
123 void OnQuit( wxCommandEvent
&event
);
128 DECLARE_DYNAMIC_CLASS(MyFrame
)
129 DECLARE_EVENT_TABLE()
132 class MyImageFrame
: public wxFrame
135 MyImageFrame(wxFrame
*parent
, const wxBitmap
& bitmap
)
136 : wxFrame(parent
, -1, _T("Double click to save"),
137 wxDefaultPosition
, wxDefaultSize
,
138 wxCAPTION
| wxSYSTEM_MENU
),
141 SetClientSize(bitmap
.GetWidth(), bitmap
.GetHeight());
144 void OnEraseBackground(wxEraseEvent
& WXUNUSED(event
))
146 // do nothing here to be able to see how transparent images are shown
149 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
151 wxPaintDC
dc( this );
152 dc
.DrawBitmap( m_bitmap
, 0, 0, TRUE
/* use mask */ );
155 void OnSave(wxMouseEvent
& WXUNUSED(event
))
157 wxImage image
= m_bitmap
.ConvertToImage();
159 int bppselection
= wxGetSingleChoiceIndex(_T("Set BMP BPP"),
164 if ( bppselection
== -1 )
170 image
.SetOption(wxIMAGE_OPTION_BMP_FORMAT
, bppvalues
[bppselection
]);
172 wxString deffilename
= bppchoices
[bppselection
];
173 deffilename
.Replace(wxT(" "), wxT("_"));
174 deffilename
+= wxT(".bmp");
175 wxString savefilename
= wxFileSelector( wxT("Save Image"),
178 (const wxChar
*)NULL
,
179 wxT("BMP files (*.bmp)|*.bmp|")
180 wxT("PNG files (*.png)|*.png|")
181 wxT("JPEG files (*.jpg)|*.jpg|")
182 wxT("GIF files (*.gif)|*.gif|")
183 wxT("TIFF files (*.tif)|*.tif|")
184 wxT("PCX files (*.pcx)|*.pcx|")
185 wxT("ICO files (*.ico)|*.ico|")
186 wxT("CUR files (*.cur)|*.cur"),
189 if ( savefilename
.empty() )
192 if ( image
.GetOptionInt(wxIMAGE_OPTION_BMP_FORMAT
) == wxBMP_8BPP_PALETTE
)
194 unsigned char *cmap
= new unsigned char [256];
195 for ( int i
= 0; i
< 256; i
++ )
197 image
.SetPalette(wxPalette(256, cmap
, cmap
, cmap
));
203 wxString extension
= savefilename
.AfterLast('.').Lower();
205 if (extension
== _T("cur"))
207 image
.Rescale(32,32);
208 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
, 0);
209 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
, 0);
210 // This shows how you can save an image with explicitly
211 // specified image format:
212 loaded
= image
.SaveFile(savefilename
, wxBITMAP_TYPE_CUR
);
216 // This one guesses image format from filename extension
217 // (it may fail if the extension is not recognized):
218 loaded
= image
.SaveFile(savefilename
);
222 wxMessageBox(_T("No handler for this file type."),
223 _T("File was not saved"),
224 wxOK
|wxCENTRE
, this);
230 DECLARE_EVENT_TABLE()
233 #ifdef wxHAVE_RAW_BITMAP
235 #include "wx/rawbmp.h"
237 class MyRawBitmapFrame
: public wxFrame
244 REAL_SIZE
= SIZE
- 2*BORDER
247 MyRawBitmapFrame(wxFrame
*parent
)
248 : wxFrame(parent
, -1, _T("Raw bitmaps (how exciting)")),
249 m_bitmap(SIZE
, SIZE
, 32)
251 SetClientSize(SIZE
, SIZE
);
253 wxRawBitmapData
data(m_bitmap
);
256 wxLogError(_T("Failed to gain raw access to bitmap data"));
260 wxRawBitmapIterator
p(data
);
262 p
.Offset(BORDER
, BORDER
);
264 for ( int y
= 0; y
< REAL_SIZE
; ++y
)
266 wxRawBitmapIterator rowStart
= p
;
268 int r
= y
< REAL_SIZE
/3 ? 255 : 0,
269 g
= (REAL_SIZE
/3 <= y
) && (y
< 2*(REAL_SIZE
/3)) ? 255 : 0,
270 b
= 2*(REAL_SIZE
/3) <= y
? 255 : 0;
272 for ( int x
= 0; x
< REAL_SIZE
; ++x
)
279 ++p
; // same as p.OffsetX(1)
287 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
289 wxPaintDC
dc( this );
290 dc
.DrawText(_T("This is alpha and raw bitmap test"), 0, BORDER
);
291 dc
.DrawText(_T("This is alpha and raw bitmap test"), 0, SIZE
/2 - BORDER
);
292 dc
.DrawText(_T("This is alpha and raw bitmap test"), 0, SIZE
- 2*BORDER
);
293 dc
.DrawBitmap( m_bitmap
, 0, 0, TRUE
/* use mask */ );
299 DECLARE_EVENT_TABLE()
302 #endif // wxHAVE_RAW_BITMAP
306 class MyApp
: public wxApp
309 virtual bool OnInit();
318 IMPLEMENT_DYNAMIC_CLASS(MyCanvas
, wxScrolledWindow
)
320 BEGIN_EVENT_TABLE(MyImageFrame
, wxFrame
)
321 EVT_ERASE_BACKGROUND(MyImageFrame::OnEraseBackground
)
322 EVT_PAINT(MyImageFrame::OnPaint
)
323 EVT_LEFT_DCLICK(MyImageFrame::OnSave
)
326 #ifdef wxHAVE_RAW_BITMAP
328 BEGIN_EVENT_TABLE(MyRawBitmapFrame
, wxFrame
)
329 EVT_PAINT(MyRawBitmapFrame::OnPaint
)
332 #endif // wxHAVE_RAW_BITMAP
334 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
335 EVT_PAINT(MyCanvas::OnPaint
)
338 MyCanvas::MyCanvas( wxWindow
*parent
, wxWindowID id
,
339 const wxPoint
&pos
, const wxSize
&size
)
340 : wxScrolledWindow( parent
, id
, pos
, size
, wxSUNKEN_BORDER
)
341 #if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW
342 , m_bmpSmileXpm((const char **) smile_xpm
)
343 , m_iconSmileXpm((const char **) smile_xpm
)
346 my_horse_png
= (wxBitmap
*) NULL
;
347 my_horse_jpeg
= (wxBitmap
*) NULL
;
348 my_horse_gif
= (wxBitmap
*) NULL
;
349 my_horse_bmp
= (wxBitmap
*) NULL
;
350 my_horse_bmp2
= (wxBitmap
*) NULL
;
351 my_horse_pcx
= (wxBitmap
*) NULL
;
352 my_horse_pnm
= (wxBitmap
*) NULL
;
353 my_horse_tiff
= (wxBitmap
*) NULL
;
354 my_horse_xpm
= (wxBitmap
*) NULL
;
355 my_horse_ico32
= (wxBitmap
*) NULL
;
356 my_horse_ico16
= (wxBitmap
*) NULL
;
357 my_horse_ico
= (wxBitmap
*) NULL
;
358 my_horse_cur
= (wxBitmap
*) NULL
;
359 my_horse_ani
= (wxBitmap
*) NULL
;
361 my_smile_xbm
= (wxBitmap
*) NULL
;
362 my_square
= (wxBitmap
*) NULL
;
363 my_anti
= (wxBitmap
*) NULL
;
367 SetBackgroundColour(* wxWHITE
);
369 wxBitmap
bitmap( 100, 100 );
372 dc
.SelectObject( bitmap
);
373 dc
.SetBrush( wxBrush( wxT("orange"), wxSOLID
) );
374 dc
.SetPen( *wxBLACK_PEN
);
375 dc
.DrawRectangle( 0, 0, 100, 100 );
376 dc
.SetBrush( *wxWHITE_BRUSH
);
377 dc
.DrawRectangle( 20, 20, 60, 60 );
378 dc
.SelectObject( wxNullBitmap
);
380 // try to find the directory with our images
382 if ( wxFile::Exists(wxT("./horse.png")) )
384 else if ( wxFile::Exists(wxT("../horse.png")) )
387 wxLogWarning(wxT("Can't find image files in either '.' or '..'!"));
389 wxImage image
= bitmap
.ConvertToImage();
392 if ( !image
.SaveFile( dir
+ _T("test.png"), wxBITMAP_TYPE_PNG
))
393 wxLogError(wxT("Can't save file"));
397 image
.LoadFile( dir
+ _T("test.png") );
398 my_square
= new wxBitmap( image
);
402 if ( !image
.LoadFile( dir
+ _T("horse.png")) )
403 wxLogError(wxT("Can't load PNG image"));
405 my_horse_png
= new wxBitmap( image
);
406 #endif // wxUSE_LIBPNG
411 if ( !image
.LoadFile( dir
+ _T("horse.jpg")) )
412 wxLogError(wxT("Can't load JPG image"));
414 my_horse_jpeg
= new wxBitmap( image
);
415 #endif // wxUSE_LIBJPEG
420 if ( !image
.LoadFile( dir
+ _T("horse.gif" )) )
421 wxLogError(wxT("Can't load GIF image"));
423 my_horse_gif
= new wxBitmap( image
);
429 if ( !image
.LoadFile( dir
+ _T("horse.pcx"), wxBITMAP_TYPE_PCX
) )
430 wxLogError(wxT("Can't load PCX image"));
432 my_horse_pcx
= new wxBitmap( image
);
437 if ( !image
.LoadFile( dir
+ _T("horse.bmp"), wxBITMAP_TYPE_BMP
) )
438 wxLogError(wxT("Can't load BMP image"));
440 my_horse_bmp
= new wxBitmap( image
);
445 if ( !image
.LoadFile( dir
+ _T("horse.xpm"), wxBITMAP_TYPE_XPM
) )
446 wxLogError(wxT("Can't load XPM image"));
448 my_horse_xpm
= new wxBitmap( image
);
450 if ( !image
.SaveFile( dir
+ _T("test.xpm"), wxBITMAP_TYPE_XPM
))
451 wxLogError(wxT("Can't save file"));
457 if ( !image
.LoadFile( dir
+ _T("horse.pnm"), wxBITMAP_TYPE_PNM
) )
458 wxLogError(wxT("Can't load PNM image"));
460 my_horse_pnm
= new wxBitmap( image
);
466 if ( !image
.LoadFile( dir
+ _T("horse.tif"), wxBITMAP_TYPE_TIF
) )
467 wxLogError(wxT("Can't load TIFF image"));
469 my_horse_tiff
= new wxBitmap( image
);
472 CreateAntiAliasedBitmap();
474 my_smile_xbm
= new wxBitmap( (const char*)smile_bits
, smile_width
,
477 #if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW
478 // demonstrates XPM automatically using the mask when saving
479 if ( m_bmpSmileXpm
.Ok() )
480 m_bmpSmileXpm
.SaveFile(_T("saved.xpm"), wxBITMAP_TYPE_XPM
);
486 if ( !image
.LoadFile( dir
+ _T("horse.ico"), wxBITMAP_TYPE_ICO
, 0 ) )
487 wxLogError(wxT("Can't load first ICO image"));
489 my_horse_ico32
= new wxBitmap( image
);
493 if ( !image
.LoadFile( dir
+ _T("horse.ico"), wxBITMAP_TYPE_ICO
, 1 ) )
494 wxLogError(wxT("Can't load second ICO image"));
496 my_horse_ico16
= new wxBitmap( image
);
500 if ( !image
.LoadFile( dir
+ _T("horse.ico") ) )
501 wxLogError(wxT("Can't load best ICO image"));
503 my_horse_ico
= new wxBitmap( image
);
507 if ( !image
.LoadFile( dir
+ _T("horse.cur"), wxBITMAP_TYPE_CUR
) )
508 wxLogError(wxT("Can't load best ICO image"));
511 my_horse_cur
= new wxBitmap( image
);
512 xH
= 30 + image
.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X
) ;
513 yH
= 2420 + image
.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y
) ;
516 m_ani_images
= wxImage::GetImageCount ( dir
+ _T("horse3.ani"), wxBITMAP_TYPE_ANI
);
518 wxLogError(wxT("No ANI-format images found"));
520 my_horse_ani
= new wxBitmap
[m_ani_images
];
522 for (i
=0; i
< m_ani_images
; i
++)
525 if (!image
.LoadFile( dir
+ _T("horse3.ani"), wxBITMAP_TYPE_ANI
, i
))
527 wxString tmp
= wxT("Can't load image number ");
532 my_horse_ani
[i
] = wxBitmap( image
);
540 // test image loading from stream
541 wxFile
file(dir
+ _T("horse.bmp"));
542 off_t len
= file
.Length();
543 void *data
= malloc(len
);
544 if ( file
.Read(data
, len
) != len
)
545 wxLogError(_T("Reading bitmap file failed"));
548 wxMemoryInputStream
mis(data
, len
);
549 if ( !image
.LoadFile(mis
) )
550 wxLogError(wxT("Can't load BMP image from stream"));
552 my_horse_bmp2
= new wxBitmap( image
);
558 MyCanvas::~MyCanvas()
562 delete my_horse_jpeg
;
565 delete my_horse_bmp2
;
567 delete my_horse_tiff
;
569 delete my_horse_ico32
;
570 delete my_horse_ico16
;
573 delete [] my_horse_ani
;
579 void MyCanvas::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
581 wxPaintDC
dc( this );
584 dc
.DrawText( _T("Loaded image"), 30, 10 );
585 if (my_square
&& my_square
->Ok()) dc
.DrawBitmap( *my_square
, 30, 30 );
587 dc
.DrawText( _T("Drawn directly"), 150, 10 );
588 dc
.SetBrush( wxBrush( wxT("orange"), wxSOLID
) );
589 dc
.SetPen( *wxBLACK_PEN
);
590 dc
.DrawRectangle( 150, 30, 100, 100 );
591 dc
.SetBrush( *wxWHITE_BRUSH
);
592 dc
.DrawRectangle( 170, 50, 60, 60 );
594 if (my_anti
&& my_anti
->Ok())
595 dc
.DrawBitmap( *my_anti
, 280, 30 );
597 dc
.DrawText( _T("PNG handler"), 30, 135 );
598 if (my_horse_png
&& my_horse_png
->Ok())
600 dc
.DrawBitmap( *my_horse_png
, 30, 150 );
601 wxRect
rect(0,0,100,100);
602 wxBitmap
sub( my_horse_png
->GetSubBitmap(rect
) );
603 dc
.DrawText( _T("GetSubBitmap()"), 280, 190 );
604 dc
.DrawBitmap( sub
, 280, 210 );
607 dc
.DrawText( _T("JPEG handler"), 30, 365 );
608 if (my_horse_jpeg
&& my_horse_jpeg
->Ok())
609 dc
.DrawBitmap( *my_horse_jpeg
, 30, 380 );
611 dc
.DrawText( _T("GIF handler"), 30, 595 );
612 if (my_horse_gif
&& my_horse_gif
->Ok())
613 dc
.DrawBitmap( *my_horse_gif
, 30, 610 );
615 dc
.DrawText( _T("PCX handler"), 30, 825 );
616 if (my_horse_pcx
&& my_horse_pcx
->Ok())
617 dc
.DrawBitmap( *my_horse_pcx
, 30, 840 );
619 dc
.DrawText( _T("BMP handler"), 30, 1055 );
620 if (my_horse_bmp
&& my_horse_bmp
->Ok())
621 dc
.DrawBitmap( *my_horse_bmp
, 30, 1070 );
623 dc
.DrawText( _T("BMP read from memory"), 280, 1055 );
624 if (my_horse_bmp2
&& my_horse_bmp2
->Ok())
625 dc
.DrawBitmap( *my_horse_bmp2
, 280, 1070 );
627 dc
.DrawText( _T("PNM handler"), 30, 1285 );
628 if (my_horse_pnm
&& my_horse_pnm
->Ok())
629 dc
.DrawBitmap( *my_horse_pnm
, 30, 1300 );
631 dc
.DrawText( _T("TIFF handler"), 30, 1515 );
632 if (my_horse_tiff
&& my_horse_tiff
->Ok())
633 dc
.DrawBitmap( *my_horse_tiff
, 30, 1530 );
635 dc
.DrawText( _T("XPM handler"), 30, 1745 );
636 if (my_horse_xpm
&& my_horse_xpm
->Ok())
637 dc
.DrawBitmap( *my_horse_xpm
, 30, 1760 );
640 if (my_smile_xbm
&& my_smile_xbm
->Ok())
642 dc
.DrawText( _T("XBM bitmap"), 30, 1975 );
643 dc
.DrawText( _T("(green on red)"), 30, 1990 );
644 dc
.SetTextForeground( _T("GREEN") );
645 dc
.SetTextBackground( _T("RED") );
646 dc
.DrawBitmap( *my_smile_xbm
, 30, 2010 );
648 dc
.SetTextForeground( wxT("BLACK") );
649 dc
.DrawText( _T("After wxImage conversion"), 150, 1975 );
650 dc
.DrawText( _T("(red on white)"), 150, 1990 );
651 dc
.SetTextForeground( wxT("RED") );
652 wxImage i
= my_smile_xbm
->ConvertToImage();
653 i
.SetMaskColour( 255, 255, 255 );
655 wxRED_PEN
->GetColour().Red(),
656 wxRED_PEN
->GetColour().Green(),
657 wxRED_PEN
->GetColour().Blue() );
658 dc
.DrawBitmap( wxBitmap(i
), 150, 2010, TRUE
);
659 dc
.SetTextForeground( wxT("BLACK") );
663 wxBitmap
mono( 60,50,1 );
665 memdc
.SelectObject( mono
);
666 memdc
.SetPen( *wxBLACK_PEN
);
667 memdc
.SetBrush( *wxWHITE_BRUSH
);
668 memdc
.DrawRectangle( 0,0,60,50 );
669 memdc
.SetTextForeground( *wxBLACK
);
670 memdc
.DrawText( _T("Hi!"), 5, 5 );
671 memdc
.SetBrush( *wxBLACK_BRUSH
);
672 memdc
.DrawRectangle( 33,5,20,20 );
673 memdc
.SetPen( *wxRED_PEN
);
674 memdc
.DrawLine( 5, 42, 50, 42 );
675 memdc
.SelectObject( wxNullBitmap
);
679 dc
.DrawText( _T("Mono bitmap"), 30, 2095 );
680 dc
.DrawText( _T("(red on green)"), 30, 2110 );
681 dc
.SetTextForeground( wxT("RED") );
682 dc
.SetTextBackground( wxT("GREEN") );
683 dc
.DrawBitmap( mono
, 30, 2130 );
685 dc
.SetTextForeground( wxT("BLACK") );
686 dc
.DrawText( _T("After wxImage conversion"), 150, 2095 );
687 dc
.DrawText( _T("(red on white)"), 150, 2110 );
688 dc
.SetTextForeground( wxT("RED") );
689 wxImage i
= mono
.ConvertToImage();
690 i
.SetMaskColour( 255,255,255 );
692 wxRED_PEN
->GetColour().Red(),
693 wxRED_PEN
->GetColour().Green(),
694 wxRED_PEN
->GetColour().Blue() );
695 dc
.DrawBitmap( wxBitmap(i
), 150, 2130, TRUE
);
696 dc
.SetTextForeground( wxT("BLACK") );
699 dc
.DrawText(_T("XPM bitmap"), 30, 2230);
700 if ( m_bmpSmileXpm
.Ok() )
702 dc
.DrawBitmap(m_bmpSmileXpm
, 30, 2250, TRUE
);
705 dc
.DrawText(_T("XPM icon"), 150, 2230);
706 if ( m_iconSmileXpm
.Ok() )
708 dc
.DrawIcon(m_iconSmileXpm
, 150, 2250);
711 dc
.DrawText( _T("ICO handler (1st image)"), 30, 2290 );
712 if (my_horse_ico32
&& my_horse_ico32
->Ok())
713 dc
.DrawBitmap( *my_horse_ico32
, 30, 2330, TRUE
);
715 dc
.DrawText( _T("ICO handler (2nd image)"), 230, 2290 );
716 if (my_horse_ico16
&& my_horse_ico16
->Ok())
717 dc
.DrawBitmap( *my_horse_ico16
, 230, 2330, TRUE
);
719 dc
.DrawText( _T("ICO handler (best image)"), 430, 2290 );
720 if (my_horse_ico
&& my_horse_ico
->Ok())
721 dc
.DrawBitmap( *my_horse_ico
, 430, 2330, TRUE
);
723 dc
.DrawText( _T("CUR handler"), 30, 2390 );
724 if (my_horse_cur
&& my_horse_cur
->Ok())
726 dc
.DrawBitmap( *my_horse_cur
, 30, 2420, TRUE
);
727 dc
.SetPen (*wxRED_PEN
);
728 dc
.DrawLine (xH
-10,yH
,xH
+10,yH
);
729 dc
.DrawLine (xH
,yH
-10,xH
,yH
+10);
731 dc
.DrawText( _T("ANI handler"), 230, 2390 );
733 for (i
=0; i
< m_ani_images
; i
++)
734 if (my_horse_ani
[i
].Ok())
736 dc
.DrawBitmap( my_horse_ani
[i
], 230 + i
* 2 * my_horse_ani
[i
].GetWidth() , 2420, TRUE
);
740 void MyCanvas::CreateAntiAliasedBitmap()
742 wxBitmap
bitmap( 300, 300 );
746 dc
.SelectObject( bitmap
);
750 dc
.SetFont( wxFont( 24, wxDECORATIVE
, wxNORMAL
, wxNORMAL
) );
751 dc
.SetTextForeground( wxT("RED") );
752 dc
.DrawText( _T("This is anti-aliased Text."), 20, 20 );
753 dc
.DrawText( _T("And a Rectangle."), 20, 60 );
755 dc
.SetBrush( *wxRED_BRUSH
);
756 dc
.SetPen( *wxTRANSPARENT_PEN
);
757 dc
.DrawRoundedRectangle( 20, 100, 200, 180, 20 );
759 wxImage original
= bitmap
.ConvertToImage();
760 wxImage
anti( 150, 150 );
762 /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */
764 for (int y
= 1; y
< 149; y
++)
765 for (int x
= 1; x
< 149; x
++)
767 int red
= original
.GetRed( x
*2, y
*2 ) +
768 original
.GetRed( x
*2-1, y
*2 ) +
769 original
.GetRed( x
*2, y
*2+1 ) +
770 original
.GetRed( x
*2+1, y
*2+1 );
773 int green
= original
.GetGreen( x
*2, y
*2 ) +
774 original
.GetGreen( x
*2-1, y
*2 ) +
775 original
.GetGreen( x
*2, y
*2+1 ) +
776 original
.GetGreen( x
*2+1, y
*2+1 );
779 int blue
= original
.GetBlue( x
*2, y
*2 ) +
780 original
.GetBlue( x
*2-1, y
*2 ) +
781 original
.GetBlue( x
*2, y
*2+1 ) +
782 original
.GetBlue( x
*2+1, y
*2+1 );
784 anti
.SetRGB( x
, y
, red
, green
, blue
);
786 my_anti
= new wxBitmap(anti
);
799 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
801 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
802 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
803 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
804 EVT_MENU (ID_NEW
, MyFrame::OnNewFrame
)
805 #ifdef wxHAVE_RAW_BITMAP
806 EVT_MENU (ID_SHOWRAW
, MyFrame::OnTestRawBitmap
)
811 : wxFrame( (wxFrame
*)NULL
, -1, _T("wxImage sample"),
812 wxPoint(20,20), wxSize(470,360) )
814 wxMenu
*file_menu
= new wxMenu();
815 file_menu
->Append( ID_NEW
, _T("&Show image...\tCtrl-O"));
816 #ifdef wxHAVE_RAW_BITMAP
817 file_menu
->Append( ID_SHOWRAW
, _T("Test &raw bitmap...\tCtrl-R"));
819 file_menu
->AppendSeparator();
820 file_menu
->Append( ID_ABOUT
, _T("&About..."));
821 file_menu
->AppendSeparator();
822 file_menu
->Append( ID_QUIT
, _T("E&xit\tCtrl-Q"));
824 wxMenuBar
*menu_bar
= new wxMenuBar();
825 menu_bar
->Append(file_menu
, _T("&File"));
827 SetMenuBar( menu_bar
);
830 int widths
[] = { -1, 100 };
831 SetStatusWidths( 2, widths
);
833 m_canvas
= new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
835 // 500 width * 2500 height
836 m_canvas
->SetScrollbars( 10, 10, 50, 250 );
839 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
844 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
846 (void)wxMessageBox( _T("wxImage demo\n")
847 _T("Robert Roebling (c) 1998,2000"),
848 _T("About wxImage Demo"), wxICON_INFORMATION
| wxOK
);
851 void MyFrame::OnNewFrame( wxCommandEvent
&WXUNUSED(event
) )
853 wxString filename
= wxFileSelector(_T("Select image file"));
858 if ( !image
.LoadFile(filename
) )
860 wxLogError(_T("Couldn't load image from '%s'."), filename
.c_str());
865 (new MyImageFrame(this, wxBitmap(image
)))->Show();
868 #ifdef wxHAVE_RAW_BITMAP
870 void MyFrame::OnTestRawBitmap( wxCommandEvent
&event
)
872 (new MyRawBitmapFrame(this))->Show();
875 #endif // wxHAVE_RAW_BITMAP
877 //-----------------------------------------------------------------------------
879 //-----------------------------------------------------------------------------
884 wxImage::AddHandler( new wxPNGHandler
);
888 wxImage::AddHandler( new wxJPEGHandler
);
892 wxImage::AddHandler( new wxTIFFHandler
);
896 wxImage::AddHandler( new wxGIFHandler
);
900 wxImage::AddHandler( new wxPCXHandler
);
904 wxImage::AddHandler( new wxPNMHandler
);
908 wxImage::AddHandler( new wxXPMHandler
);
912 wxImage::AddHandler( new wxICOHandler
);
913 wxImage::AddHandler( new wxCURHandler
);
914 wxImage::AddHandler( new wxANIHandler
);
917 wxFrame
*frame
= new MyFrame();