Reputation: 354
I have raw data of an image captured from my phone, it's resolution is 480*800, format is RGBA. Then I want to save it into a jpeg image with wxImage function. The cod is listed below:
wxFile m_bufferfile = wxFile(wxT("out.raw"));
if(!m_bufferfile->IsOpened())
{
wxLogMessage( _T("Fail to open the config file.") );
}
m_count = m_bufferfile->Length();
unsigned char* rawdata = new unsigned char[m_count];
for(unsigned int i = 0; i < m_count; i=i+4)
{
m_bufferfile->Seek(1,wxFromCurrent);
m_bufferfile->Read(rawdata, 3);
}
wxImage *image = new wxImage(480, 800, rawdata, false);
image->SaveFile(wxT("raw.jpg"),wxBITMAP_TYPE_JPEG);
When I opened the raw.jpg, it turns out black. Is there wrong?
Upvotes: 1
Views: 1704
Reputation: 76822
You have a bug here:
m_bufferfile->Read(rawdata, 3);
You only ever read into the beginning of your rawdata
buffer.
Upvotes: 1