Search code examples
c++bitmapgdinullptr

c++ GDI Bitmap doesn't want to load


My name is Miguel, and I'm trying to get each single pixel in one .bmp, but so far, when i initialize the bitmap, it doesn't get any value, so i guess that i have initialized it wrong. This is my current code:(Snippet)

Bitmap *PerlinImage;

void OpenPerlinFile()
{
    PerlinImage = new Bitmap((WCHAR*)"C:\\Users\\Utilizador\\Documents\\Visual Studio 2012\\Projects\\Cube3D\\IDTech_JavaOpenGL_Port\\perlinNoise.bmp");
}

// END

void Initialize(void)
{
    OpenPerlinFile();

    Unit tempunit;
    Color color; 

    int ccount = 0;
    for (int h = 0; h != PerlinImage->GetHeight(); h++)
......

Now, can you look at my code, and maybe predict what I'm doing wrong.

Thank You

Miguel Petersen


Solution

  • Invoking GdiplusStartup is needed. Also check value of PerlinImage, if it's not NULL, then you could check error with PerlinImage->GetLastStatus(). If PerlinImage is NULL, then you may forget to call GdiplusStartup.