本文整理汇总了C++中wxImage类的典型用法代码示例。如果您正苦于以下问题:C++ wxImage类的具体用法?C++ wxImage怎么用?C++ wxImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了wxImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TransferToWx
void TransferToWx(const Map& map, wxImage& wx)
{
wx.Create(map.width * 8, map.height * 8);
if (map.tileset->bpp == 4)
{
for (unsigned int i = 0; i < map.data.size(); i++)
{
int x = i % map.width;
int y = i / map.width;
int tile_id = map.data[i] & 0x3FF;
int pal_id = (map.data[i] >> 12) & 0xF;
const Tile& tile = map.tileset->tilesExport[tile_id];
const PaletteBank& palette = map.tileset->paletteBanks[pal_id];
for (unsigned int j = 0; j < TILE_SIZE; j++)
{
unsigned char pix = tile.pixels[j];
if (!pix) continue;
const auto& c = palette.At(pix);
wx.SetRGB(x * 8 + j % 8, y * 8 + j / 8, c.r << 3, c.g << 3, c.b << 3);
}
}
}
else
{
for (unsigned int i = 0; i < map.data.size(); i++)
示例2: SetImage
void wxHtmlImageCell::SetImage(const wxImage& img)
{
#if !defined(__WXMSW__) || wxUSE_WXDIB
if ( img.IsOk() )
{
delete m_bitmap;
int ww, hh;
ww = img.GetWidth();
hh = img.GetHeight();
if ( m_bmpW == wxDefaultCoord)
m_bmpW = ww;
if ( m_bmpH == wxDefaultCoord)
m_bmpH = hh;
// Only scale the bitmap at the rendering stage,
// so we don't lose quality twice
/*
if ((m_bmpW != ww) || (m_bmpH != hh))
{
wxImage img2 = img.Scale(m_bmpW, m_bmpH);
m_bitmap = new wxBitmap(img2);
}
else
*/
m_bitmap = new wxBitmap(img);
}
#endif
}
示例3: SetPixels
void Surface::SetPixels( const wxImage& image )
{
m_Format = Format( image );
size_t numPixels = (size_t)m_Format.m_Pitch*m_Format.m_CanvasHeight;
if ( m_Format.GetDepth() == 24 ) {
m_Pixels = (void*)new char[ numPixels ];
memcpy( m_Pixels, image.GetData(), numPixels );
} else if ( m_Format.GetDepth() == 32 ) {
// wx uses a screwed up image format with a separate alpha plane. We need to convert into RGBA
m_Pixels = (void*)new char[ numPixels ];
unsigned int sPitch = image.GetWidth()*3;
unsigned char* pData = image.GetData();
unsigned char* pAlpha= image.GetAlpha();
unsigned int aMask = m_Format.m_AMask;
unsigned int aShift= m_Format.m_AShift;
int w = (int)m_Format.GetWidth();
int h = (int)m_Format.GetHeight();
for ( int y = 0; y < h; y++ ) {
unsigned int *pSrc = (unsigned int*)(pData + y*sPitch);
unsigned int *pDst = (unsigned int*)((unsigned char*)m_Pixels + y*m_Format.GetPitch());
for ( int x = 0; x < w; x++ ) {
*pDst++ = ((*pSrc) & ~aMask) | ((*pAlpha) << aShift);
pAlpha++; pSrc = (unsigned int *)(((unsigned char*)pSrc) + 3); // performance issues with odd addresses???
}
}
} else if ( m_Format.GetDepth() == 8 ) {
// 8 bit gray scale - downscale to gray using luma
} else if ( m_Format.GetDepth() == 1 ) {
// 1 bit bitmap
} else {
// cannot compute
m_Pixels = NULL;
}
}
示例4: CreateFromImage
bool wxBitmap::CreateFromImage(const wxImage& image, int depth)
{
UnRef();
wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") )
wxCHECK_MSG( depth == -1 || depth == 1, FALSE, wxT("invalid bitmap depth") )
if (image.GetWidth() <= 0 || image.GetHeight() <= 0)
return false;
m_refData = new wxBitmapRefData();
if (depth == 1)
{
return CreateFromImageAsBitmap(image);
}
else
{
#ifdef __WXGTK20__
if (image.HasAlpha())
return CreateFromImageAsPixbuf(image);
#endif
return CreateFromImageAsPixmap(image);
}
}
示例5: AdjustAndSetBitmap
void AdjustAndSetBitmap(int size, wxImage &image, wxBitmap&bitmap) {
if (image.GetHeight() == size) {
bitmap = wxBitmap(image);
} else {
wxImage scaled = image.Scale(size, size, wxIMAGE_QUALITY_HIGH);
bitmap = wxBitmap(scaled);
}
}
示例6: wxCreateGreyedImage
bool wxCreateGreyedImage(const wxImage& in, wxImage& out)
{
#if wxUSE_IMAGE
out = in.ConvertToGreyscale();
if ( out.IsOk() )
return true;
#endif // wxUSE_IMAGE
return false;
}
示例7:
ImagePanelDyn::ImagePanelDyn(wxWindow* parent, wxImage &imageScaled, wxImage &imageNoScaled, wxPoint point, wxSize size, int style) :
wxPanel(parent, wxID_ANY, point, size, style)
{
image0 = imageScaled.Copy();
image1 = imageNoScaled.Copy();
w = point.x;
h = point.y;
win = parent;
}
示例8: assert
wxImage zen::stackImages(const wxImage& img1, const wxImage& img2, ImageStackLayout dir, ImageStackAlignment align, int gap)
{
assert(gap >= 0);
gap = std::max(0, gap);
const int img1Width = img1.GetWidth ();
const int img1Height = img1.GetHeight();
const int img2Width = img2.GetWidth ();
const int img2Height = img2.GetHeight();
int width = std::max(img1Width, img2Width);
int height = std::max(img1Height, img2Height);
switch (dir)
{
case ImageStackLayout::HORIZONTAL:
width = img1Width + gap + img2Width;
break;
case ImageStackLayout::VERTICAL:
height = img1Height + gap + img2Height;
break;
}
wxImage output(width, height);
output.SetAlpha();
::memset(output.GetAlpha(), wxIMAGE_ALPHA_TRANSPARENT, width * height);
auto calcPos = [&](int imageExtent, int totalExtent)
{
switch (align)
{
case ImageStackAlignment::CENTER:
return (totalExtent - imageExtent) / 2;
case ImageStackAlignment::LEFT:
return 0;
case ImageStackAlignment::RIGHT:
return totalExtent - imageExtent;
}
assert(false);
return 0;
};
switch (dir)
{
case ImageStackLayout::HORIZONTAL:
writeToImage(img1, output, wxPoint(0, calcPos(img1Height, height)));
writeToImage(img2, output, wxPoint(img1Width + gap, calcPos(img2Height, height)));
break;
case ImageStackLayout::VERTICAL:
writeToImage(img1, output, wxPoint(calcPos(img1Width, width), 0));
writeToImage(img2, output, wxPoint(calcPos(img2Width, width), img1Height + gap));
break;
}
return output;
}
示例9: StretchDraw
bool CFrameWnd::StretchDraw(wxDC &x_dc, wxImage &x_img, wxRect &x_rect)
{_STT();
if ( !x_img.Ok() ) return FALSE;
// The slow but portable way...
wxImage cWxImage = x_img.Copy();
cWxImage.Rescale( x_rect.GetWidth(), x_rect.GetHeight() );
x_dc.DrawBitmap( cWxImage, x_rect.x, x_rect.y );
return TRUE;
}
示例10: subRect
// static
ImageArray ImageRoll::SplitH(const wxImage &src, wxColour magicColor)
{
ImageArray result;
int width = src.GetWidth();
int height = src.GetHeight();
unsigned char *data = src.GetData();
unsigned char *ptr = data;
unsigned char magicRed = magicColor.Red();
unsigned char magicGreen = magicColor.Green();
unsigned char magicBlue = magicColor.Blue();
bool cur, prev;
int i, j, start;
// Sanity check...
if (width<=0 || height<=0 || data==NULL)
return result;
prev = false;
start = 0;
for(i=0; i<width+1; i++) {
if (i < width) {
unsigned char *ptr2 = ptr;
cur = true;
for(j=0; j<height && cur; j++) {
if (!(ptr2[0] == magicRed &&
ptr2[1] == magicGreen &&
ptr2[2] == magicBlue))
cur = false;
ptr2 += 3 * width;
}
}
else
cur = !prev;
if ((cur && !prev)) {
wxRect subRect(start, 0, i-start, height);
wxImage subImage;
if (subRect.width > 0)
subImage = src.GetSubImage(subRect);
else
subImage = wxImage(subRect.width, subRect.height);
result.Add(subImage);
}
else if (!cur && prev) {
start = i;
}
prev = cur;
ptr += 3;
}
return result;
}
示例11: addMipMap
static void addMipMap(GLuint* texture, const wxImage &l_Image, int &level) {
if (l_Image.IsOk() == true)
{
glTexImage2D(GL_TEXTURE_2D, level, GL_RGB, (GLsizei)l_Image.GetWidth(), (GLsizei)l_Image.GetHeight(),
0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)l_Image.GetData());
int err = glGetError();
if (err == GL_NO_ERROR) {
level++;
}
}
}
示例12: recognize
wxString Ocr::recognize(const wxImage & image) const
{
char * text = _api->TesseractRect(image.GetData(),
3,
3 * image.GetWidth(),
0,
0,
image.GetWidth(),
image.GetHeight());
wxString outputText(text, wxConvUTF8);
delete[] text;
return outputText;
}
示例13: GreyOutImage
void GreyOutImage(wxImage &img)
{
unsigned char *data = img.GetData();
unsigned char r,g,b;
unsigned char mr,mg,mb;
int i, tst;
int len = img.GetHeight()*img.GetWidth()*3;
if (img.HasMask())
{
mr = img.GetMaskRed();
mg = img.GetMaskGreen();
mb = img.GetMaskBlue();
}
tst=0;
for (i=0;i<len;i+=3)
{
r=data[i]; g=data[i+1]; b=data[i+2];
if (!img.HasMask() ||
r!=mr || g!=mg || b!=mb)
{
if (!tst)
{
tst=1;
}
r = (unsigned char)((230.0-r)*0.7+r);
g = (unsigned char)((230.0-g)*0.7+g);
b = (unsigned char)((230.0-b)*0.7+b);
data[i]=r; data[i+1]=g; data[i+2]=b;
}
}
}
示例14: DoRegionUnion
static bool DoRegionUnion(wxRegion& region,
const wxImage& image,
unsigned char loR,
unsigned char loG,
unsigned char loB,
int tolerance)
{
unsigned char hiR, hiG, hiB;
hiR = (unsigned char)wxMin(0xFF, loR + tolerance);
hiG = (unsigned char)wxMin(0xFF, loG + tolerance);
hiB = (unsigned char)wxMin(0xFF, loB + tolerance);
// Loop through the image row by row, pixel by pixel, building up
// rectangles to add to the region.
int width = image.GetWidth();
int height = image.GetHeight();
for (int y=0; y < height; y++)
{
wxRect rect;
rect.y = y;
rect.height = 1;
for (int x=0; x < width; x++)
{
// search for a continuous range of non-transparent pixels
int x0 = x;
while ( x < width)
{
unsigned char R = image.GetRed(x,y);
unsigned char G = image.GetGreen(x,y);
unsigned char B = image.GetBlue(x,y);
if (( R >= loR && R <= hiR) &&
( G >= loG && G <= hiG) &&
( B >= loB && B <= hiB)) // It's transparent
break;
x++;
}
// Add the run of non-transparent pixels (if any) to the region
if (x > x0) {
rect.x = x0;
rect.width = x - x0;
region.Union(rect);
}
}
}
return true;
}
示例15: wxT
void BM2CMP_FRAME::ExportFile( FILE* aOutfile, OUTPUT_FMT_ID aFormat )
{
// Create a potrace bitmap
int h = m_NB_Image.GetHeight();
int w = m_NB_Image.GetWidth();
potrace_bitmap_t* potrace_bitmap = bm_new( w, h );
if( !potrace_bitmap )
{
wxString msg;
msg.Printf( wxT( "Error allocating memory for potrace bitmap" ) );
wxMessageBox( msg );
return;
}
/* fill the bitmap with data */
for( int y = 0; y < h; y++ )
{
for( int x = 0; x < w; x++ )
{
unsigned char pix = m_NB_Image.GetGreen( x, y );
BM_PUT( potrace_bitmap, x, y, pix ? 1 : 0 );
}
}
bitmap2component( potrace_bitmap, aOutfile, aFormat, m_imageDPI.x, m_imageDPI.y );
}