Let me explain in more detail:
- method wxImage* wxMainFrame::LoadImageFromBlob(const unsigned char *data, int size) returns an image in wxImage format.
- next I override my own cell renderer from wxGridCellRenderer - class wxBmpGridCellRenderer
- further, when rendering the wxGrid grid, I assign a new renderer
Code: Select all
SetCellRenderer(row, col, new wxBmpCellRenderer(bmp));
The question is, which class would it be correct to make this image a member of? Maybe it would be more correct to include the LoadImageFromBlob method in the wxBmpGridCellRenderer class? Sorry for possibly stupid questions, I'm just learning.
Below is the syntax for overriding the Draw method
Code: Select all
void wxBmpGridCellRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected)
{
wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
dc.SetClippingRegion(rect);
dc.DrawBitmap(*m_foto ,rect.x,rect.y);
dc.DestroyClippingRegion();
}
Below is the implementation of the wxMainFrame::LoadImageFromBlob method, it returns the wxImage image
Code: Select all
wxImage* testWxSmithFrame::LoadImageFromBlob(const unsigned char *data, int size)
{
if( data != NULL )
{
wxMemoryInputStream mi(data, size);
wxImage *img = new wxImage(mi, wxBITMAP_TYPE_ANY);
if( img != NULL && img->IsOk() ) return img;
// wxLogDebug( wxT("DB::LoadImageFromBlob error: data=%p size=%d"), data, size);
// caller is responsible for deleting the pointer
delete img;
}
return NULL;
}
The following code outputs an image from memory to a StaticBitmap while scaling the image.
Code: Select all
wxMemoryBufferBufferOut;
void *pBlob = pResults->GetResultBlob(_("FIMG"),BufferOut);
const unsigned char *pRetrievedBuffer = (const unsigned char*)pBlob;
intlen;
len = (int)BufferOut.GetDataLen();
m_foto = LoadImageFromBlob(pRetrievedBuffer,len);
StaticBitmap1->SetBitmap(wxBitmap(m_foto->Rescale(wxSize(218,290).GetWidth(),wxSize(218,290).GetHeight())));