سؤال

I am using OpenCV's imdecode() function. When I pass a partial image, it prints to screen saying "libpng error: PNG input buffer is incomplete". I tried putting that in a try/catch block but I still see that being printed. How do I handle such errors?

هل كانت مفيدة؟

المحلول

libpng by default prints error messages to stderr. But you can supply your own replacement error handler to do whatever you want with the error messages. See the explanation (look for "user_error_fn) in the libpng-manual.txt file that is distributed with libpng.

You don't need to rebuild libpng to do that; simply put your replacement handler in your own source code along with a pointer to it in your png_create_read_struct() call.

نصائح أخرى

Those errors are shown because it prints directly to the output, no exception is thrown. Note that libpng is developed in C, not C++.

To remove this message, you pretty much must edit the libpng source code and recompile it.

There is only one thing else you could try: maybe libpng prints it to stderr instead of stdout. If so, you can redirect stderr to /dev/null or something else.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top