FreeImage to Load PNGs

I'm trying out this example in my code to load and display a PNG image. How do I declare "rcDest" that is used in this example:

1
2
3
4
5
6
7
8
9
10
FIBITMAP *dib = FreeImage_Load(FIF_PNG, "test.png", PNG_DEFAULT);

SetStretchBltMode(hDC, COLORONCOLOR);
StretchDIBits(hDC, rcDest.left, rcDest.top,

    rcDest.right-rcDest.left, rcDest.bottom-rcDest.top,
    0, 0, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib),
    FreeImage_GetBits(dib), FreeImage_GetInfo(dib), DIB_RGB_COLORS, SRCCOPY);

FreeImage_Unload(dib);
The type is irrelevant as long as it has those four members (the Windows structure RECT fits the bill). The rectangle specifies the destination rectangle.
This code gives the errors below it:

1
2
3
4
5
6
7
8
9
10
11
12
            HDC hDC;
            RECT rcDest;
            FIBITMAP *dib = FreeImage_Load(FIF_PNG, "test.png", PNG_DEFAULT);

            SetStretchBltMode(hDC, COLORONCOLOR);
            StretchDIBits(hDC, rcDest.left, rcDest.top,

            rcDest.right-rcDest.left, rcDest.bottom-rcDest.top,
            0, 0, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib),
            FreeImage_GetBits(dib), FreeImage_GetInfo(dib), DIB_RGB_COLORS, SRCCOPY);

            FreeImage_Unload(dib);


Errors:
1
2
3
4
5
6
7
obj\Release\main.o:main.cpp|| undefined reference to `_imp__FreeImage_Load@12'|
obj\Release\main.o:main.cpp|| undefined reference to `_imp__FreeImage_GetInfo@4'|
obj\Release\main.o:main.cpp|| undefined reference to `_imp__FreeImage_GetBits@4'|
obj\Release\main.o:main.cpp|| undefined reference to `_imp__FreeImage_GetHeight@4'|
obj\Release\main.o:main.cpp|| undefined reference to `_imp__FreeImage_GetWidth@4'|
obj\Release\main.o:main.cpp|| undefined reference to `_imp__FreeImage_Unload@4'|
||=== Build finished: 6 errors, 0 warnings (0 minutes, 1 seconds) ===|
Last edited on
These are linker errors, it means you have to add freeimage.lib or whatever is called to linker input.
Where is "FreeImage.lib" included in the latest ZIP packaged source? Apparently I need to link to it. I'm using Code::Blocks 12.11 with MinGW.
For MinGW is likely called "libfreeimage.a" or something like that. It is produced after you compile FreeImage from source code using the same compiler.
The image doesn't show up in the window with this code, linked to "FreeImage.lib". I've included "FreeImage.dll" in the "bin\Release" folder, and with the image it needs. Code:

1
2
3
4
5
6
7
8
9
10
11
            RECT rcDest;
            FIBITMAP *dib = FreeImage_Load(FIF_PNG, "Mac.png", PNG_DEFAULT);

            SetStretchBltMode(hDC, COLORONCOLOR);
            StretchDIBits(hDC, rcDest.left, rcDest.top,

            rcDest.right-rcDest.left, rcDest.bottom-rcDest.top,
            0, 0, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib),
            FreeImage_GetBits(dib), FreeImage_GetInfo(dib), DIB_RGB_COLORS, SRCCOPY);

            FreeImage_Unload(dib);
I never used FreeImage or any image library in windows (you could load PNG images natively using GDI+ in windows, no library needed), but the idea is that you need to check return values from any functions you call and see where the problem is exactly.
Topic archived. No new replies allowed.