本文整理汇总了C++中wxBitmap::GetSubBitmap方法的典型用法代码示例。如果您正苦于以下问题:C++ wxBitmap::GetSubBitmap方法的具体用法?C++ wxBitmap::GetSubBitmap怎么用?C++ wxBitmap::GetSubBitmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wxBitmap
的用法示例。
在下文中一共展示了wxBitmap::GetSubBitmap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Add
int wxImageList::Add( const wxBitmap &bitmap )
{
wxASSERT_MSG( (bitmap.GetScaledWidth() >= m_width && bitmap.GetScaledHeight() == m_height)
|| (m_width == 0 && m_height == 0),
wxT("invalid bitmap size in wxImageList: this might work ")
wxT("on this platform but definitely won't under Windows.") );
// Mimic behaviour of Windows ImageList_Add that automatically breaks up the added
// bitmap into sub-images of the correct size
if (m_width > 0 && bitmap.GetScaledWidth() > m_width && bitmap.GetScaledHeight() >= m_height)
{
int numImages = bitmap.GetScaledWidth() / m_width;
for (int subIndex = 0; subIndex < numImages; subIndex++)
{
wxRect rect(m_width * subIndex, 0, m_width, m_height);
wxBitmap tmpBmp = bitmap.GetSubBitmap(rect);
m_images.Append( new wxBitmap(tmpBmp) );
}
}
else
{
m_images.Append( new wxBitmap(bitmap) );
}
if (m_width == 0 && m_height == 0)
{
m_width = bitmap.GetScaledWidth();
m_height = bitmap.GetScaledHeight();
}
return m_images.GetCount() - 1;
}
示例2: DoDrawBitmap
void osm_pi::DoDrawBitmap( const wxBitmap &bitmap, wxCoord x, wxCoord y, bool usemask )
{
if ( m_pdc ) {
wxLogMessage (_T("OSM_PI: DoDrawBitmap %i,%i"),x,y);
m_pdc->DrawBitmap( bitmap, x, y, usemask );
} else {
wxLogMessage (_T("OSM_PI: DoDrawBitmapGL %i,%i"),x,y);
// GL doesn't draw anything if x<0 || y<0 so we must crop image first
wxBitmap bmp;
if ( x < 0 || y < 0 ) {
int dx = (x < 0 ? -x : 0);
int dy = (y < 0 ? -y : 0);
int w = bitmap.GetWidth()-dx;
int h = bitmap.GetHeight()-dy;
/* picture is out of viewport */
if ( w <= 0 || h <= 0 )
return;
wxBitmap newBitmap = bitmap.GetSubBitmap( wxRect( dx, dy, w, h ) );
x += dx;
y += dy;
bmp = newBitmap;
} else {
bmp = bitmap;
}
wxImage image = bmp.ConvertToImage();
int w = image.GetWidth(), h = image.GetHeight();
if ( usemask ) {
unsigned char *d = image.GetData();
unsigned char *a = image.GetAlpha();
unsigned char mr, mg, mb;
if( !image.GetOrFindMaskColour( &mr, &mg, &mb ) && !a )
printf("trying to use mask to draw a bitmap without alpha or mask\n");
unsigned char *e = new unsigned char[4*w*h];
// int w = image.GetWidth(), h = image.GetHeight();
int sb = w*h;
unsigned char r, g, b;
for ( int i=0 ; i<sb ; i++ ) {
r = d[i*3 + 0];
g = d[i*3 + 1];
b = d[i*3 + 2];
e[i*4 + 0] = r;
e[i*4 + 1] = g;
e[i*4 + 2] = b;
e[i*4 + 3] = a ? a[i] :
((r==mr)&&(g==mg)&&(b==mb) ? 0 : 255);
}
glColor4f( 1, 1, 1, 1 );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glRasterPos2i( x, y );
glPixelZoom( 1, -1 );
glDrawPixels( w, h, GL_RGBA, GL_UNSIGNED_BYTE, e );
glPixelZoom( 1, 1 );
glDisable( GL_BLEND );
free( e );
} else {
glRasterPos2i( x, y );
glPixelZoom( 1, -1 ); /* draw data from top to bottom */
glDrawPixels( w, h, GL_RGB, GL_UNSIGNED_BYTE, image.GetData() );
glPixelZoom( 1, 1 );
}
}
}
示例3: DrawBitmap
void ocpnDC::DrawBitmap( const wxBitmap &bitmap, wxCoord x, wxCoord y, bool usemask )
{
wxBitmap bmp;
if( x < 0 || y < 0 ) {
int dx = ( x < 0 ? -x : 0 );
int dy = ( y < 0 ? -y : 0 );
int w = bitmap.GetWidth() - dx;
int h = bitmap.GetHeight() - dy;
/* picture is out of viewport */
if( w <= 0 || h <= 0 ) return;
wxBitmap newBitmap = bitmap.GetSubBitmap( wxRect( dx, dy, w, h ) );
x += dx;
y += dy;
bmp = newBitmap;
} else {
bmp = bitmap;
}
if( dc ) dc->DrawBitmap( bmp, x, y, usemask );
else {
wxImage image = bmp.ConvertToImage();
int w = image.GetWidth(), h = image.GetHeight();
if( usemask ) {
unsigned char *d = image.GetData();
unsigned char *a = image.GetAlpha();
unsigned char mr, mg, mb;
if( !image.GetOrFindMaskColour( &mr, &mg, &mb ) && !a ) printf(
"trying to use mask to draw a bitmap without alpha or mask\n" );
unsigned char *e = new unsigned char[4 * w * h];
// int w = image.GetWidth(), h = image.GetHeight();
{
for( int y = 0; y < h; y++ )
for( int x = 0; x < w; x++ ) {
unsigned char r, g, b;
int off = ( y * image.GetWidth() + x );
r = d[off * 3 + 0];
g = d[off * 3 + 1];
b = d[off * 3 + 2];
e[off * 4 + 0] = r;
e[off * 4 + 1] = g;
e[off * 4 + 2] = b;
e[off * 4 + 3] =
a ? a[off] : ( ( r == mr ) && ( g == mg ) && ( b == mb ) ? 0 : 255 );
}
}
glColor4f( 1, 1, 1, 1 );
GLDrawBlendData( x, y, w, h, GL_RGBA, e );
delete[] ( e );
} else {
glRasterPos2i( x, y );
glPixelZoom( 1, -1 ); /* draw data from top to bottom */
glDrawPixels( w, h, GL_RGB, GL_UNSIGNED_BYTE, image.GetData() );
glPixelZoom( 1, 1 );
}
}
}
示例4: SplitGlyphs
void wxSpeedButton::SplitGlyphs(const wxBitmap &inBitmap, int inCount) {
int n;
int bw,bh;
int sw,sh;
wxRect rr;
wxImage img;
wxBitmap *bmp;
// no images yet
mGlyphUp = wxNullBitmap;
mGlyphDown = wxNullBitmap;
mGlyphDisabled = wxNullBitmap;
// if no bitmap, then we are done
if (! inBitmap.Ok()) return;
// size of the bitmap
bw = inBitmap.GetWidth();
bh = inBitmap.GetHeight();
if ((bw <= 0) || (bh <= 0)) return;
// determine the number of images in the source bitmap
// if inCount > 0, then that is the count specified by the user
// else, count number of square sub-images
if (inCount > 0) n = inCount;
else if (bw >= bh) n = (int) bw / bh;
else n = (int) bh / bw;
// extract sub-images, either vertically or horizontally
if (n == 1) {
mGlyphUp = inBitmap;
mGlyphDown = inBitmap;
img = inBitmap.ConvertToImage();
img = img.ConvertToGreyscale();
bmp = new wxBitmap(img);
mGlyphDisabled = *bmp;
}
else if ((n == 2) && (bw >= bh)) {
sw = (int) bw / n;
sh = bh;
rr.SetX(0);
rr.SetY(0);
rr.SetWidth(sw);
rr.SetHeight(sh);
mGlyphUp = inBitmap.GetSubBitmap(rr);
mGlyphDown = inBitmap.GetSubBitmap(rr);
rr.SetX(sw);
mGlyphDisabled = inBitmap.GetSubBitmap(rr);
}
else if ((n == 2) && (bh > bw)) {
sw = bw;
sh = (int) bh / n;
rr.SetX(0);
rr.SetY(0);
rr.SetWidth(sw);
rr.SetHeight(sh);
mGlyphUp = inBitmap.GetSubBitmap(rr);
mGlyphDown = inBitmap.GetSubBitmap(rr);
rr.SetY(sh);
mGlyphDisabled = inBitmap.GetSubBitmap(rr);
}
else if ((n >= 3) && (bw >= bh)) {
sw = (int) bw / n;
sh = bh;
rr.SetX(0);
rr.SetY(0);
rr.SetWidth(sw);
rr.SetHeight(sh);
mGlyphUp = inBitmap.GetSubBitmap(rr);
rr.SetX(sw);
mGlyphDown = inBitmap.GetSubBitmap(rr);
rr.SetX(sw+sw);
mGlyphDisabled = inBitmap.GetSubBitmap(rr);
}
else { // (n >= 3) && (bh > bw)
sw = bw;
sh = (int) bh / n;
rr.SetX(0);
rr.SetY(0);
rr.SetWidth(sw);
rr.SetHeight(sh);
mGlyphUp = inBitmap.GetSubBitmap(rr);
rr.SetY(sh);
mGlyphDown = inBitmap.GetSubBitmap(rr);
rr.SetY(sh+sh);;
mGlyphDisabled = inBitmap.GetSubBitmap(rr);
};
// make them all transparent
//.........这里部分代码省略.........