GDI+ question: Bitmap:FromFile, how to detect non-existent image file?
-
Hi I am currently trying to use Bitmap::FromFile function provided by GDI+. It seems that the method does not provide any notification when the specified file does not exist. Subsequent calls to Bitmap::GetPixel also does not raise any error, it just gives a result of 255 for all the A, R,G, and B values. My question is, is there a way to check whether the FromFile method has successfully loaded an image or whether the image does not exist? Thanks!
-
Hi I am currently trying to use Bitmap::FromFile function provided by GDI+. It seems that the method does not provide any notification when the specified file does not exist. Subsequent calls to Bitmap::GetPixel also does not raise any error, it just gives a result of 255 for all the A, R,G, and B values. My question is, is there a way to check whether the FromFile method has successfully loaded an image or whether the image does not exist? Thanks!
GDI+ is implemented strangely. The public interface is C++ classes, but to get around the fact that there's no common Application Binary Interface for C++ on Windows, and to allow both .NET and non-Microsoft compilers to use GDI+, the main body of the implementation is contained in a DLL with a 'flat', C-style interface. The implementation of the GDI+ classes is contained entirely within the GDI+ headers, in terms of this flat API. The Bitmap class is implemented in GdiPlusBitmap.h.
Bitmap::FromFile
simply creates a newBitmap
object, using theBitmap(const WCHAR* filename, BOOL useEmbeddedColorManagement)
constructor. If an error occurs, the underlying flat API call (GdipCreateBitmapFromFileICM
orGdipCreateBitmapFromFile
depending on whether the second parameter is set or not) returns an error code, which theBitmap
constructor stores internally. This error code can be retrieved using theGetLastStatus
method (inherited fromImage
). I would expect that, if the file was not found, this method will returnFileNotFound
from theStatus
enumeration. Stability. What an interesting concept. -- Chris Maunder -
Hi I am currently trying to use Bitmap::FromFile function provided by GDI+. It seems that the method does not provide any notification when the specified file does not exist. Subsequent calls to Bitmap::GetPixel also does not raise any error, it just gives a result of 255 for all the A, R,G, and B values. My question is, is there a way to check whether the FromFile method has successfully loaded an image or whether the image does not exist? Thanks!