loadimage

This function is used to load image from a file.

// Get an image from a picture file(bmp/gif/jpg/png/tif/emf/wmf/ico)
void loadimage(
	IMAGE* pDstImg,			// Image object pointer for saving images
	LPCTSTR pImgFile,		// Picture file name
	int nWidth = 0,			//  The stretch width of the picture
	int nHeight = 0,		// The stretch height of the picture
	bool bResize = false	// Whether to resize the IMAGE to fit the picture
);
// Get an image from a resource file
(bmp/gif/jpg/png/tif/emf/wmf/ico)
void loadimage(
	IMAGE* pDstImg,			// Image object pointer for saving images
	LPCTSTR pResType,		// Types of resources
	LPCTSTR pResName,		// Resource name
	int nWidth = 0,			// The stretch width of the picture
	int nHeight = 0,		// The stretch height of the picture
	bool bResize = false	// Whether to resize the IMAGE to fit the picture
);

Parameters

pDstImg

The IMAGE object pointer that holds the image. If NULL, the picture is read to the graphics window.

pImgFile

Picture file name. Support for images in the bmp / gif / jpg / png / tif / emf / wmf / ico format. Pictures in gif format load only the first frame;

nWidth

The stretch width of the picture. When the picture is loaded, it is stretched to that width. If 0, the width of the original drawing is used.

nHeight

The stretch height of the picture. When the picture is loaded, it is stretched to that height. If 0, the height of the original image is used.

bResize

Whether to resize the IMAGE to fit the picture.

pResType

The type of picture resource.

pResName

The name of the picture resource.

Return Value

None

Remarks

If you did not specify a width and height when you created the IMAGE object, you can set it through the Resize function.

For IMAGE objects that are not set to be wide, performing loadimage sets its height to the same size as the picture you read.

Examples

The following complete example implements the load of the picture "D:\test.jpg" to the graphics window:

#include <graphics.h>
#include <conio.h>

// Main function
int main()
{
	// Drawing window initialization
	initgraph(640, 480);

	// Read pictures to the graphics window
	loadimage(NULL, _T("D:\\test.jpg"));

	// Press any key to exit
	_getch();
	closegraph();
}

The following snippet implements the loading of the image "D:test.jpg" to the graphics window (MBCS and Unicode Adaptation):

loadimage(NULL, _T("D:\\test.jpg"));

The following snippet implements the loading of the image resource "Player" to the img object under the "IMAGE" category and displays it at a specified location on the screen:

IMAGE img;
loadimage(&img, _T("IMAGE"), _T("Player"));
putimage(100, 100, &img);	// Show the background again in another location

The following snippet implements the loading of the image resource iDR-PLAYER to img object under the "IMAGE" category and displays it at a specified location on the screen:

IMAGE img;
loadimage(&img, _T("IMAGE"), MAKEINTRESOURCE(IDB_PLAYER));
putimage(100, 100, &img);	// Show the background again in another place
(贡献者:Krissi  编辑