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:18:18 AM

Title: GDI+: GdipDrawImageRect
Post by: José Roca on June 23, 2008, 02:18:18 AM


The following example draws the source image, the rectangle that bounds the resized image, and then draws the resized image to fit the rectangle.

C++


VOID Example_DrawImage10(HDC hdc)

{
   Graphics graphics(hdc);

   // Create an Image object.
   Image image(L"climber.jpg");

   // Create a Pen object.
   Pen pen (Color(255, 255, 0, 0), 2);

   // Draw the original source image.
   graphics.DrawImage(&image, 10, 10);

   // Create a RectF object that specifies the destination of the image.
   RectF destRect(200, 50, 150, 75);

   // Draw the rectangle that bounds the image.
   graphics.DrawRectangle(&pen, destRect);

   // Draw the image.
   graphics.DrawImage(&image, destRect);
}


PowerBASIC


SUB GDIP_GdipDrawImageRect (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pImage AS DWORD
   LOCAL strFileName AS STRING
   LOCAL pPen AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create the Image object
   strFileName = UCODE$("climber.jpg")
   hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)

   ' // Create a red Pen
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 1.0!, %UnitWorld, pPen)

   ' // Draw the original source image.
   hStatus = GdipDrawImage(pGraphics, pImage, 10, 10)

   ' // Draw the rectangle that bounds the image.
   hStatus = GdipDrawRectangle(pGraphics, pPen, 200, 50, 150, 75)

   ' // Draw the image
   hStatus = GdipDrawImageRect(pGraphics, pImage, 200 + 1, 50 + 1 , 150 - 1, 75 - 1)

   ' // Cleanup
   IF pPen THEN GdipDeletePen(pPen)
   IF pImage THEN GdipDisposeImage(pImage)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB


(http://www.jose.it-berater.org/captures/GdipDrawImageRect.png)