Added wxImage wxImage::GetSubImage(cont wxRect&) const
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3414 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -478,6 +478,13 @@ Example:
|
||||
|
||||
\helpref{Rescale}{wximagerescale}
|
||||
|
||||
\membersection{wxImage::GetSubImage}\label{wximagegetsubimage}
|
||||
|
||||
\constfunc{wxImage}{GetSubImage}{\param{const wxRect&}{rect}}
|
||||
|
||||
Returns a sub image of the current one as long as the rect belongs entirely to
|
||||
the image.
|
||||
|
||||
\membersection{wxImage::SetData}\label{wximagesetdata}
|
||||
|
||||
\func{void}{SetData}{\param{unsigned char*}{data}}
|
||||
|
@@ -170,6 +170,30 @@ public:
|
||||
#endif
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxPNMHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxPNMHandler : public wxImageHandler
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxPNMHandler)
|
||||
|
||||
public:
|
||||
|
||||
inline wxPNMHandler()
|
||||
{
|
||||
m_name = "PNM file";
|
||||
m_extension = "pnm";
|
||||
m_type = wxBITMAP_TYPE_PNM;
|
||||
m_mime = "image/pnm";
|
||||
};
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
|
||||
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
|
||||
#endif
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxImage
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -200,6 +224,9 @@ public:
|
||||
void Create( int width, int height );
|
||||
void Destroy();
|
||||
|
||||
// return the new image with size width*height
|
||||
wxImage GetSubImage( const wxRect& ) const;
|
||||
|
||||
// return the new image with size width*height
|
||||
wxImage Scale( int width, int height ) const;
|
||||
|
||||
|
@@ -189,6 +189,43 @@ wxImage wxImage::Scale( int width, int height ) const
|
||||
return image;
|
||||
}
|
||||
|
||||
wxImage wxImage::GetSubImage( const wxRect &rect ) const
|
||||
{
|
||||
wxImage image;
|
||||
|
||||
wxCHECK_MSG( Ok(), image, _T("invalid image") );
|
||||
|
||||
wxCHECK_MSG( (rect.GetLeft()>=0) && (rect.GetTop()>=0) && (rect.GetRight()<=GetWidth()) && (rect.GetBottom()<=GetHeight())
|
||||
, image, _T("invalid subimage size") );
|
||||
|
||||
int subwidth=rect.GetWidth();
|
||||
const int subheight=rect.GetHeight();
|
||||
|
||||
image.Create( subwidth, subheight );
|
||||
|
||||
char unsigned *subdata = image.GetData(), *data=GetData();
|
||||
|
||||
wxCHECK_MSG( subdata, image, _T("unable to create image") );
|
||||
|
||||
if (M_IMGDATA->m_hasMask)
|
||||
image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
|
||||
|
||||
const int subleft=3*rect.GetLeft();
|
||||
const int width=3*GetWidth();
|
||||
subwidth*=3;
|
||||
|
||||
data+=rect.GetTop()*width+subleft;
|
||||
|
||||
for (long j = 0; j < subheight; ++j)
|
||||
{
|
||||
memcpy( subdata, data, subwidth);
|
||||
subdata+=subwidth;
|
||||
data+=width;
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
void wxImage::SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b )
|
||||
{
|
||||
wxCHECK_RET( Ok(), _T("invalid image") );
|
||||
@@ -388,7 +425,6 @@ bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype )
|
||||
}
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
//#include <stream.h>
|
||||
|
||||
bool wxImage::LoadFile( wxInputStream& stream, long type )
|
||||
{
|
||||
@@ -403,8 +439,8 @@ bool wxImage::LoadFile( wxInputStream& stream, long type )
|
||||
// here we can try to guess the handler according the extension,
|
||||
// but we lose the stream name !?
|
||||
// Probably we should write methods such as
|
||||
// bool wxImageHandler::IsAppropriate(wxString&)
|
||||
// bool wxImageHandler::IsAppropriate(sxInputStream&&)
|
||||
// bool wxImageHandler::CanRead(wxString&)
|
||||
// bool wxImageHandler::CanRead(sxInputStream&&)
|
||||
// for png : see example.c
|
||||
wxList &list=GetHandlers();
|
||||
off_t pos=stream.TellI();
|
||||
@@ -412,13 +448,14 @@ bool wxImage::LoadFile( wxInputStream& stream, long type )
|
||||
wxLogNull prevent_log;
|
||||
|
||||
for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
|
||||
{
|
||||
handler=(wxImageHandler*)node->GetData();
|
||||
//cout << handler->GetExtension() << endl;
|
||||
{
|
||||
handler=(wxImageHandler*)node->GetData();
|
||||
if (handler->LoadFile( this, stream, FALSE )) return TRUE;
|
||||
|
||||
stream.SeekI(pos);
|
||||
}
|
||||
|
||||
wxLogWarning( _T("No handler found for this image.") );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user