PowerBasic Museum 2020-A

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Source Code => Graphics and Multimedia => GDI+ (GDI Plus) => Topic started by: José Roca on June 23, 2008, 02:34:05 AM

Title: GDI+: GdipCloneImage
Post by: José Roca on June 23, 2008, 02:34:05 AM


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)