Monday, December 31, 2007

Programming Tips: Filenames in GDI+

When using Bitmap class of GDI+ in Visual Studio 2005 and unicode names there is a problem when we try to load an image file which's name was acquired by a function of Windows API. While classic API returns paths in form: c:\some_folder\some_other_folder\filename , the Bitmap class constructor treats \ (backslash) as an escape character that means it is not treating it as a character but as an instruction to consider the next symbol as standard character (like & in HTML). In order for Bitmap constructor to see the file the path must be modified so that every backslash in the original path is followed by one more backslash. ie c:\\some_folder\\some_other_folder\\filename.

No comments: