Page 1 of 1

SOLVED: wxImage.LoadFile

Posted: Sun Feb 26, 2017 2:58 am
by Nefarious
I am trying to use wxImage and wxBitmap so have been following the image sample. I can draw to a wxBitmap, and now I am trying to draw a jpg to a wxBitmap then I can draw it on the screen. I have a stream of jpeg data that I read and I thought the process would be something like:

Code: Select all

// mXPixels is the number of pixels in x
// mYPixels is the number of pixels in y

// allocate the data for the image
mImageSize = mXPixels * mYPixels * 3;
byte* bpImage = (byte*)malloc(mImageSize);

// Get the image from the stream
ReadImage(bpImage);

wxBitmap mBitmap(mXPixels, mYPixels);
wxImage mImage = bitmap.ConvertToImage();
mImage.SetType(wxBITMAP_TYPE_JPEG);
// pass the jpeg data to the image
mImage.SetData(bpImage);

// get a wxBitmap of the bImage
wxBitmap foo = wxBitmap(mImage);

// Draw as
dc.DrawBitmap(foo, 0, 0);
It of course didn't work because I don't really know what I am doing. So I tried to read in the jpg file from the image sample and that won't work. I can't tell why, but simply loading the jpg file from the image sample won't work.

Code: Select all

if (wxFile::Exists(wxT("horse.jpg")))
{
	wxLogError(wxT("JPG image Exists"));
}
else
{
	wxLogError(wxT("JPG image Doesn't Exist"));
}
reports that the image exists

but

Code: Select all

if (!hImage.LoadFile(wxT("horse.jpg"), wxBITMAP_TYPE_JPEG,))
{
	wxLogError(wxT("Can't load JPG image"));
}
always reports that it can't load the jpg file.

I put the file in the same directory as the executable, I put it in the same directory as the source file. I tried "./horse.jpg", I tried ".\\horse.jpg" since it is windows :(. I can't load the jpg file and I don't know why it won't load.

I searched for how to find errors, are log files created? Something has to be there, this code has been around a long time.

Sorry to be a bother.

Re: wxImage.LoadFile

Posted: Sun Feb 26, 2017 4:49 am
by Nefarious
I never read the App::OnInit, never thought about it until I was pulling out my hair. Didn't see the call

wxInitAllImageHandlers();

Re: SOLVED: wxImage.LoadFile

Posted: Thu Oct 11, 2018 12:41 pm
by buttonsrtoys
+1. Solved my problem, too. Thanks for posting sol'n