The following example creates an Image object based on a JPEG file. The code creates a second Image object by cloning the first. Then the code calls the
GdipDrawImage function twice to draw the two images.
C++
VOID Example_Clone(HDC hdc)
{
Graphics graphics(hdc);
// Create an Image object, and then clone it.
Image image1(L"Crayons.jpg");
Image* pImage2 = image1.Clone();
// Draw the original image and the cloned image.
graphics.DrawImage(&image1, 20, 20);
graphics.DrawImage(pImage2, 250, 20);
delete pImage2;
}
PowerBASIC
SUB GDIP_CloneImage (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pImage AS DWORD
LOCAL pClonedImage AS DWORD
LOCAL strFileName AS STRING
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create an Image object, and then clone it.
strFileName = UCODE$("climber.jpg")
hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
hStatus = GdipCloneImage(pImage, pClonedImage)
' // Draw the original image and the cloned image.
hStatus = GdipDrawImage(pGraphics, pImage, 20, 20)
hStatus = GdipDrawImage(pGraphics, pClonedImage, 230, 20)
' // Cleanup
IF pClonedImage THEN GdipDisposeImage(pClonedImage)
IF pImage THEN GdipDisposeImage(pImage)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipCloneImage.png)