2005-02-27 15:25:55 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: samples/image/image.cpp
|
|
|
|
// Purpose: sample showing operations with wxImage
|
|
|
|
// Author: Robert Roebling
|
|
|
|
// Modified by:
|
|
|
|
// Created: 1998
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998-2005 Robert Roebling
|
|
|
|
// License: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
1998-10-24 17:12:05 +00:00
|
|
|
|
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"
|
2005-02-27 15:25:55 +00:00
|
|
|
#include "wx/filename.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
|
|
|
|
2003-03-23 17:48:42 +00:00
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
#include "wx/dataobj.h"
|
|
|
|
#include "wx/clipbrd.h"
|
|
|
|
#endif // wxUSE_CLIPBOARD
|
|
|
|
|
1999-12-14 16:53:41 +00:00
|
|
|
#include "smile.xbm"
|
2004-01-11 15:28:05 +00:00
|
|
|
#include "smile.xpm"
|
1999-12-14 16:53:41 +00:00
|
|
|
|
2005-02-13 15:35:43 +00:00
|
|
|
#if defined(__WXMSW__)
|
2003-09-09 20:39:58 +00:00
|
|
|
#ifdef wxHAVE_RAW_BITMAP
|
2003-06-13 23:25:09 +00:00
|
|
|
#include "wx/rawbmp.h"
|
2003-09-09 20:39:58 +00:00
|
|
|
#endif
|
2003-06-12 11:28:16 +00:00
|
|
|
#endif
|
2001-04-22 22:25:18 +00:00
|
|
|
|
2005-02-13 15:35:43 +00:00
|
|
|
#if defined(__WXMAC__) || defined(__WXGTK__)
|
|
|
|
#define wxHAVE_RAW_BITMAP
|
|
|
|
#include "wx/rawbmp.h"
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2005-05-22 15:37:40 +00:00
|
|
|
wxBitmap *my_horse_asciigrey_pnm;
|
|
|
|
wxBitmap *my_horse_rawgrey_pnm;
|
|
|
|
|
2005-07-28 22:50:34 +00:00
|
|
|
wxBitmap *colorized_horse_jpeg;
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2003-05-07 17:24:11 +00:00
|
|
|
#if wxUSE_CLIPBOARD
|
2003-03-23 17:48:42 +00:00
|
|
|
void OnCopy(wxCommandEvent& event);
|
|
|
|
void OnPaste(wxCommandEvent& event);
|
|
|
|
#endif // wxUSE_CLIPBOARD
|
|
|
|
|
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)
|
2004-06-01 15:42:12 +00:00
|
|
|
: wxFrame(parent, wxID_ANY, _T("Double click to save"),
|
2000-03-16 17:57:19 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2003-03-23 18:02:05 +00:00
|
|
|
wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX),
|
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 );
|
2004-06-01 15:42:12 +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
|
|
|
{
|
2005-08-24 17:47:11 +00:00
|
|
|
#if wxUSE_FILEDLG
|
2002-03-24 00:22:15 +00:00
|
|
|
wxImage image = m_bitmap.ConvertToImage();
|
2001-08-25 15:30:49 +00:00
|
|
|
|
2001-09-21 20:21:44 +00:00
|
|
|
wxString savefilename = wxFileSelector( wxT("Save Image"),
|
2005-08-24 17:47:11 +00:00
|
|
|
wxEmptyString,
|
|
|
|
wxEmptyString,
|
2001-09-21 20:21:44 +00:00
|
|
|
(const wxChar *)NULL,
|
2005-06-13 12:19:33 +00:00
|
|
|
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|")
|
|
|
|
wxT("PCX files (*.pcx)|*.pcx|")
|
|
|
|
wxT("ICO files (*.ico)|*.ico|")
|
|
|
|
wxT("CUR files (*.cur)|*.cur"),
|
2004-06-01 15:42:12 +00:00
|
|
|
wxSAVE,
|
|
|
|
this);
|
2001-08-25 15:30:49 +00:00
|
|
|
|
|
|
|
if ( savefilename.empty() )
|
|
|
|
return;
|
|
|
|
|
2005-02-27 15:25:55 +00:00
|
|
|
wxString extension;
|
|
|
|
wxFileName::SplitPath(savefilename, NULL, NULL, &extension);
|
2001-08-25 15:30:49 +00:00
|
|
|
|
2005-02-27 15:25:55 +00:00
|
|
|
bool saved = false;
|
|
|
|
if ( extension == _T("bpp") )
|
|
|
|
{
|
|
|
|
static const int bppvalues[] =
|
|
|
|
{
|
|
|
|
wxBMP_1BPP,
|
|
|
|
wxBMP_1BPP_BW,
|
|
|
|
wxBMP_4BPP,
|
|
|
|
wxBMP_8BPP,
|
|
|
|
wxBMP_8BPP_GREY,
|
|
|
|
wxBMP_8BPP_RED,
|
|
|
|
wxBMP_8BPP_PALETTE,
|
|
|
|
wxBMP_24BPP
|
|
|
|
};
|
|
|
|
|
2005-03-30 15:50:06 +00:00
|
|
|
const wxString bppchoices[] =
|
2005-02-27 15:25:55 +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")
|
|
|
|
};
|
|
|
|
|
|
|
|
int bppselection = wxGetSingleChoiceIndex(_T("Set BMP BPP"),
|
|
|
|
_T("Image sample: save file"),
|
|
|
|
WXSIZEOF(bppchoices),
|
|
|
|
bppchoices,
|
|
|
|
this);
|
|
|
|
if ( bppselection != -1 )
|
|
|
|
{
|
|
|
|
int format = bppvalues[bppselection];
|
|
|
|
image.SetOption(wxIMAGE_OPTION_BMP_FORMAT, format);
|
|
|
|
|
|
|
|
if ( format == wxBMP_8BPP_PALETTE )
|
|
|
|
{
|
|
|
|
unsigned char *cmap = new unsigned char [256];
|
|
|
|
for ( int i = 0; i < 256; i++ )
|
|
|
|
cmap[i] = (unsigned char)i;
|
|
|
|
image.SetPalette(wxPalette(256, cmap, cmap, cmap));
|
|
|
|
|
2005-06-13 12:19:33 +00:00
|
|
|
delete[] cmap;
|
2005-02-27 15:25:55 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-25 15:30:49 +00:00
|
|
|
}
|
2005-02-27 15:25:55 +00:00
|
|
|
else if ( extension == _T("png") )
|
|
|
|
{
|
|
|
|
static const int pngvalues[] =
|
|
|
|
{
|
|
|
|
wxPNG_TYPE_COLOUR,
|
|
|
|
wxPNG_TYPE_COLOUR,
|
|
|
|
wxPNG_TYPE_GREY,
|
|
|
|
wxPNG_TYPE_GREY,
|
|
|
|
wxPNG_TYPE_GREY_RED,
|
|
|
|
wxPNG_TYPE_GREY_RED,
|
|
|
|
};
|
|
|
|
|
2005-03-30 15:50:06 +00:00
|
|
|
const wxString pngchoices[] =
|
2005-02-27 15:25:55 +00:00
|
|
|
{
|
|
|
|
_T("Colour 8bpp"),
|
|
|
|
_T("Colour 16bpp"),
|
|
|
|
_T("Grey 8bpp"),
|
|
|
|
_T("Grey 16bpp"),
|
|
|
|
_T("Grey red 8bpp"),
|
|
|
|
_T("Grey red 16bpp"),
|
|
|
|
};
|
|
|
|
|
|
|
|
int sel = wxGetSingleChoiceIndex(_T("Set PNG format"),
|
|
|
|
_T("Image sample: save file"),
|
|
|
|
WXSIZEOF(pngchoices),
|
|
|
|
pngchoices,
|
|
|
|
this);
|
|
|
|
if ( sel != -1 )
|
|
|
|
{
|
|
|
|
image.SetOption(wxIMAGE_OPTION_PNG_FORMAT, pngvalues[sel]);
|
|
|
|
image.SetOption(wxIMAGE_OPTION_PNG_BITDEPTH, sel % 2 ? 16 : 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else 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:
|
2005-02-27 15:25:55 +00:00
|
|
|
saved = image.SaveFile(savefilename, wxBITMAP_TYPE_CUR);
|
2002-03-17 11:35:32 +00:00
|
|
|
}
|
2005-02-27 15:25:55 +00:00
|
|
|
|
|
|
|
if ( !saved )
|
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):
|
2005-02-27 15:25:55 +00:00
|
|
|
image.SaveFile(savefilename);
|
2002-03-17 11:35:32 +00:00
|
|
|
}
|
2005-08-24 17:47:11 +00:00
|
|
|
#endif // wxUSE_FILEDLG
|
2001-08-25 15:30:49 +00:00
|
|
|
}
|
|
|
|
|
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)
|
2004-06-01 15:42:12 +00:00
|
|
|
: wxFrame(parent, wxID_ANY, _T("Raw bitmaps (how exciting)")),
|
2003-03-22 19:10:09 +00:00
|
|
|
m_bitmap(SIZE, SIZE, 32)
|
|
|
|
{
|
|
|
|
SetClientSize(SIZE, SIZE);
|
|
|
|
|
2003-06-14 13:00:31 +00:00
|
|
|
// another possibility: wxNativePixelData (don't forget to remove code
|
|
|
|
// setting alpha in the loop below then)
|
|
|
|
typedef wxAlphaPixelData Data;
|
|
|
|
|
|
|
|
Data data(m_bitmap, wxPoint(BORDER, BORDER), wxSize(REAL_SIZE, REAL_SIZE));
|
2003-03-22 19:10:09 +00:00
|
|
|
if ( !data )
|
|
|
|
{
|
|
|
|
wxLogError(_T("Failed to gain raw access to bitmap data"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-01 17:52:50 +00:00
|
|
|
data.UseAlpha();
|
2003-04-13 13:45:20 +00:00
|
|
|
|
2003-06-14 13:00:31 +00:00
|
|
|
Data::Iterator p(data);
|
2003-03-22 19:10:09 +00:00
|
|
|
|
|
|
|
for ( int y = 0; y < REAL_SIZE; ++y )
|
|
|
|
{
|
2003-06-14 13:00:31 +00:00
|
|
|
Data::Iterator rowStart = p;
|
2003-03-22 19:10:09 +00:00
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2005-04-15 00:14:32 +00:00
|
|
|
// note that RGB must be premultiplied by alpha
|
|
|
|
unsigned a = (Data::Iterator::ChannelType)((x*255.)/REAL_SIZE);
|
2005-04-16 20:40:43 +00:00
|
|
|
p.Red() = r * a / 256;
|
|
|
|
p.Green() = g * a / 256;
|
|
|
|
p.Blue() = b * a / 256;
|
2005-04-15 00:14:32 +00:00
|
|
|
p.Alpha() = a;
|
2003-03-22 19:10:09 +00:00
|
|
|
|
|
|
|
++p; // same as p.OffsetX(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = rowStart;
|
2003-04-28 02:04:09 +00:00
|
|
|
p.OffsetY(data, 1);
|
2003-03-22 19:10:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.DrawBitmap( m_bitmap, 0, 0, true /* use mask */ );
|
2003-03-22 19:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 )
|
|
|
|
, m_bmpSmileXpm((const char **) smile_xpm)
|
|
|
|
, m_iconSmileXpm((const char **) smile_xpm)
|
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;
|
2005-07-28 22:50:34 +00:00
|
|
|
colorized_horse_jpeg = (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;
|
|
|
|
|
2005-05-22 15:37:40 +00:00
|
|
|
my_horse_asciigrey_pnm = (wxBitmap*) NULL;
|
|
|
|
my_horse_rawgrey_pnm = (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
|
|
|
|
2003-04-14 00:46:59 +00:00
|
|
|
if ( image.LoadFile( dir + _T("test.png") ) )
|
|
|
|
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
|
2005-07-28 22:50:34 +00:00
|
|
|
{
|
2001-04-28 23:30:11 +00:00
|
|
|
my_horse_jpeg = new wxBitmap( image );
|
2005-07-28 22:50:34 +00:00
|
|
|
// Colorize by rotating green hue to red
|
|
|
|
wxImage::HSVValue greenHSV = wxImage::RGBtoHSV(wxImage::RGBValue(0, 255, 0));
|
|
|
|
wxImage::HSVValue redHSV = wxImage::RGBtoHSV(wxImage::RGBValue(255, 0, 0));
|
|
|
|
image.RotateHue(redHSV.hue - greenHSV.hue);
|
|
|
|
colorized_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 );
|
2005-05-22 15:37:40 +00:00
|
|
|
|
|
|
|
image.Destroy();
|
|
|
|
|
|
|
|
if ( !image.LoadFile( dir + _T("horse_ag.pnm"), wxBITMAP_TYPE_PNM ) )
|
|
|
|
wxLogError(wxT("Can't load PNM image"));
|
|
|
|
else
|
|
|
|
my_horse_asciigrey_pnm = new wxBitmap( image );
|
|
|
|
|
|
|
|
image.Destroy();
|
|
|
|
|
|
|
|
if ( !image.LoadFile( dir + _T("horse_rg.pnm"), wxBITMAP_TYPE_PNM ) )
|
|
|
|
wxLogError(wxT("Can't load PNM image"));
|
|
|
|
else
|
|
|
|
my_horse_rawgrey_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
|
|
|
|
|
|
|
// 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);
|
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);
|
|
|
|
}
|
2004-10-06 20:54:57 +00:00
|
|
|
else
|
2002-12-04 14:11:26 +00:00
|
|
|
my_horse_ani [i] = wxBitmap( image );
|
|
|
|
}
|
2003-03-23 17:48:42 +00:00
|
|
|
#endif // wxUSE_ICO_CUR
|
2002-02-02 23:16:09 +00:00
|
|
|
|
2002-05-24 22:23:24 +00:00
|
|
|
image.Destroy();
|
|
|
|
|
|
|
|
// test image loading from stream
|
|
|
|
wxFile file(dir + _T("horse.bmp"));
|
2003-04-14 00:46:59 +00:00
|
|
|
if ( file.IsOpened() )
|
2002-05-24 22:23:24 +00:00
|
|
|
{
|
2004-11-12 14:08:31 +00:00
|
|
|
wxFileOffset len = file.Length();
|
|
|
|
size_t dataSize = (size_t)len;
|
|
|
|
void *data = malloc(dataSize);
|
|
|
|
if ( file.Read(data, dataSize) != len )
|
2003-04-14 00:46:59 +00:00
|
|
|
wxLogError(_T("Reading bitmap file failed"));
|
2002-05-24 22:23:24 +00:00
|
|
|
else
|
2003-04-14 00:46:59 +00:00
|
|
|
{
|
2004-11-12 14:08:31 +00:00
|
|
|
wxMemoryInputStream mis(data, dataSize);
|
2003-04-14 00:46:59 +00:00
|
|
|
if ( !image.LoadFile(mis) )
|
|
|
|
wxLogError(wxT("Can't load BMP image from stream"));
|
|
|
|
else
|
|
|
|
my_horse_bmp2 = new wxBitmap( image );
|
|
|
|
}
|
2002-05-24 22:23:24 +00:00
|
|
|
|
2003-04-14 00:46:59 +00:00
|
|
|
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;
|
2005-05-22 15:37:40 +00:00
|
|
|
delete my_horse_asciigrey_pnm;
|
|
|
|
delete my_horse_rawgrey_pnm;
|
2005-07-28 22:50:34 +00:00
|
|
|
delete colorized_horse_jpeg;
|
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 );
|
2005-06-13 12:19:33 +00:00
|
|
|
|
2005-05-22 15:37:40 +00:00
|
|
|
dc.DrawText( _T("PNM handler (ascii grey)"), 280, 1285 );
|
|
|
|
if (my_horse_asciigrey_pnm && my_horse_asciigrey_pnm->Ok())
|
|
|
|
dc.DrawBitmap( *my_horse_asciigrey_pnm, 280, 1300 );
|
|
|
|
|
|
|
|
dc.DrawText( _T("PNM handler (raw grey)"), 530, 1285 );
|
|
|
|
if (my_horse_rawgrey_pnm && my_horse_rawgrey_pnm->Ok())
|
|
|
|
dc.DrawBitmap( *my_horse_rawgrey_pnm, 530, 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() );
|
2004-06-01 15:42:12 +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 );
|
2003-10-09 20:00:22 +00:00
|
|
|
#ifndef __WXGTK20__
|
|
|
|
// I cannot convince GTK2 to draw into mono bitmaps
|
2002-05-24 22:23:24 +00:00
|
|
|
memdc.DrawText( _T("Hi!"), 5, 5 );
|
2003-10-09 20:00:22 +00:00
|
|
|
#endif
|
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() );
|
2004-06-01 15:42:12 +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
|
|
|
}
|
|
|
|
|
2003-10-18 19:23:19 +00:00
|
|
|
// For testing transparency
|
|
|
|
dc.SetBrush( *wxRED_BRUSH );
|
|
|
|
dc.DrawRectangle( 20, 2220, 560, 68 );
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2003-10-18 19:23:19 +00:00
|
|
|
dc.DrawText(_T("XPM bitmap"), 30, 2230 );
|
2000-01-21 21:40:10 +00:00
|
|
|
if ( m_bmpSmileXpm.Ok() )
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.DrawBitmap(m_bmpSmileXpm, 30, 2250, true);
|
2000-01-21 21:40:10 +00:00
|
|
|
|
2003-10-18 19:23:19 +00:00
|
|
|
dc.DrawText(_T("XPM icon"), 110, 2230 );
|
2000-01-21 21:40:10 +00:00
|
|
|
if ( m_iconSmileXpm.Ok() )
|
2003-10-18 19:23:19 +00:00
|
|
|
dc.DrawIcon(m_iconSmileXpm, 110, 2250);
|
2004-10-06 20:54:57 +00:00
|
|
|
|
|
|
|
// testing icon -> bitmap conversion
|
2003-10-18 19:23:19 +00:00
|
|
|
wxBitmap to_blit( m_iconSmileXpm );
|
2004-01-11 15:28:05 +00:00
|
|
|
if (to_blit.Ok())
|
|
|
|
{
|
|
|
|
dc.DrawText( _T("SubBitmap"), 170, 2230 );
|
|
|
|
wxBitmap sub = to_blit.GetSubBitmap( wxRect(0,0,15,15) );
|
|
|
|
if (sub.Ok())
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.DrawBitmap( sub, 170, 2250, true );
|
2004-01-11 15:28:05 +00:00
|
|
|
|
|
|
|
dc.DrawText( _T("Enlarged"), 250, 2230 );
|
|
|
|
dc.SetUserScale( 1.5, 1.5 );
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.DrawBitmap( to_blit, (int)(250/1.5), (int)(2250/1.5), true );
|
2004-01-11 15:28:05 +00:00
|
|
|
dc.SetUserScale( 2, 2 );
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.DrawBitmap( to_blit, (int)(300/2), (int)(2250/2), true );
|
2004-01-11 15:28:05 +00:00
|
|
|
dc.SetUserScale( 1.0, 1.0 );
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2004-01-11 15:28:05 +00:00
|
|
|
dc.DrawText( _T("Blit"), 400, 2230);
|
|
|
|
wxMemoryDC blit_dc;
|
|
|
|
blit_dc.SelectObject( to_blit );
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.Blit( 400, 2250, to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
|
2004-01-11 15:28:05 +00:00
|
|
|
dc.SetUserScale( 1.5, 1.5 );
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.Blit( (int)(450/1.5), (int)(2250/1.5), to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
|
2004-01-11 15:28:05 +00:00
|
|
|
dc.SetUserScale( 2, 2 );
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.Blit( (int)(500/2), (int)(2250/2), to_blit.GetWidth(), to_blit.GetHeight(), &blit_dc, 0, 0, wxCOPY, true );
|
2004-01-11 15:28:05 +00:00
|
|
|
dc.SetUserScale( 1.0, 1.0 );
|
|
|
|
}
|
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())
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.DrawBitmap( *my_horse_ico32, 30, 2330, true );
|
2002-02-02 23:16:09 +00:00
|
|
|
|
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())
|
2004-06-01 15:42:12 +00:00
|
|
|
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())
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.DrawBitmap( *my_horse_ico, 430, 2330, true );
|
2002-02-02 23:16:09 +00:00
|
|
|
|
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
|
|
|
{
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.DrawBitmap( *my_horse_cur, 30, 2420, true );
|
2002-02-02 23:16:09 +00:00
|
|
|
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())
|
|
|
|
{
|
2004-06-01 15:42:12 +00:00
|
|
|
dc.DrawBitmap( my_horse_ani[i], 230 + i * 2 * my_horse_ani[i].GetWidth() , 2420, true );
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
2005-07-28 22:50:34 +00:00
|
|
|
#if wxUSE_LIBJPEG
|
|
|
|
if (colorized_horse_jpeg)
|
|
|
|
{
|
|
|
|
dc.DrawText( _T("Colorize image by rotating green hue to red"), 30, 2490 );
|
|
|
|
dc.DrawBitmap( *colorized_horse_jpeg, 30, 2520 );
|
|
|
|
}
|
|
|
|
#endif // wxUSE_LIBJPEG
|
|
|
|
|
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;
|
2004-10-06 20:54:57 +00:00
|
|
|
anti.SetRGB( x, y, (unsigned char)red, (unsigned char)green, (unsigned char)blue );
|
1999-01-22 18:08:54 +00:00
|
|
|
}
|
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
|
|
|
|
{
|
2005-06-02 12:04:48 +00:00
|
|
|
ID_QUIT = wxID_EXIT,
|
|
|
|
ID_ABOUT = wxID_ABOUT,
|
|
|
|
ID_NEW = 100,
|
|
|
|
ID_SHOWRAW = 101
|
2003-03-22 19:10:09 +00:00
|
|
|
};
|
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
|
2003-03-23 17:48:42 +00:00
|
|
|
|
2003-05-07 17:24:11 +00:00
|
|
|
#if wxUSE_CLIPBOARD
|
2003-03-23 17:48:42 +00:00
|
|
|
EVT_MENU(wxID_COPY, MyFrame::OnCopy)
|
|
|
|
EVT_MENU(wxID_PASTE, MyFrame::OnPaste)
|
|
|
|
#endif // wxUSE_CLIPBOARD
|
1998-10-24 17:12:05 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
1999-01-12 23:51:13 +00:00
|
|
|
MyFrame::MyFrame()
|
2004-06-01 15:42:12 +00:00
|
|
|
: wxFrame( (wxFrame *)NULL, wxID_ANY, _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
|
|
|
{
|
2003-03-23 17:48:42 +00:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar();
|
|
|
|
|
|
|
|
wxMenu *menuImage = new wxMenu;
|
|
|
|
menuImage->Append( ID_NEW, _T("&Show any image...\tCtrl-O"));
|
2003-05-02 12:58:00 +00:00
|
|
|
|
2003-03-22 19:10:09 +00:00
|
|
|
#ifdef wxHAVE_RAW_BITMAP
|
2003-03-23 17:48:42 +00:00
|
|
|
menuImage->Append( ID_SHOWRAW, _T("Test &raw bitmap...\tCtrl-R"));
|
2003-03-22 19:10:09 +00:00
|
|
|
#endif
|
2003-03-23 17:48:42 +00:00
|
|
|
menuImage->AppendSeparator();
|
|
|
|
menuImage->Append( ID_ABOUT, _T("&About..."));
|
|
|
|
menuImage->AppendSeparator();
|
|
|
|
menuImage->Append( ID_QUIT, _T("E&xit\tCtrl-Q"));
|
|
|
|
menu_bar->Append(menuImage, _T("&Image"));
|
|
|
|
|
2003-05-07 17:24:11 +00:00
|
|
|
#if wxUSE_CLIPBOARD
|
2003-03-23 17:48:42 +00:00
|
|
|
wxMenu *menuClipboard = new wxMenu;
|
|
|
|
menuClipboard->Append(wxID_COPY, _T("&Copy test image\tCtrl-C"));
|
|
|
|
menuClipboard->Append(wxID_PASTE, _T("&Paste image\tCtrl-V"));
|
|
|
|
menu_bar->Append(menuClipboard, _T("&Clipboard"));
|
|
|
|
#endif // wxUSE_CLIPBOARD
|
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
|
|
|
|
2004-07-19 15:36:01 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
1998-11-10 19:43:04 +00:00
|
|
|
CreateStatusBar(2);
|
|
|
|
int widths[] = { -1, 100 };
|
|
|
|
SetStatusWidths( 2, widths );
|
2004-07-19 15:36:01 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1999-01-12 23:51:13 +00:00
|
|
|
|
2004-06-01 15:42:12 +00:00
|
|
|
m_canvas = new MyCanvas( this, wxID_ANY, wxPoint(0,0), wxSize(10,10) );
|
1999-08-27 11:42:47 +00:00
|
|
|
|
2005-07-28 22:50:34 +00:00
|
|
|
// 500 width * 2750 height
|
|
|
|
m_canvas->SetScrollbars( 10, 10, 50, 275 );
|
1998-10-24 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
2004-06-01 15:42:12 +00:00
|
|
|
Close( true );
|
1998-10-24 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) )
|
|
|
|
{
|
2005-08-24 17:47:11 +00:00
|
|
|
#if wxUSE_FILEDLG
|
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();
|
2005-08-24 17:47:11 +00:00
|
|
|
#endif // wxUSE_FILEDLG
|
2000-03-16 17:57:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-22 19:10:09 +00:00
|
|
|
#ifdef wxHAVE_RAW_BITMAP
|
|
|
|
|
2003-09-09 20:39:58 +00:00
|
|
|
void MyFrame::OnTestRawBitmap( wxCommandEvent &WXUNUSED(event) )
|
2003-03-22 19:10:09 +00:00
|
|
|
{
|
|
|
|
(new MyRawBitmapFrame(this))->Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxHAVE_RAW_BITMAP
|
|
|
|
|
2003-05-07 17:24:11 +00:00
|
|
|
#if wxUSE_CLIPBOARD
|
2003-03-23 17:48:42 +00:00
|
|
|
|
|
|
|
void MyFrame::OnCopy(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxBitmapDataObject *dobjBmp = new wxBitmapDataObject;
|
|
|
|
dobjBmp->SetBitmap(*m_canvas->my_horse_png);
|
|
|
|
|
2003-05-07 17:24:11 +00:00
|
|
|
wxTheClipboard->Open();
|
|
|
|
|
2003-03-23 17:48:42 +00:00
|
|
|
if ( !wxTheClipboard->SetData(dobjBmp) )
|
|
|
|
{
|
|
|
|
wxLogError(_T("Failed to copy bitmap to clipboard"));
|
|
|
|
}
|
2003-05-07 17:24:11 +00:00
|
|
|
|
|
|
|
wxTheClipboard->Close();
|
2003-03-23 17:48:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnPaste(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxBitmapDataObject dobjBmp;
|
2003-05-07 17:24:11 +00:00
|
|
|
|
|
|
|
wxTheClipboard->Open();
|
2003-03-23 17:48:42 +00:00
|
|
|
if ( !wxTheClipboard->GetData(dobjBmp) )
|
|
|
|
{
|
|
|
|
wxLogMessage(_T("No bitmap data in the clipboard"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(new MyImageFrame(this, dobjBmp.GetBitmap()))->Show();
|
|
|
|
}
|
2003-05-07 17:24:11 +00:00
|
|
|
wxTheClipboard->Close();
|
2003-03-23 17:48:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_CLIPBOARD
|
|
|
|
|
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();
|
2004-06-01 15:42:12 +00:00
|
|
|
frame->Show( true );
|
1999-01-12 23:51:13 +00:00
|
|
|
|
2004-06-01 15:42:12 +00:00
|
|
|
return true;
|
1998-10-24 17:12:05 +00:00
|
|
|
}
|