• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipCloneImage

Started by José Roca, June 23, 2008, 02:34:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



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