1998-10-24 17:12:05 +00:00
|
|
|
/*
|
|
|
|
* Program: image
|
1999-01-12 23:51:13 +00:00
|
|
|
*
|
1998-10-24 17:12:05 +00:00
|
|
|
* Author: Robert Roebling
|
|
|
|
*
|
|
|
|
* Copyright: (C) 1998, Robert Roebling
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-01-09 20:18:06 +00:00
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
1998-10-24 17:12:05 +00:00
|
|
|
#include "wx/wx.h"
|
1999-01-09 20:18:06 +00:00
|
|
|
#endif
|
|
|
|
|
1998-10-24 17:12:05 +00:00
|
|
|
#include "wx/image.h"
|
1999-05-13 21:21:04 +00:00
|
|
|
#include "wx/file.h"
|
2001-04-22 22:25:18 +00:00
|
|
|
#include "wx/mstream.h"
|
|
|
|
#include "wx/wfstream.h"
|
2001-08-25 15:30:49 +00:00
|
|
|
#include "wx/quantize.h"
|
1999-05-13 21:21:04 +00:00
|
|
|
|
1999-12-14 16:53:41 +00:00
|
|
|
#include "smile.xbm"
|
2002-08-22 23:20:40 +00:00
|
|
|
|
|
|
|
#if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW
|
|
|
|
#include "smile.xpm"
|
|
|
|
#endif
|
1999-12-14 16:53:41 +00:00
|
|
|
|
2003-03-22 19:10:09 +00:00
|
|
|
#define wxHAVE_RAW_BITMAP
|
2001-04-22 22:25:18 +00:00
|
|
|
|
1998-10-24 17:12:05 +00:00
|
|
|
// derived classes
|
|
|
|
|
|
|
|
class MyFrame;
|
|
|
|
class MyApp;
|
|
|
|
|
|
|
|
// MyCanvas
|
|
|
|
|
|
|
|
class MyCanvas: public wxScrolledWindow
|
|
|
|
{
|
1999-01-12 23:51:13 +00:00
|
|
|
public:
|
2002-05-24 22:23:24 +00:00
|
|
|
MyCanvas() {}
|
1998-10-24 17:12:05 +00:00
|
|
|
MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size );
|
1999-01-12 23:51:13 +00:00
|
|
|
~MyCanvas();
|
1998-10-24 17:12:05 +00:00
|
|
|
void OnPaint( wxPaintEvent &event );
|
1999-01-22 18:08:54 +00:00
|
|
|
void CreateAntiAliasedBitmap();
|
1999-01-12 23:51:13 +00:00
|
|
|
|
1999-04-17 17:54:07 +00:00
|
|
|
wxBitmap *my_horse_png;
|
|
|
|
wxBitmap *my_horse_jpeg;
|
|
|
|
wxBitmap *my_horse_gif;
|
1999-05-27 19:54:05 +00:00
|
|
|
wxBitmap *my_horse_bmp;
|
2002-05-24 22:23:24 +00:00
|
|
|
wxBitmap *my_horse_bmp2;
|
1999-08-27 11:42:47 +00:00
|
|
|
wxBitmap *my_horse_pcx;
|
1999-08-29 19:48:03 +00:00
|
|
|
wxBitmap *my_horse_pnm;
|
1999-11-28 17:21:03 +00:00
|
|
|
wxBitmap *my_horse_tiff;
|
2001-04-28 23:30:11 +00:00
|
|
|
wxBitmap *my_horse_xpm;
|
2002-02-02 23:16:09 +00:00
|
|
|
wxBitmap *my_horse_ico32;
|
|
|
|
wxBitmap *my_horse_ico16;
|
|
|
|
wxBitmap *my_horse_ico;
|
|
|
|
wxBitmap *my_horse_cur;
|
2002-12-04 14:11:26 +00:00
|
|
|
wxBitmap *my_horse_ani;
|
2002-05-24 22:23:24 +00:00
|
|
|
|
1999-12-14 16:53:41 +00:00
|
|
|
wxBitmap *my_smile_xbm;
|
1998-11-10 19:18:37 +00:00
|
|
|
wxBitmap *my_square;
|
1999-01-22 18:08:54 +00:00
|
|
|
wxBitmap *my_anti;
|
1999-01-12 23:51:13 +00:00
|
|
|
|
2002-02-02 23:16:09 +00:00
|
|
|
int xH, yH ;
|
2002-12-04 14:11:26 +00:00
|
|
|
int m_ani_images ;
|
2002-02-02 23:16:09 +00:00
|
|
|
|
2000-01-21 21:40:10 +00:00
|
|
|
protected:
|
|
|
|
wxBitmap m_bmpSmileXpm;
|
|
|
|
wxIcon m_iconSmileXpm;
|
|
|
|
|
1999-11-28 17:21:03 +00:00
|
|
|
private:
|
1999-01-12 23:51:13 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS(MyCanvas)
|
|
|
|
DECLARE_EVENT_TABLE()
|
1998-10-24 17:12:05 +00:00
|
|
|
};
|
|
|
|
|
2001-11-20 17:01:17 +00:00
|
|
|
|
|
|
|
const int nChoices = 8 ;
|
|
|
|
static const wxString bppchoices[nChoices] =
|
|
|
|
{
|
2002-05-24 22:23:24 +00:00
|
|
|
_T("1 bpp color"),
|
|
|
|
_T("1 bpp B&W"),
|
|
|
|
_T("4 bpp color"),
|
|
|
|
_T("8 bpp color"),
|
|
|
|
_T("8 bpp greyscale"),
|
|
|
|
_T("8 bpp red"),
|
|
|
|
_T("8 bpp own palette"),
|
|
|
|
_T("24 bpp")
|
2001-11-20 17:01:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const int bppvalues[nChoices] =
|
|
|
|
{
|
|
|
|
wxBMP_1BPP,
|
|
|
|
wxBMP_1BPP_BW,
|
|
|
|
wxBMP_4BPP,
|
|
|
|
wxBMP_8BPP,
|
|
|
|
wxBMP_8BPP_GREY,
|
|
|
|
wxBMP_8BPP_RED,
|
|
|
|
wxBMP_8BPP_PALETTE,
|
|
|
|
wxBMP_24BPP
|
|
|
|
};
|
|
|
|
|
1998-10-24 17:12:05 +00:00
|
|
|
// MyFrame
|
|
|
|
|
2001-11-20 17:01:17 +00:00
|
|
|
|
1998-10-24 17:12:05 +00:00
|
|
|
class MyFrame: public wxFrame
|
|
|
|
{
|
1999-01-12 23:51:13 +00:00
|
|
|
public:
|
|
|
|
MyFrame();
|
1998-10-24 17:12:05 +00:00
|
|
|
|
|
|
|
void OnAbout( wxCommandEvent &event );
|
2000-03-16 17:57:19 +00:00
|
|
|
void OnNewFrame( wxCommandEvent &event );
|
2003-03-22 19:10:09 +00:00
|
|
|
#ifdef wxHAVE_RAW_BITMAP
|
|
|
|
void OnTestRawBitmap( wxCommandEvent &event );
|
|
|
|
#endif // wxHAVE_RAW_BITMAP
|
1998-10-24 17:12:05 +00:00
|
|
|
void OnQuit( wxCommandEvent &event );
|
1999-01-12 23:51:13 +00:00
|
|
|
|
1998-10-24 17:12:05 +00:00
|
|
|
MyCanvas *m_canvas;
|
1999-01-12 23:51:13 +00:00
|
|
|
|
1999-11-28 17:21:03 +00:00
|
|
|
private:
|
1999-01-12 23:51:13 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS(MyFrame)
|
|
|
|
DECLARE_EVENT_TABLE()
|
1998-10-24 17:12:05 +00:00
|
|
|
};
|
|
|
|
|
2000-03-16 17:57:19 +00:00
|
|
|
class MyImageFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyImageFrame(wxFrame *parent, const wxBitmap& bitmap)
|
2001-08-25 15:30:49 +00:00
|
|
|
: wxFrame(parent, -1, _T("Double click to save"),
|
2000-03-16 17:57:19 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2000-07-15 19:51:35 +00:00
|
|
|
wxCAPTION | wxSYSTEM_MENU),
|
2001-08-25 15:30:49 +00:00
|
|
|
m_bitmap(bitmap)
|
2000-03-16 17:57:19 +00:00
|
|
|
{
|
|
|
|
SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
|
|
|
|
}
|
|
|
|
|
2003-03-04 02:10:27 +00:00
|
|
|
void OnEraseBackground(wxEraseEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
// do nothing here to be able to see how transparent images are shown
|
|
|
|
}
|
|
|
|
|
2000-03-16 17:57:19 +00:00
|
|
|
void OnPaint(wxPaintEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxPaintDC dc( this );
|
2003-03-04 02:10:27 +00:00
|
|
|
dc.DrawBitmap( m_bitmap, 0, 0, TRUE /* use mask */ );
|
2000-03-16 17:57:19 +00:00
|
|
|
}
|
|
|
|
|
2003-01-12 22:31:16 +00:00
|
|
|
void OnSave(wxMouseEvent& WXUNUSED(event))
|
2001-08-25 15:30:49 +00:00
|
|
|
{
|
2002-03-24 00:22:15 +00:00
|
|
|
wxImage image = m_bitmap.ConvertToImage();
|
2001-08-25 15:30:49 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
int bppselection = wxGetSingleChoiceIndex(_T("Set BMP BPP"),
|
|
|
|
_T("Set BMP BPP"),
|
2001-11-20 17:01:17 +00:00
|
|
|
nChoices,
|
2001-08-25 15:30:49 +00:00
|
|
|
bppchoices,
|
|
|
|
this);
|
|
|
|
if ( bppselection == -1 )
|
|
|
|
{
|
|
|
|
// cancelled
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-02-16 01:45:30 +00:00
|
|
|
image.SetOption(wxIMAGE_OPTION_BMP_FORMAT, bppvalues[bppselection]);
|
2001-08-25 15:30:49 +00:00
|
|
|
|
|
|
|
wxString deffilename = bppchoices[bppselection];
|
2001-09-21 20:21:44 +00:00
|
|
|
deffilename.Replace(wxT(" "), wxT("_"));
|
|
|
|
deffilename += wxT(".bmp");
|
|
|
|
wxString savefilename = wxFileSelector( wxT("Save Image"),
|
|
|
|
wxT(""),
|
2001-08-25 15:30:49 +00:00
|
|
|
deffilename,
|
2001-09-21 20:21:44 +00:00
|
|
|
(const wxChar *)NULL,
|
|
|
|
wxT("BMP files (*.bmp)|*.bmp|")
|
|
|
|
wxT("PNG files (*.png)|*.png|")
|
|
|
|
wxT("JPEG files (*.jpg)|*.jpg|")
|
|
|
|
wxT("GIF files (*.gif)|*.gif|")
|
|
|
|
wxT("TIFF files (*.tif)|*.tif|")
|
2002-02-02 23:16:09 +00:00
|
|
|
wxT("PCX files (*.pcx)|*.pcx|")
|
|
|
|
wxT("ICO files (*.ico)|*.ico|")
|
|
|
|
wxT("CUR files (*.cur)|*.cur"),
|
2001-08-25 15:30:49 +00:00
|
|
|
wxSAVE);
|
|
|
|
|
|
|
|
if ( savefilename.empty() )
|
|
|
|
return;
|
|
|
|
|
2002-02-16 01:45:30 +00:00
|
|
|
if ( image.GetOptionInt(wxIMAGE_OPTION_BMP_FORMAT) == wxBMP_8BPP_PALETTE )
|
2001-08-25 15:30:49 +00:00
|
|
|
{
|
|
|
|
unsigned char *cmap = new unsigned char [256];
|
|
|
|
for ( int i = 0; i < 256; i++ )
|
|
|
|
cmap[i] = i;
|
|
|
|
image.SetPalette(wxPalette(256, cmap, cmap, cmap));
|
|
|
|
|
|
|
|
delete cmap;
|
|
|
|
}
|
|
|
|
|
2002-03-17 11:35:32 +00:00
|
|
|
bool loaded;
|
2001-08-25 15:30:49 +00:00
|
|
|
wxString extension = savefilename.AfterLast('.').Lower();
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if (extension == _T("cur"))
|
2002-03-17 11:35:32 +00:00
|
|
|
{
|
2002-05-24 22:23:24 +00:00
|
|
|
image.Rescale(32,32);
|
|
|
|
image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 0);
|
2002-03-17 11:35:32 +00:00
|
|
|
image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 0);
|
|
|
|
// This shows how you can save an image with explicitly
|
|
|
|
// specified image format:
|
|
|
|
loaded = image.SaveFile(savefilename, wxBITMAP_TYPE_CUR);
|
|
|
|
}
|
2002-05-24 22:23:24 +00:00
|
|
|
else
|
2002-03-17 11:35:32 +00:00
|
|
|
{
|
|
|
|
// This one guesses image format from filename extension
|
|
|
|
// (it may fail if the extension is not recognized):
|
|
|
|
loaded = image.SaveFile(savefilename);
|
|
|
|
}
|
2002-05-24 22:23:24 +00:00
|
|
|
|
2002-03-17 11:35:32 +00:00
|
|
|
if ( !loaded )
|
2002-05-24 22:23:24 +00:00
|
|
|
wxMessageBox(_T("No handler for this file type."),
|
|
|
|
_T("File was not saved"),
|
2001-08-25 15:30:49 +00:00
|
|
|
wxOK|wxCENTRE, this);
|
|
|
|
}
|
|
|
|
|
2000-03-16 17:57:19 +00:00
|
|
|
private:
|
|
|
|
wxBitmap m_bitmap;
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
2003-03-22 19:10:09 +00:00
|
|
|
#ifdef wxHAVE_RAW_BITMAP
|
|
|
|
|
|
|
|
#include "wx/rawbmp.h"
|
|
|
|
|
|
|
|
class MyRawBitmapFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
BORDER = 15,
|
|
|
|
SIZE = 150,
|
|
|
|
REAL_SIZE = SIZE - 2*BORDER
|
|
|
|
};
|
|
|
|
|
|
|
|
MyRawBitmapFrame(wxFrame *parent)
|
|
|
|
: wxFrame(parent, -1, _T("Raw bitmaps (how exciting)")),
|
|
|
|
m_bitmap(SIZE, SIZE, 32)
|
|
|
|
{
|
|
|
|
SetClientSize(SIZE, SIZE);
|
|
|
|
|
|
|
|
wxRawBitmapData data(m_bitmap);
|
|
|
|
if ( !data )
|
|
|
|
{
|
|
|
|
wxLogError(_T("Failed to gain raw access to bitmap data"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxRawBitmapIterator p(data);
|
|
|
|
|
|
|
|
p.Offset(BORDER, BORDER);
|
|
|
|
|
|
|
|
for ( int y = 0; y < REAL_SIZE; ++y )
|
|
|
|
{
|
|
|
|
wxRawBitmapIterator rowStart = p;
|
|
|
|
|
|
|
|
int r = y < REAL_SIZE/3 ? 255 : 0,
|
|
|
|
g = (REAL_SIZE/3 <= y) && (y < 2*(REAL_SIZE/3)) ? 255 : 0,
|
|
|
|
b = 2*(REAL_SIZE/3) <= y ? 255 : 0;
|
|
|
|
|
|
|
|
for ( int x = 0; x < REAL_SIZE; ++x )
|
|
|
|
{
|
|
|
|
p.Red() = r;
|
|
|
|
p.Green() = g;
|
|
|
|
p.Blue() = b;
|
|
|
|
p.Alpha() = x;
|
|
|
|
|
|
|
|
++p; // same as p.OffsetX(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = rowStart;
|
|
|
|
p.OffsetY(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnPaint(wxPaintEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxPaintDC dc( this );
|
|
|
|
dc.DrawText(_T("This is alpha and raw bitmap test"), 0, BORDER);
|
|
|
|
dc.DrawText(_T("This is alpha and raw bitmap test"), 0, SIZE/2 - BORDER);
|
|
|
|
dc.DrawText(_T("This is alpha and raw bitmap test"), 0, SIZE - 2*BORDER);
|
|
|
|
dc.DrawBitmap( m_bitmap, 0, 0, TRUE /* use mask */ );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxBitmap m_bitmap;
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // wxHAVE_RAW_BITMAP
|
|
|
|
|
1998-10-24 17:12:05 +00:00
|
|
|
// MyApp
|
|
|
|
|
|
|
|
class MyApp: public wxApp
|
|
|
|
{
|
1999-01-12 23:51:13 +00:00
|
|
|
public:
|
|
|
|
virtual bool OnInit();
|
1998-10-24 17:12:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// main program
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// MyCanvas
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
|
|
|
|
|
2000-03-16 17:57:19 +00:00
|
|
|
BEGIN_EVENT_TABLE(MyImageFrame, wxFrame)
|
2003-03-04 02:10:27 +00:00
|
|
|
EVT_ERASE_BACKGROUND(MyImageFrame::OnEraseBackground)
|
|
|
|
EVT_PAINT(MyImageFrame::OnPaint)
|
|
|
|
EVT_LEFT_DCLICK(MyImageFrame::OnSave)
|
2000-03-16 17:57:19 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2003-03-22 19:10:09 +00:00
|
|
|
#ifdef wxHAVE_RAW_BITMAP
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyRawBitmapFrame, wxFrame)
|
|
|
|
EVT_PAINT(MyRawBitmapFrame::OnPaint)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
#endif // wxHAVE_RAW_BITMAP
|
|
|
|
|
1999-01-12 23:51:13 +00:00
|
|
|
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
|
|
|
EVT_PAINT(MyCanvas::OnPaint)
|
1998-10-24 17:12:05 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
1999-02-04 11:14:41 +00:00
|
|
|
MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
|
1999-01-12 23:51:13 +00:00
|
|
|
const wxPoint &pos, const wxSize &size )
|
2000-02-06 01:30:21 +00:00
|
|
|
: wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER )
|
|
|
|
#if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW
|
|
|
|
, m_bmpSmileXpm((const char **) smile_xpm)
|
|
|
|
, m_iconSmileXpm((const char **) smile_xpm)
|
|
|
|
#endif
|
1998-10-24 17:12:05 +00:00
|
|
|
{
|
1999-11-28 17:21:03 +00:00
|
|
|
my_horse_png = (wxBitmap*) NULL;
|
|
|
|
my_horse_jpeg = (wxBitmap*) NULL;
|
|
|
|
my_horse_gif = (wxBitmap*) NULL;
|
|
|
|
my_horse_bmp = (wxBitmap*) NULL;
|
2002-05-24 22:23:24 +00:00
|
|
|
my_horse_bmp2 = (wxBitmap*) NULL;
|
1999-11-28 17:21:03 +00:00
|
|
|
my_horse_pcx = (wxBitmap*) NULL;
|
|
|
|
my_horse_pnm = (wxBitmap*) NULL;
|
|
|
|
my_horse_tiff = (wxBitmap*) NULL;
|
2001-04-28 23:30:11 +00:00
|
|
|
my_horse_xpm = (wxBitmap*) NULL;
|
2002-02-02 23:16:09 +00:00
|
|
|
my_horse_ico32 = (wxBitmap*) NULL;
|
|
|
|
my_horse_ico16 = (wxBitmap*) NULL;
|
|
|
|
my_horse_ico = (wxBitmap*) NULL;
|
|
|
|
my_horse_cur = (wxBitmap*) NULL;
|
2002-12-04 14:11:26 +00:00
|
|
|
my_horse_ani = (wxBitmap*) NULL;
|
2002-02-02 23:16:09 +00:00
|
|
|
|
1999-12-14 16:53:41 +00:00
|
|
|
my_smile_xbm = (wxBitmap*) NULL;
|
1999-11-28 17:21:03 +00:00
|
|
|
my_square = (wxBitmap*) NULL;
|
|
|
|
my_anti = (wxBitmap*) NULL;
|
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
m_ani_images = 0 ;
|
|
|
|
|
1999-11-28 17:21:03 +00:00
|
|
|
SetBackgroundColour(* wxWHITE);
|
|
|
|
|
|
|
|
wxBitmap bitmap( 100, 100 );
|
|
|
|
|
|
|
|
wxMemoryDC dc;
|
|
|
|
dc.SelectObject( bitmap );
|
2001-11-22 09:11:33 +00:00
|
|
|
dc.SetBrush( wxBrush( wxT("orange"), wxSOLID ) );
|
2000-01-14 20:29:01 +00:00
|
|
|
dc.SetPen( *wxBLACK_PEN );
|
1999-11-28 17:21:03 +00:00
|
|
|
dc.DrawRectangle( 0, 0, 100, 100 );
|
2000-01-14 20:29:01 +00:00
|
|
|
dc.SetBrush( *wxWHITE_BRUSH );
|
|
|
|
dc.DrawRectangle( 20, 20, 60, 60 );
|
1999-11-28 17:21:03 +00:00
|
|
|
dc.SelectObject( wxNullBitmap );
|
|
|
|
|
|
|
|
// try to find the directory with our images
|
|
|
|
wxString dir;
|
2001-09-21 20:21:44 +00:00
|
|
|
if ( wxFile::Exists(wxT("./horse.png")) )
|
2002-12-04 14:11:26 +00:00
|
|
|
dir = wxT("./");
|
2001-09-21 20:21:44 +00:00
|
|
|
else if ( wxFile::Exists(wxT("../horse.png")) )
|
2002-12-04 14:11:26 +00:00
|
|
|
dir = wxT("../");
|
1999-11-28 17:21:03 +00:00
|
|
|
else
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogWarning(wxT("Can't find image files in either '.' or '..'!"));
|
1999-11-28 17:21:03 +00:00
|
|
|
|
2001-04-22 22:25:18 +00:00
|
|
|
wxImage image = bitmap.ConvertToImage();
|
1999-11-28 17:21:03 +00:00
|
|
|
|
2000-01-21 21:40:10 +00:00
|
|
|
#if wxUSE_LIBPNG
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.SaveFile( dir + _T("test.png"), wxBITMAP_TYPE_PNG ))
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogError(wxT("Can't save file"));
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2000-02-19 04:22:08 +00:00
|
|
|
image.Destroy();
|
1999-11-28 17:21:03 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
image.LoadFile( dir + _T("test.png") );
|
2001-04-22 22:25:18 +00:00
|
|
|
my_square = new wxBitmap( image );
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2000-02-19 04:22:08 +00:00
|
|
|
image.Destroy();
|
2000-02-15 12:56:16 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.png")) )
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogError(wxT("Can't load PNG image"));
|
1999-11-28 17:21:03 +00:00
|
|
|
else
|
2001-04-22 22:25:18 +00:00
|
|
|
my_horse_png = new wxBitmap( image );
|
2000-01-21 21:40:10 +00:00
|
|
|
#endif // wxUSE_LIBPNG
|
1999-11-28 17:21:03 +00:00
|
|
|
|
2000-01-21 21:40:10 +00:00
|
|
|
#if wxUSE_LIBJPEG
|
2000-02-19 04:22:08 +00:00
|
|
|
image.Destroy();
|
2000-02-10 18:43:33 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.jpg")) )
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogError(wxT("Can't load JPG image"));
|
1999-11-28 17:21:03 +00:00
|
|
|
else
|
2001-04-28 23:30:11 +00:00
|
|
|
my_horse_jpeg = new wxBitmap( image );
|
2000-01-21 21:40:10 +00:00
|
|
|
#endif // wxUSE_LIBJPEG
|
1999-11-06 10:39:19 +00:00
|
|
|
|
|
|
|
#if wxUSE_GIF
|
2000-02-19 04:22:08 +00:00
|
|
|
image.Destroy();
|
2000-02-10 18:43:33 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.gif" )) )
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogError(wxT("Can't load GIF image"));
|
1999-11-28 17:21:03 +00:00
|
|
|
else
|
2001-04-28 23:30:11 +00:00
|
|
|
my_horse_gif = new wxBitmap( image );
|
1999-11-06 10:39:19 +00:00
|
|
|
#endif
|
1999-08-27 11:42:47 +00:00
|
|
|
|
1999-11-06 10:39:19 +00:00
|
|
|
#if wxUSE_PCX
|
2000-02-19 04:22:08 +00:00
|
|
|
image.Destroy();
|
2000-02-10 18:43:33 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.pcx"), wxBITMAP_TYPE_PCX ) )
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogError(wxT("Can't load PCX image"));
|
1999-11-28 17:21:03 +00:00
|
|
|
else
|
2001-04-28 23:30:11 +00:00
|
|
|
my_horse_pcx = new wxBitmap( image );
|
1999-11-06 10:39:19 +00:00
|
|
|
#endif
|
1999-08-27 11:42:47 +00:00
|
|
|
|
2000-02-19 04:22:08 +00:00
|
|
|
image.Destroy();
|
2000-02-10 18:43:33 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.bmp"), wxBITMAP_TYPE_BMP ) )
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogError(wxT("Can't load BMP image"));
|
1999-11-28 17:21:03 +00:00
|
|
|
else
|
2001-04-28 23:30:11 +00:00
|
|
|
my_horse_bmp = new wxBitmap( image );
|
1999-08-29 19:48:03 +00:00
|
|
|
|
2001-04-22 22:25:18 +00:00
|
|
|
#if wxUSE_XPM
|
2001-04-28 23:30:11 +00:00
|
|
|
image.Destroy();
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.xpm"), wxBITMAP_TYPE_XPM ) )
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogError(wxT("Can't load XPM image"));
|
2001-04-28 23:30:11 +00:00
|
|
|
else
|
|
|
|
my_horse_xpm = new wxBitmap( image );
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.SaveFile( dir + _T("test.xpm"), wxBITMAP_TYPE_XPM ))
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogError(wxT("Can't save file"));
|
2001-04-22 22:25:18 +00:00
|
|
|
#endif
|
|
|
|
|
1999-11-06 10:39:19 +00:00
|
|
|
#if wxUSE_PNM
|
2000-02-19 04:22:08 +00:00
|
|
|
image.Destroy();
|
2000-02-10 18:43:33 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.pnm"), wxBITMAP_TYPE_PNM ) )
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogError(wxT("Can't load PNM image"));
|
1999-11-28 17:21:03 +00:00
|
|
|
else
|
2001-04-28 23:30:11 +00:00
|
|
|
my_horse_pnm = new wxBitmap( image );
|
1999-11-06 10:39:19 +00:00
|
|
|
#endif
|
1999-11-25 23:28:41 +00:00
|
|
|
|
1999-11-28 17:21:03 +00:00
|
|
|
#if wxUSE_LIBTIFF
|
2000-02-19 04:22:08 +00:00
|
|
|
image.Destroy();
|
2000-02-10 18:43:33 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.tif"), wxBITMAP_TYPE_TIF ) )
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogError(wxT("Can't load TIFF image"));
|
1999-11-28 17:21:03 +00:00
|
|
|
else
|
2001-04-28 23:30:11 +00:00
|
|
|
my_horse_tiff = new wxBitmap( image );
|
1999-11-28 17:21:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
CreateAntiAliasedBitmap();
|
1999-12-14 16:53:41 +00:00
|
|
|
|
|
|
|
my_smile_xbm = new wxBitmap( (const char*)smile_bits, smile_width,
|
|
|
|
smile_height, 1 );
|
2000-02-01 18:12:29 +00:00
|
|
|
|
2000-02-06 01:30:21 +00:00
|
|
|
#if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW
|
2000-02-01 18:12:29 +00:00
|
|
|
// demonstrates XPM automatically using the mask when saving
|
|
|
|
if ( m_bmpSmileXpm.Ok() )
|
2002-05-24 22:23:24 +00:00
|
|
|
m_bmpSmileXpm.SaveFile(_T("saved.xpm"), wxBITMAP_TYPE_XPM);
|
2000-02-06 01:30:21 +00:00
|
|
|
#endif
|
2002-02-02 23:16:09 +00:00
|
|
|
|
|
|
|
#if wxUSE_ICO_CUR
|
|
|
|
image.Destroy();
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.ico"), wxBITMAP_TYPE_ICO, 0 ) )
|
2002-02-02 23:16:09 +00:00
|
|
|
wxLogError(wxT("Can't load first ICO image"));
|
|
|
|
else
|
|
|
|
my_horse_ico32 = new wxBitmap( image );
|
2002-05-24 22:23:24 +00:00
|
|
|
|
2002-02-02 23:16:09 +00:00
|
|
|
image.Destroy();
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.ico"), wxBITMAP_TYPE_ICO, 1 ) )
|
2002-02-02 23:16:09 +00:00
|
|
|
wxLogError(wxT("Can't load second ICO image"));
|
|
|
|
else
|
|
|
|
my_horse_ico16 = new wxBitmap( image );
|
|
|
|
|
|
|
|
image.Destroy();
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.ico") ) )
|
2002-02-02 23:16:09 +00:00
|
|
|
wxLogError(wxT("Can't load best ICO image"));
|
|
|
|
else
|
|
|
|
my_horse_ico = new wxBitmap( image );
|
|
|
|
|
|
|
|
image.Destroy();
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
if ( !image.LoadFile( dir + _T("horse.cur"), wxBITMAP_TYPE_CUR ) )
|
2002-02-02 23:16:09 +00:00
|
|
|
wxLogError(wxT("Can't load best ICO image"));
|
|
|
|
else
|
2002-05-24 22:23:24 +00:00
|
|
|
{
|
2002-02-02 23:16:09 +00:00
|
|
|
my_horse_cur = new wxBitmap( image );
|
2002-02-16 01:45:30 +00:00
|
|
|
xH = 30 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X) ;
|
|
|
|
yH = 2420 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ;
|
2002-05-24 22:23:24 +00:00
|
|
|
}
|
2002-12-04 14:11:26 +00:00
|
|
|
|
2002-12-05 10:19:00 +00:00
|
|
|
m_ani_images = wxImage::GetImageCount ( dir + _T("horse3.ani"), wxBITMAP_TYPE_ANI );
|
2002-12-04 14:11:26 +00:00
|
|
|
if (m_ani_images==0)
|
|
|
|
wxLogError(wxT("No ANI-format images found"));
|
|
|
|
else
|
|
|
|
my_horse_ani = new wxBitmap [m_ani_images];
|
|
|
|
int i ;
|
|
|
|
for (i=0; i < m_ani_images; i++)
|
|
|
|
{
|
|
|
|
image.Destroy();
|
2002-12-05 10:19:00 +00:00
|
|
|
if (!image.LoadFile( dir + _T("horse3.ani"), wxBITMAP_TYPE_ANI, i ))
|
2002-12-04 14:11:26 +00:00
|
|
|
{
|
|
|
|
wxString tmp = wxT("Can't load image number ");
|
|
|
|
tmp << i ;
|
|
|
|
wxLogError(tmp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
my_horse_ani [i] = wxBitmap( image );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-02 23:16:09 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
image.Destroy();
|
|
|
|
|
|
|
|
// test image loading from stream
|
|
|
|
wxFile file(dir + _T("horse.bmp"));
|
|
|
|
off_t len = file.Length();
|
|
|
|
void *data = malloc(len);
|
|
|
|
if ( file.Read(data, len) != len )
|
|
|
|
wxLogError(_T("Reading bitmap file failed"));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMemoryInputStream mis(data, len);
|
|
|
|
if ( !image.LoadFile(mis) )
|
|
|
|
wxLogError(wxT("Can't load BMP image from stream"));
|
|
|
|
else
|
|
|
|
my_horse_bmp2 = new wxBitmap( image );
|
|
|
|
}
|
|
|
|
|
|
|
|
free(data);
|
1998-10-24 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
1999-01-12 23:51:13 +00:00
|
|
|
MyCanvas::~MyCanvas()
|
1998-10-24 17:12:05 +00:00
|
|
|
{
|
1999-11-28 17:21:03 +00:00
|
|
|
delete my_horse_pnm;
|
|
|
|
delete my_horse_png;
|
|
|
|
delete my_horse_jpeg;
|
|
|
|
delete my_horse_gif;
|
|
|
|
delete my_horse_bmp;
|
2002-05-24 22:23:24 +00:00
|
|
|
delete my_horse_bmp2;
|
1999-11-28 17:21:03 +00:00
|
|
|
delete my_horse_pcx;
|
|
|
|
delete my_horse_tiff;
|
2001-04-28 23:30:11 +00:00
|
|
|
delete my_horse_xpm;
|
2002-02-02 23:16:09 +00:00
|
|
|
delete my_horse_ico32;
|
|
|
|
delete my_horse_ico16;
|
|
|
|
delete my_horse_ico;
|
2002-03-17 14:16:03 +00:00
|
|
|
delete my_horse_cur;
|
2002-12-04 14:11:26 +00:00
|
|
|
delete [] my_horse_ani;
|
1999-12-14 16:53:41 +00:00
|
|
|
delete my_smile_xbm;
|
1999-11-28 17:21:03 +00:00
|
|
|
delete my_square;
|
|
|
|
delete my_anti;
|
1998-10-24 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|
|
|
{
|
1999-12-27 13:01:07 +00:00
|
|
|
wxPaintDC dc( this );
|
|
|
|
PrepareDC( dc );
|
1999-02-11 16:00:33 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("Loaded image"), 30, 10 );
|
1999-12-27 13:01:07 +00:00
|
|
|
if (my_square && my_square->Ok()) dc.DrawBitmap( *my_square, 30, 30 );
|
1999-11-25 23:28:41 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("Drawn directly"), 150, 10 );
|
2001-11-22 09:11:33 +00:00
|
|
|
dc.SetBrush( wxBrush( wxT("orange"), wxSOLID ) );
|
2000-01-14 20:29:01 +00:00
|
|
|
dc.SetPen( *wxBLACK_PEN );
|
1999-12-27 13:01:07 +00:00
|
|
|
dc.DrawRectangle( 150, 30, 100, 100 );
|
2000-01-14 20:29:01 +00:00
|
|
|
dc.SetBrush( *wxWHITE_BRUSH );
|
|
|
|
dc.DrawRectangle( 170, 50, 60, 60 );
|
1999-12-27 13:01:07 +00:00
|
|
|
|
2000-01-15 01:52:26 +00:00
|
|
|
if (my_anti && my_anti->Ok())
|
1999-12-27 13:01:07 +00:00
|
|
|
dc.DrawBitmap( *my_anti, 280, 30 );
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("PNG handler"), 30, 135 );
|
1999-12-27 13:01:07 +00:00
|
|
|
if (my_horse_png && my_horse_png->Ok())
|
2000-01-15 01:52:26 +00:00
|
|
|
{
|
1999-12-27 13:01:07 +00:00
|
|
|
dc.DrawBitmap( *my_horse_png, 30, 150 );
|
|
|
|
wxRect rect(0,0,100,100);
|
|
|
|
wxBitmap sub( my_horse_png->GetSubBitmap(rect) );
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("GetSubBitmap()"), 280, 190 );
|
1999-12-27 13:01:07 +00:00
|
|
|
dc.DrawBitmap( sub, 280, 210 );
|
|
|
|
}
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("JPEG handler"), 30, 365 );
|
2000-01-15 01:52:26 +00:00
|
|
|
if (my_horse_jpeg && my_horse_jpeg->Ok())
|
1999-12-27 13:01:07 +00:00
|
|
|
dc.DrawBitmap( *my_horse_jpeg, 30, 380 );
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("GIF handler"), 30, 595 );
|
2000-01-15 01:52:26 +00:00
|
|
|
if (my_horse_gif && my_horse_gif->Ok())
|
1999-12-27 13:01:07 +00:00
|
|
|
dc.DrawBitmap( *my_horse_gif, 30, 610 );
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("PCX handler"), 30, 825 );
|
2000-01-15 01:52:26 +00:00
|
|
|
if (my_horse_pcx && my_horse_pcx->Ok())
|
1999-12-27 13:01:07 +00:00
|
|
|
dc.DrawBitmap( *my_horse_pcx, 30, 840 );
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("BMP handler"), 30, 1055 );
|
2000-01-15 01:52:26 +00:00
|
|
|
if (my_horse_bmp && my_horse_bmp->Ok())
|
1999-12-27 13:01:07 +00:00
|
|
|
dc.DrawBitmap( *my_horse_bmp, 30, 1070 );
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("BMP read from memory"), 280, 1055 );
|
|
|
|
if (my_horse_bmp2 && my_horse_bmp2->Ok())
|
|
|
|
dc.DrawBitmap( *my_horse_bmp2, 280, 1070 );
|
|
|
|
|
|
|
|
dc.DrawText( _T("PNM handler"), 30, 1285 );
|
2000-01-15 01:52:26 +00:00
|
|
|
if (my_horse_pnm && my_horse_pnm->Ok())
|
1999-12-27 13:01:07 +00:00
|
|
|
dc.DrawBitmap( *my_horse_pnm, 30, 1300 );
|
2000-01-15 01:52:26 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("TIFF handler"), 30, 1515 );
|
2000-01-15 01:52:26 +00:00
|
|
|
if (my_horse_tiff && my_horse_tiff->Ok())
|
2000-01-14 15:35:40 +00:00
|
|
|
dc.DrawBitmap( *my_horse_tiff, 30, 1530 );
|
1999-12-27 13:01:07 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("XPM handler"), 30, 1745 );
|
2001-04-28 23:30:11 +00:00
|
|
|
if (my_horse_xpm && my_horse_xpm->Ok())
|
|
|
|
dc.DrawBitmap( *my_horse_xpm, 30, 1760 );
|
|
|
|
|
2002-02-02 23:16:09 +00:00
|
|
|
|
2000-01-15 01:52:26 +00:00
|
|
|
if (my_smile_xbm && my_smile_xbm->Ok())
|
1999-12-27 13:01:07 +00:00
|
|
|
{
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("XBM bitmap"), 30, 1975 );
|
|
|
|
dc.DrawText( _T("(green on red)"), 30, 1990 );
|
|
|
|
dc.SetTextForeground( _T("GREEN") );
|
|
|
|
dc.SetTextBackground( _T("RED") );
|
2001-04-28 23:30:11 +00:00
|
|
|
dc.DrawBitmap( *my_smile_xbm, 30, 2010 );
|
2000-01-15 01:52:26 +00:00
|
|
|
|
2001-11-22 09:11:33 +00:00
|
|
|
dc.SetTextForeground( wxT("BLACK") );
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("After wxImage conversion"), 150, 1975 );
|
|
|
|
dc.DrawText( _T("(red on white)"), 150, 1990 );
|
2001-11-22 09:11:33 +00:00
|
|
|
dc.SetTextForeground( wxT("RED") );
|
2001-04-22 22:25:18 +00:00
|
|
|
wxImage i = my_smile_xbm->ConvertToImage();
|
2000-02-19 04:22:08 +00:00
|
|
|
i.SetMaskColour( 255, 255, 255 );
|
|
|
|
i.Replace( 0, 0, 0,
|
1999-12-27 13:01:07 +00:00
|
|
|
wxRED_PEN->GetColour().Red(),
|
|
|
|
wxRED_PEN->GetColour().Green(),
|
|
|
|
wxRED_PEN->GetColour().Blue() );
|
2002-03-24 00:22:15 +00:00
|
|
|
dc.DrawBitmap( wxBitmap(i), 150, 2010, TRUE );
|
2001-11-22 09:11:33 +00:00
|
|
|
dc.SetTextForeground( wxT("BLACK") );
|
1999-12-27 13:01:07 +00:00
|
|
|
}
|
2000-02-19 04:22:08 +00:00
|
|
|
|
2000-01-15 01:52:26 +00:00
|
|
|
|
2000-01-15 10:39:27 +00:00
|
|
|
wxBitmap mono( 60,50,1 );
|
2000-01-12 17:57:18 +00:00
|
|
|
wxMemoryDC memdc;
|
|
|
|
memdc.SelectObject( mono );
|
2000-02-01 18:12:29 +00:00
|
|
|
memdc.SetPen( *wxBLACK_PEN );
|
2000-01-12 17:57:18 +00:00
|
|
|
memdc.SetBrush( *wxWHITE_BRUSH );
|
2000-01-15 10:39:27 +00:00
|
|
|
memdc.DrawRectangle( 0,0,60,50 );
|
|
|
|
memdc.SetTextForeground( *wxBLACK );
|
2002-05-24 22:23:24 +00:00
|
|
|
memdc.DrawText( _T("Hi!"), 5, 5 );
|
2000-01-15 10:39:27 +00:00
|
|
|
memdc.SetBrush( *wxBLACK_BRUSH );
|
|
|
|
memdc.DrawRectangle( 33,5,20,20 );
|
|
|
|
memdc.SetPen( *wxRED_PEN );
|
|
|
|
memdc.DrawLine( 5, 42, 50, 42 );
|
2000-01-12 17:57:18 +00:00
|
|
|
memdc.SelectObject( wxNullBitmap );
|
2000-02-19 04:22:08 +00:00
|
|
|
|
2000-01-15 01:52:26 +00:00
|
|
|
if (mono.Ok())
|
2000-01-12 17:57:18 +00:00
|
|
|
{
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("Mono bitmap"), 30, 2095 );
|
|
|
|
dc.DrawText( _T("(red on green)"), 30, 2110 );
|
2001-11-22 09:11:33 +00:00
|
|
|
dc.SetTextForeground( wxT("RED") );
|
|
|
|
dc.SetTextBackground( wxT("GREEN") );
|
2001-04-28 23:30:11 +00:00
|
|
|
dc.DrawBitmap( mono, 30, 2130 );
|
2000-01-15 01:52:26 +00:00
|
|
|
|
2001-11-22 09:11:33 +00:00
|
|
|
dc.SetTextForeground( wxT("BLACK") );
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("After wxImage conversion"), 150, 2095 );
|
|
|
|
dc.DrawText( _T("(red on white)"), 150, 2110 );
|
2001-11-22 09:11:33 +00:00
|
|
|
dc.SetTextForeground( wxT("RED") );
|
2001-04-22 22:25:18 +00:00
|
|
|
wxImage i = mono.ConvertToImage();
|
2000-01-15 01:52:26 +00:00
|
|
|
i.SetMaskColour( 255,255,255 );
|
|
|
|
i.Replace( 0,0,0,
|
2000-01-12 17:57:18 +00:00
|
|
|
wxRED_PEN->GetColour().Red(),
|
|
|
|
wxRED_PEN->GetColour().Green(),
|
|
|
|
wxRED_PEN->GetColour().Blue() );
|
2002-03-24 00:22:15 +00:00
|
|
|
dc.DrawBitmap( wxBitmap(i), 150, 2130, TRUE );
|
2001-11-22 09:11:33 +00:00
|
|
|
dc.SetTextForeground( wxT("BLACK") );
|
2000-01-21 21:40:10 +00:00
|
|
|
}
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText(_T("XPM bitmap"), 30, 2230);
|
2000-01-21 21:40:10 +00:00
|
|
|
if ( m_bmpSmileXpm.Ok() )
|
|
|
|
{
|
2001-04-28 23:30:11 +00:00
|
|
|
dc.DrawBitmap(m_bmpSmileXpm, 30, 2250, TRUE);
|
2000-01-21 21:40:10 +00:00
|
|
|
}
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText(_T("XPM icon"), 150, 2230);
|
2000-01-21 21:40:10 +00:00
|
|
|
if ( m_iconSmileXpm.Ok() )
|
|
|
|
{
|
2001-04-28 23:30:11 +00:00
|
|
|
dc.DrawIcon(m_iconSmileXpm, 150, 2250);
|
2000-01-12 17:57:18 +00:00
|
|
|
}
|
2002-02-02 23:16:09 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("ICO handler (1st image)"), 30, 2290 );
|
2002-02-02 23:16:09 +00:00
|
|
|
if (my_horse_ico32 && my_horse_ico32->Ok())
|
|
|
|
dc.DrawBitmap( *my_horse_ico32, 30, 2330, TRUE );
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("ICO handler (2nd image)"), 230, 2290 );
|
2002-02-02 23:16:09 +00:00
|
|
|
if (my_horse_ico16 && my_horse_ico16->Ok())
|
|
|
|
dc.DrawBitmap( *my_horse_ico16, 230, 2330, TRUE );
|
2002-05-24 22:23:24 +00:00
|
|
|
|
|
|
|
dc.DrawText( _T("ICO handler (best image)"), 430, 2290 );
|
2002-02-02 23:16:09 +00:00
|
|
|
if (my_horse_ico && my_horse_ico->Ok())
|
|
|
|
dc.DrawBitmap( *my_horse_ico, 430, 2330, TRUE );
|
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("CUR handler"), 30, 2390 );
|
2002-02-02 23:16:09 +00:00
|
|
|
if (my_horse_cur && my_horse_cur->Ok())
|
2002-05-24 22:23:24 +00:00
|
|
|
{
|
2002-02-02 23:16:09 +00:00
|
|
|
dc.DrawBitmap( *my_horse_cur, 30, 2420, TRUE );
|
|
|
|
dc.SetPen (*wxRED_PEN);
|
|
|
|
dc.DrawLine (xH-10,yH,xH+10,yH);
|
|
|
|
dc.DrawLine (xH,yH-10,xH,yH+10);
|
2002-05-24 22:23:24 +00:00
|
|
|
}
|
2002-12-04 14:11:26 +00:00
|
|
|
dc.DrawText( _T("ANI handler"), 230, 2390 );
|
|
|
|
int i ;
|
|
|
|
for (i=0; i < m_ani_images; i ++)
|
|
|
|
if (my_horse_ani[i].Ok())
|
|
|
|
{
|
|
|
|
dc.DrawBitmap( my_horse_ani[i], 230 + i * 2 * my_horse_ani[i].GetWidth() , 2420, TRUE );
|
|
|
|
}
|
1999-01-22 18:08:54 +00:00
|
|
|
}
|
1999-01-12 23:51:13 +00:00
|
|
|
|
1999-01-22 18:08:54 +00:00
|
|
|
void MyCanvas::CreateAntiAliasedBitmap()
|
|
|
|
{
|
|
|
|
wxBitmap bitmap( 300, 300 );
|
1999-02-11 16:00:33 +00:00
|
|
|
|
1999-01-22 18:08:54 +00:00
|
|
|
wxMemoryDC dc;
|
1999-02-11 16:00:33 +00:00
|
|
|
|
1999-01-22 18:08:54 +00:00
|
|
|
dc.SelectObject( bitmap );
|
1999-02-11 16:00:33 +00:00
|
|
|
|
1999-01-22 18:08:54 +00:00
|
|
|
dc.Clear();
|
1999-11-25 23:28:41 +00:00
|
|
|
|
1999-11-06 10:39:19 +00:00
|
|
|
dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL) );
|
2001-11-22 09:11:33 +00:00
|
|
|
dc.SetTextForeground( wxT("RED") );
|
2002-05-24 22:23:24 +00:00
|
|
|
dc.DrawText( _T("This is anti-aliased Text."), 20, 20 );
|
|
|
|
dc.DrawText( _T("And a Rectangle."), 20, 60 );
|
1999-11-25 23:28:41 +00:00
|
|
|
|
1999-01-22 18:08:54 +00:00
|
|
|
dc.SetBrush( *wxRED_BRUSH );
|
1999-06-13 15:24:01 +00:00
|
|
|
dc.SetPen( *wxTRANSPARENT_PEN );
|
1999-01-22 18:08:54 +00:00
|
|
|
dc.DrawRoundedRectangle( 20, 100, 200, 180, 20 );
|
1999-11-25 23:28:41 +00:00
|
|
|
|
2001-04-22 22:25:18 +00:00
|
|
|
wxImage original= bitmap.ConvertToImage();
|
1999-01-22 18:08:54 +00:00
|
|
|
wxImage anti( 150, 150 );
|
1999-02-11 16:00:33 +00:00
|
|
|
|
1999-01-22 18:08:54 +00:00
|
|
|
/* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */
|
1999-11-25 23:28:41 +00:00
|
|
|
|
1999-01-22 18:08:54 +00:00
|
|
|
for (int y = 1; y < 149; y++)
|
|
|
|
for (int x = 1; x < 149; x++)
|
|
|
|
{
|
|
|
|
int red = original.GetRed( x*2, y*2 ) +
|
1999-11-25 23:28:41 +00:00
|
|
|
original.GetRed( x*2-1, y*2 ) +
|
|
|
|
original.GetRed( x*2, y*2+1 ) +
|
1999-01-22 18:08:54 +00:00
|
|
|
original.GetRed( x*2+1, y*2+1 );
|
1999-11-25 23:28:41 +00:00
|
|
|
red = red/4;
|
|
|
|
|
1999-01-22 18:08:54 +00:00
|
|
|
int green = original.GetGreen( x*2, y*2 ) +
|
1999-11-25 23:28:41 +00:00
|
|
|
original.GetGreen( x*2-1, y*2 ) +
|
|
|
|
original.GetGreen( x*2, y*2+1 ) +
|
1999-01-22 18:08:54 +00:00
|
|
|
original.GetGreen( x*2+1, y*2+1 );
|
1999-11-25 23:28:41 +00:00
|
|
|
green = green/4;
|
|
|
|
|
1999-01-22 18:08:54 +00:00
|
|
|
int blue = original.GetBlue( x*2, y*2 ) +
|
1999-11-25 23:28:41 +00:00
|
|
|
original.GetBlue( x*2-1, y*2 ) +
|
|
|
|
original.GetBlue( x*2, y*2+1 ) +
|
1999-01-22 18:08:54 +00:00
|
|
|
original.GetBlue( x*2+1, y*2+1 );
|
1999-11-25 23:28:41 +00:00
|
|
|
blue = blue/4;
|
1999-01-22 18:08:54 +00:00
|
|
|
anti.SetRGB( x, y, red, green, blue );
|
|
|
|
}
|
2002-03-24 00:22:15 +00:00
|
|
|
my_anti = new wxBitmap(anti);
|
1998-10-24 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MyFrame
|
|
|
|
|
2003-03-22 19:10:09 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ID_QUIT = 108,
|
|
|
|
ID_ABOUT,
|
|
|
|
ID_NEW,
|
|
|
|
ID_SHOWRAW
|
|
|
|
};
|
1998-10-24 17:12:05 +00:00
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
|
|
|
|
EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU (ID_QUIT, MyFrame::OnQuit)
|
2000-03-16 17:57:19 +00:00
|
|
|
EVT_MENU (ID_NEW, MyFrame::OnNewFrame)
|
2003-03-22 19:10:09 +00:00
|
|
|
#ifdef wxHAVE_RAW_BITMAP
|
|
|
|
EVT_MENU (ID_SHOWRAW, MyFrame::OnTestRawBitmap)
|
|
|
|
#endif
|
1998-10-24 17:12:05 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
1999-01-12 23:51:13 +00:00
|
|
|
MyFrame::MyFrame()
|
2002-05-24 22:23:24 +00:00
|
|
|
: wxFrame( (wxFrame *)NULL, -1, _T("wxImage sample"),
|
1999-01-12 23:51:13 +00:00
|
|
|
wxPoint(20,20), wxSize(470,360) )
|
1998-10-24 17:12:05 +00:00
|
|
|
{
|
|
|
|
wxMenu *file_menu = new wxMenu();
|
2003-03-22 19:10:09 +00:00
|
|
|
file_menu->Append( ID_NEW, _T("&Show image...\tCtrl-O"));
|
|
|
|
#ifdef wxHAVE_RAW_BITMAP
|
|
|
|
file_menu->Append( ID_SHOWRAW, _T("Test &raw bitmap...\tCtrl-R"));
|
|
|
|
#endif
|
2000-03-16 17:57:19 +00:00
|
|
|
file_menu->AppendSeparator();
|
2002-05-24 22:23:24 +00:00
|
|
|
file_menu->Append( ID_ABOUT, _T("&About..."));
|
2000-03-16 17:57:19 +00:00
|
|
|
file_menu->AppendSeparator();
|
2003-03-22 19:10:09 +00:00
|
|
|
file_menu->Append( ID_QUIT, _T("E&xit\tCtrl-Q"));
|
1999-01-12 23:51:13 +00:00
|
|
|
|
1998-10-24 17:12:05 +00:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar();
|
2002-05-24 22:23:24 +00:00
|
|
|
menu_bar->Append(file_menu, _T("&File"));
|
1999-01-09 20:18:06 +00:00
|
|
|
|
1998-10-24 17:12:05 +00:00
|
|
|
SetMenuBar( menu_bar );
|
1999-01-12 23:51:13 +00:00
|
|
|
|
1998-11-10 19:43:04 +00:00
|
|
|
CreateStatusBar(2);
|
|
|
|
int widths[] = { -1, 100 };
|
|
|
|
SetStatusWidths( 2, widths );
|
1999-01-12 23:51:13 +00:00
|
|
|
|
1998-11-11 14:19:46 +00:00
|
|
|
m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
|
1999-08-27 11:42:47 +00:00
|
|
|
|
2002-02-02 23:16:09 +00:00
|
|
|
// 500 width * 2500 height
|
|
|
|
m_canvas->SetScrollbars( 10, 10, 50, 250 );
|
1998-10-24 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
Close( TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
2002-05-24 22:23:24 +00:00
|
|
|
(void)wxMessageBox( _T("wxImage demo\n")
|
|
|
|
_T("Robert Roebling (c) 1998,2000"),
|
|
|
|
_T("About wxImage Demo"), wxICON_INFORMATION | wxOK );
|
1998-11-11 14:19:46 +00:00
|
|
|
}
|
|
|
|
|
2000-03-16 17:57:19 +00:00
|
|
|
void MyFrame::OnNewFrame( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
wxString filename = wxFileSelector(_T("Select image file"));
|
|
|
|
if ( !filename )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxImage image;
|
|
|
|
if ( !image.LoadFile(filename) )
|
|
|
|
{
|
|
|
|
wxLogError(_T("Couldn't load image from '%s'."), filename.c_str());
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-24 00:22:15 +00:00
|
|
|
(new MyImageFrame(this, wxBitmap(image)))->Show();
|
2000-03-16 17:57:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-22 19:10:09 +00:00
|
|
|
#ifdef wxHAVE_RAW_BITMAP
|
|
|
|
|
|
|
|
void MyFrame::OnTestRawBitmap( wxCommandEvent &event )
|
|
|
|
{
|
|
|
|
(new MyRawBitmapFrame(this))->Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxHAVE_RAW_BITMAP
|
|
|
|
|
1998-10-24 17:12:05 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1999-01-12 23:51:13 +00:00
|
|
|
bool MyApp::OnInit()
|
1998-10-24 17:12:05 +00:00
|
|
|
{
|
1999-04-06 13:44:37 +00:00
|
|
|
#if wxUSE_LIBPNG
|
|
|
|
wxImage::AddHandler( new wxPNGHandler );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if wxUSE_LIBJPEG
|
|
|
|
wxImage::AddHandler( new wxJPEGHandler );
|
|
|
|
#endif
|
|
|
|
|
1999-11-28 17:21:03 +00:00
|
|
|
#if wxUSE_LIBTIFF
|
|
|
|
wxImage::AddHandler( new wxTIFFHandler );
|
|
|
|
#endif
|
|
|
|
|
1999-11-06 10:39:19 +00:00
|
|
|
#if wxUSE_GIF
|
1999-04-17 17:54:07 +00:00
|
|
|
wxImage::AddHandler( new wxGIFHandler );
|
1999-11-06 10:39:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if wxUSE_PCX
|
1999-08-27 11:42:47 +00:00
|
|
|
wxImage::AddHandler( new wxPCXHandler );
|
1999-11-06 10:39:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if wxUSE_PNM
|
1999-08-29 19:48:03 +00:00
|
|
|
wxImage::AddHandler( new wxPNMHandler );
|
1999-11-06 10:39:19 +00:00
|
|
|
#endif
|
1999-04-17 17:54:07 +00:00
|
|
|
|
2001-04-22 22:25:18 +00:00
|
|
|
#if wxUSE_XPM
|
|
|
|
wxImage::AddHandler( new wxXPMHandler );
|
|
|
|
#endif
|
|
|
|
|
2002-02-02 23:16:09 +00:00
|
|
|
#if wxUSE_ICO_CUR
|
|
|
|
wxImage::AddHandler( new wxICOHandler );
|
|
|
|
wxImage::AddHandler( new wxCURHandler );
|
2002-12-04 14:11:26 +00:00
|
|
|
wxImage::AddHandler( new wxANIHandler );
|
2002-02-02 23:16:09 +00:00
|
|
|
#endif
|
|
|
|
|
1998-10-24 17:12:05 +00:00
|
|
|
wxFrame *frame = new MyFrame();
|
|
|
|
frame->Show( TRUE );
|
1999-01-12 23:51:13 +00:00
|
|
|
|
1998-10-24 17:12:05 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|