• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipCloneBitmapAreaI

Started by José Roca, June 22, 2008, 12:39:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a Bitmap object from an image file, clones the upper-left portion of the image, and then draws the cloned image.

C++


VOID Example_Clone3(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a Bitmap object from a JPEG file.
   Bitmap bitmap(L"Climber.jpg");

   // Clone a portion of the bitmap.
   Bitmap* clone = bitmap.Clone(0, 0, 100, 100, PixelFormatDontCare);

   // Draw the clone.
   graphics.DrawImage(clone, 0, 0);
   
   delete clone;
}


PowerBASIC


SUB GDIP_Clone (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pBitmap AS DWORD
   LOCAL pClone AS DWORD
   LOCAL strFileName AS STRING

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   '  // Create a Bitmap object from a JPEG file.
   strFileName = UCODE$("climber.jpg")
   hStatus = GdipCreateBitmapFromFile(STRPTR(strFileName), pBitmap)

   ' // Clone a portion of the bitmap
   hStatus = GdipCloneBitmapAreaI(0, 0, 100, 100, %PixelFormatDontCare, pBitmap, pClone)

   ' // Draw the clone
   hStatus = GdipDrawImageI(pGraphics, pClone, 0, 0)

   ' // Cleanup
   IF pClone THEN GdipDisposeImage(pClone)
   IF pBitmap THEN GdipDisposeImage(pBitmap)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB