⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image.tex

📁 Wxpython Implemented on Windows CE, Source code
💻 TEX
📖 第 1 页 / 共 4 页
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Name:        image.tex
%% Purpose:     wxImage documentation
%% Author:      wxWidgets Team
%% Modified by:
%% Created:
%% RCS-ID:      $Id: image.tex,v 1.84 2006/01/19 09:55:15 JS Exp $
%% Copyright:   (c) wxWidgets Team
%% License:     wxWindows license
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{\class{wxImage}}\label{wximage}

This class encapsulates a platform-independent image. An image can be created
from data, or using \helpref{wxBitmap::ConvertToImage}{wxbitmapconverttoimage}. An image
can be loaded from a file in a variety of formats, and is extensible to new formats
via image format handlers. Functions are available to set and get image bits, so
it can be used for basic image manipulation.

A wxImage cannot (currently) be drawn directly to a \helpref{wxDC}{wxdc}. Instead,
a platform-specific \helpref{wxBitmap}{wxbitmap} object must be created from it using
the \helpref{wxBitmap::wxBitmap(wxImage,int depth)}{wxbitmapctor} constructor.
This bitmap can then
be drawn in a device context, using \helpref{wxDC::DrawBitmap}{wxdcdrawbitmap}.

One colour value of the image may be used as a mask colour which will lead to the automatic
creation of a \helpref{wxMask}{wxmask} object associated to the bitmap object.

\wxheading{Alpha channel support}

Starting from wxWidgets 2.5.0 wxImage supports alpha channel data, that is in
addition to a byte for the red, green and blue colour components for each pixel
it also stores a byte representing the pixel opacity. An alpha value of $0$
corresponds to a transparent pixel (null opacity) while a value of $255$
means that the pixel is 100\% opaque.

Unlike RGB data, not all images have an alpha channel and before using
\helpref{GetAlpha}{wximagegetalpha} you should check if this image contains
an alpha channel with \helpref{HasAlpha}{wximagehasalpha}. Note that currently only
images loaded from PNG files with transparency information will have an alpha
channel but alpha support will be added to the other formats as well (as well
as support for saving images with alpha channel which also isn't implemented).

\wxheading{Available image handlers}

The following image handlers are available. {\bf wxBMPHandler} is always
installed by default. To use other image formats, install the appropriate
handler with \helpref{wxImage::AddHandler}{wximageaddhandler} or
\helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}.

\twocolwidtha{5cm}%
\begin{twocollist}
\twocolitem{\indexit{wxBMPHandler}}{For loading and saving, always installed.}
\twocolitem{\indexit{wxPNGHandler}}{For loading (including alpha support) and saving.}
\twocolitem{\indexit{wxJPEGHandler}}{For loading and saving.}
\twocolitem{\indexit{wxGIFHandler}}{Only for loading, due to legal issues.}
\twocolitem{\indexit{wxPCXHandler}}{For loading and saving (see below).}
\twocolitem{\indexit{wxPNMHandler}}{For loading and saving (see below).}
\twocolitem{\indexit{wxTIFFHandler}}{For loading and saving.}
\twocolitem{\indexit{wxIFFHandler}}{For loading only.}
\twocolitem{\indexit{wxXPMHandler}}{For loading and saving.}
\twocolitem{\indexit{wxICOHandler}}{For loading and saving.}
\twocolitem{\indexit{wxCURHandler}}{For loading and saving.}
\twocolitem{\indexit{wxANIHandler}}{For loading only.}
\end{twocollist}

When saving in PCX format, {\bf wxPCXHandler} will count the number of
different colours in the image; if there are 256 or less colours, it will
save as 8 bit, else it will save as 24 bit.

Loading PNMs only works for ASCII or raw RGB images. When saving in
PNM format, {\bf wxPNMHandler} will always save as raw RGB.

\wxheading{Derived from}

\helpref{wxObject}{wxobject}

\wxheading{Include files}

<wx/image.h>

\wxheading{See also}

\helpref{wxBitmap}{wxbitmap},
\helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}

\latexignore{\rtfignore{\wxheading{Members}}}


\membersection{wxImage::wxImage}\label{wximagector}

\func{}{wxImage}{\void}

Default constructor.

\func{}{wxImage}{\param{const wxImage\& }{image}}

Copy constructor.

\func{}{wxImage}{\param{const wxBitmap\&}{ bitmap}}

(Deprecated form, use \helpref{wxBitmap::ConvertToImage}{wxbitmapconverttoimage}
instead.) Constructs an image from a platform-dependent bitmap. This preserves
mask information so that bitmaps and images can be converted back
and forth without loss in that respect.

\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{bool}{ clear=true}}

Creates an image with the given width and height.  If {\it clear} is true, the new image will be initialized to black.
Otherwise, the image data will be uninitialized.

\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{unsigned char*}{ data}, \param{bool}{ static\_data = \false}}

Creates an image from given data with the given width and height. If
{\it static\_data} is true, then wxImage will not delete the actual
image data in its destructor, otherwise it will free it by calling
{\it free()}.

\func{}{wxImage}{\param{const wxString\& }{name}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}, \param{int}{ index = -1}}

\func{}{wxImage}{\param{const wxString\& }{name}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}

Loads an image from a file.

\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}, \param{int}{ index = -1}}

\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}

Loads an image from an input stream.

\func{}{wxImage}{\param{const char** }{xpmData}}

Creates an image from XPM data.

\wxheading{Parameters}

\docparam{width}{Specifies the width of the image.}

\docparam{height}{Specifies the height of the image.}

\docparam{name}{Name of the file from which to load the image.}

\docparam{stream}{Opened input stream from which to load the image. Currently, the stream must support seeking.}

\docparam{type}{May be one of the following:

\twocolwidtha{5cm}%
\begin{twocollist}
\twocolitem{\indexit{wxBITMAP\_TYPE\_BMP}}{Load a Windows bitmap file.}
\twocolitem{\indexit{wxBITMAP\_TYPE\_GIF}}{Load a GIF bitmap file.}
\twocolitem{\indexit{wxBITMAP\_TYPE\_JPEG}}{Load a JPEG bitmap file.}
\twocolitem{\indexit{wxBITMAP\_TYPE\_PNG}}{Load a PNG bitmap file.}
\twocolitem{\indexit{wxBITMAP\_TYPE\_PCX}}{Load a PCX bitmap file.}
\twocolitem{\indexit{wxBITMAP\_TYPE\_PNM}}{Load a PNM bitmap file.}
\twocolitem{\indexit{wxBITMAP\_TYPE\_TIF}}{Load a TIFF bitmap file.}
\twocolitem{\indexit{wxBITMAP\_TYPE\_XPM}}{Load a XPM bitmap file.}
\twocolitem{\indexit{wxBITMAP\_TYPE\_ICO}}{Load a Windows icon file (ICO).}
\twocolitem{\indexit{wxBITMAP\_TYPE\_CUR}}{Load a Windows cursor file (CUR).}
\twocolitem{\indexit{wxBITMAP\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).}
\twocolitem{\indexit{wxBITMAP\_TYPE\_ANY}}{Will try to autodetect the format.}
\end{twocollist}}

\docparam{mimetype}{MIME type string (for example 'image/jpeg')}

\docparam{index}{Index of the image to load in the case that the image file contains multiple images.
This is only used by GIF, ICO and TIFF handlers. The default value (-1) means
"choose the default image" and is interpreted as the first image (index=0) by
the GIF and TIFF handler and as the largest and most colourful one by the ICO handler.}

\docparam{xpmData}{A pointer to XPM image data.}

\wxheading{Remarks}

Depending on how wxWidgets has been configured, not all formats may be available.

Note: any handler other than BMP must be previously
initialized with \helpref{wxImage::AddHandler}{wximageaddhandler} or
\helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}.

Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to get the
hotspot for loaded cursor file:
\begin{verbatim}
    int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
    int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);

\end{verbatim}

\wxheading{See also}

\helpref{wxImage::LoadFile}{wximageloadfile}

\pythonnote{Constructors supported by wxPython are:\par
\indented{2cm}{\begin{twocollist}
\twocolitem{{\bf wxImage(name, flag)}}{Loads an image from a file}
\twocolitem{{\bf wxNullImage()}}{Create a null image (has no size or
image data)}
\twocolitem{{\bf wxEmptyImage(width, height)}}{Creates an empty image
of the given size}
\twocolitem{{\bf wxImageFromMime(name, mimetype}}{Creates an image from
the given file of the given mimetype}
\twocolitem{{\bf wxImageFromBitmap(bitmap)}}{Creates an image from a
platform-dependent bitmap}
\end{twocollist}}
}

\perlnote{Constructors supported by wxPerl are:\par
\begin{itemize}
\item{Wx::Image->new( bitmap )}
\item{Wx::Image->new( icon )}
\item{Wx::Image->new( width, height )}
\item{Wx::Image->new( width, height, data )}
\item{Wx::Image->new( file, type, index )}
\item{Wx::Image->new( file, mimetype, index )}
\item{Wx::Image->new( stream, type, index )}
\item{Wx::Image->new( stream, mimetype, index )}
\end{itemize}
}


\membersection{wxImage::\destruct{wxImage}}\label{wximagedtor}

\func{}{\destruct{wxImage}}{\void}

Destructor.


\membersection{wxImage::AddHandler}\label{wximageaddhandler}

\func{static void}{AddHandler}{\param{wxImageHandler*}{ handler}}

Adds a handler to the end of the static list of format handlers.

\docparam{handler}{A new image format handler object. There is usually only one instance
of a given handler class in an application session.}

\wxheading{See also}

\helpref{wxImageHandler}{wximagehandler}

\func{bool}{CanRead}{\param{const wxString\&}{ filename}}

returns true if the current image handlers can read this file

\pythonnote{In wxPython this static method is named {\tt wxImage\_AddHandler}.}

\membersection{wxImage::CleanUpHandlers}\label{wximagecleanuphandlers}

\func{static void}{CleanUpHandlers}{\void}

Deletes all image handlers.

This function is called by wxWidgets on exit.


\membersection{wxImage::ComputeHistogram}\label{wximagecomputehistogram}

\constfunc{unsigned long}{ComputeHistogram}{\param{wxImageHistogram\& }{histogram}}

Computes the histogram of the image. {\it histogram} is a reference to
wxImageHistogram object. wxImageHistogram is a specialization of
\helpref{wxHashMap}{wxhashmap} "template" and is defined as follows:

\begin{verbatim}
class WXDLLEXPORT wxImageHistogramEntry
{
public:
    wxImageHistogramEntry() : index(0), value(0) {}
    unsigned long index;
    unsigned long value;
};

WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
                             wxIntegerHash, wxIntegerEqual,
                             wxImageHistogram);
\end{verbatim}

\wxheading{Return value}

Returns number of colours in the histogram.


\membersection{wxImage::ConvertAlphaToMask}\label{wximageconvertalphatomask}

\func{bool}{ConvertAlphaToMask}{\param{unsigned char}{ threshold = $128$}}

If the image has alpha channel, this method converts it to mask. All pixels
with alpha value less than \arg{threshold} are replaced with mask colour
and the alpha channel is removed. Mask colour is chosen automatically using
\helpref{FindFirstUnusedColour}{wximagefindfirstunusedcolour}.

If the image image doesn't have alpha channel,
ConvertAlphaToMask does nothing.

\wxheading{Return value}

\false if FindFirstUnusedColour returns \false, \true otherwise.


\membersection{wxImage::ConvertToBitmap}\label{wximageconverttobitmap}

\constfunc{wxBitmap}{ConvertToBitmap}{\void}

Deprecated, use equivalent \helpref{wxBitmap constructor}{wxbitmapctor}
(which takes wxImage and depth as its arguments) instead.


\membersection{wxImage::ConvertToGreyscale}\label{wximageconverttogreyscale}

\constfunc{wxImage}{ConvertToGreyscale}{\param{double}{ lr = 0.299}, \param{double}{ lg = 0.587}, \param{double}{ lb = 0.114}}

Returns a greyscale version of the image. The returned image uses the luminance
component of the original to calculate the greyscale. Defaults to using
ITU-T BT.601 when converting to YUV, where every pixel equals
(R * {\it lr}) + (G * {\it lg}) + (B * {\it lb}).


\membersection{wxImage::ConvertToMono}\label{wxbitmapconverttomono}

\constfunc{wxImage}{ConvertToMono}{\param{unsigned char}{ r}, \param{unsigned char}{ g}, \param{unsigned char}{ b}}

Returns monochromatic version of the image. The returned image has white
colour where the original has {\it (r,g,b)} colour and black colour
everywhere else.


\membersection{wxImage::Copy}\label{wximagecopy}

\constfunc{wxImage}{Copy}{\void}

Returns an identical copy of the image.


\membersection{wxImage::Create}\label{wximagecreate}

\func{bool}{Create}{\param{int}{ width}, \param{int}{ height}, \param{bool}{ clear=true}}

Creates a fresh image.  If {\it clear} is true, the new image will be initialized to black.
Otherwise, the image data will be uninitialized.

\wxheading{Parameters}

\docparam{width}{The width of the image in pixels.}

\docparam{height}{The height of the image in pixels.}

\wxheading{Return value}

true if the call succeeded, false otherwise.


\membersection{wxImage::Destroy}\label{wximagedestroy}

\func{void}{Destroy}{\void}

Destroys the image data.


\membersection{wxImage::FindFirstUnusedColour}\label{wximagefindfirstunusedcolour}

\func{bool}{FindFirstUnusedColour}{\param{unsigned char *}{ r}, \param{unsigned char *}{ g}, \param{unsigned char *}{ b}, \param{unsigned char}{ startR = 1}, \param{unsigned char}{ startG = 0}, \param{unsigned char}{ startB = 0}}

\wxheading{Parameters}

\docparam{r,g,b}{Pointers to variables to save the colour.}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -