I have an application which is mostly working currently... It loads data
from a postgreSQL database {using libpqxx} and in the database are
images stored as binary strings. I am able to extract the images and
display them...
My problem is that some of the jpeg images in the database are
corrupted, they will not display for some reason. What happens when
these jpegs are displayed is that a message box is popped up saying that
the jpeg load failed....
I DON"T WANT THIS DIALOG BOX... I would like my application to handle
this situation gracefully by advancing to the next image, or displaying
an alternate image...
How can I get wxImage to not pop up the message box?
Thank you,
Michael Uman
PS: I am looking into the sourcecode shortly...
I don't know if this is the best option, but check out wxLogNull.
http://www.wxwidgets.org/manuals/2.6.2/wx_wxlognull.html#wxlognull
-Scott
I have looked at the source and determined what needs to be done....
It appears that there is the intention to allow the application to
request whether or not to display the error message box. Looking into
wxJPEGImageHandler I find the following code:
bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream,
bool verbose, int WXUNUSED(index) )
{
struct jpeg_decompress_struct cinfo;
struct wx_error_mgr jerr;
JSAMPARRAY tempbuf;
unsigned char *ptr;
unsigned stride;
image->Destroy();
cinfo.err = jpeg_std_error( &jerr.pub );
jerr.pub.error_exit = wx_error_exit;
if (!verbose) cinfo.err->output_message=NULL;
/* Establish the setjmp return context for wx_error_exit to use. */
if (setjmp(jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and
return.
*/
if (verbose)
wxLogError(_("JPEG: Couldn't load - file is probably
corrupted."));
(cinfo.src->term_source)(&cinfo);
jpeg_destroy_decompress(&cinfo);
if (image->Ok()) image->Destroy();
return false;
}
.
.
.
So, this function appears to take a boolean 'verbose' which determines
whether or not to display the message 'JPEG: Couldn't load - file is
probably corrupted.'. This is GOOD!!! ;)
BUT!!!! When I access the loader through wxImage using wxImage::Load(
wxInputStream& stream, long type, int index) it appears that the
function is hard-coded to pass 'true' as verbose... SEE BELOW:
bool wxImage::LoadFile( wxInputStream& stream, long type, int index )
{
UnRef();
m_refData = new wxImageRefData;
wxImageHandler *handler;
if ( type == wxBITMAP_TYPE_ANY )
{
wxList &list=GetHandlers();
for ( wxList::compatibility_iterator node = list.GetFirst();
node; node = node->GetNext() )
{
handler=(wxImageHandler*)node->GetData();
if ( handler->CanRead(stream) )
return handler->LoadFile(this, stream, true/*verbose*/,
index);
}
wxLogWarning( _("No handler found for image type.") );
return false;
}
handler = FindHandler(type);
if (handler == 0)
{
wxLogWarning( _("No image handler for type %d defined."), type
);
return false;
}
return handler->LoadFile(this, stream, true/*verbose*/, index);
}
It appears that my only workaround is to write my own version of
wxImage::LoadFile() which calls the ImageHandlers LoadFile passing my
own 'verbose' parameter as 'false'...
I would request anyone working on this class to consider opening up the
access to 'verbose' through the wxImage::LoadFile member, or setting a
flag on the wxImage class which is passed down to the wxImageHandler...
Thank you so much,
Michael Uman
ONE LOVE!
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-u...@lists.wxwidgets.org
> For additional commands, e-mail: wx-use...@lists.wxwidgets.org
>
>
Thanks for the response... If my initial attempt fails, I will use your
suggestion. As I said in my previous message, this is the result of a
wxLogError call...
Thanks,
Michael
Thanks for the response... If my initial attempt fails, I will use your
suggestion. As I said in my previous message, this is the result of a
wxLogError call...
Thanks,
Michael
On Wed, 2005-11-02 at 15:03, scott wrote:
bool wxImage::LoadFile( wxInputStream& stream, long type, int index,
verbose = true)
...
return handler->LoadFile(this, stream, verbose, index);
It keeps backward compatibility and gives you the freedom you want.
Janos