wxImage::Loadfile using wxMemoryInputStr overload issue-Reg Topic is solved

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
udayakumar
In need of some credit
In need of some credit
Posts: 2
Joined: Fri Jan 28, 2011 3:46 am

wxImage::Loadfile using wxMemoryInputStr overload issue-Reg

Post by udayakumar »

Hi Team,

My requirement is to load an encoded image from the memory buffer directly rather from the file.
I am trying to use wxImage::LoadFile API to load bmp/jpeg/TIF(G4) images from the memory buffer. I am able to load using FilePath but failed using memorystream as follows,
char* pcEncodedBuffer = new char[nFileSize];
wxMemoryInputStream memstream(pcEncodedBuffer, nFileSize);
objImage.LoadFile(memstream, wxBITMAP_TYPE_TIF, -1);

Can u please help me in this regard? Please let me know if you need any other information.

I have attached the complete code for reference.
[/img]
Attachments
wxImageLoadFileUsingBuffer.cpp
Code using wxImage::LoadFile API in both overloaded formats for reference
(1.52 KiB) Downloaded 164 times
Udayakumar Arunachalam,
Imaging Engineer.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin »

You're using istream incorrectly. See the example here for reading a file: http://www.cplusplus.com/reference/iost ... ream/read/ , ios::beg is not necessarily 0. And there are more efficient ways than reading 1 byte at a time. Check for errors after every read.

You may want to try wxFileInputStream instead of istream, and the corresponding wxMemoryInputStream constructor.
udayakumar
In need of some credit
In need of some credit
Posts: 2
Joined: Fri Jan 28, 2011 3:46 am

Post by udayakumar »

Actually, the issue is not with the API/stream. I have found it to be the way in which the file buffer was read.

Both JPEG and TIF images have EOF jus after the header.
Hence, the stream is built with an invalid buffer and it did not work.

I have used fread() to read the entire file a a single block instead of reading all the characters, one at a time. This has resolved the issue.


Thanks to wxWidgets!!!
Udayakumar Arunachalam,
Imaging Engineer.
Post Reply