Author Topic: GDI+: GdipDrawImagePointRect  (Read 3438 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2517
  • User-Rate: +209/-0
  • Gender: Male
GDI+: GdipDrawImagePointRect
« on: June 23, 2008, 02:11:53 AM »

The following example draws a portion of an image. The portion of the source image to be drawn is scaled to fit the rectangle.

C++

Code: [Select]
VOID Example_DrawImage15(HDC hdc)

{
   Graphics graphics(hdc);

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

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

   // Set up the location for the image and the portion of the source to draw.
   REAL x = 200.0f;
   REAL y = 30.0f;
   REAL srcx = 70.0f;
   REAL srcy = 20.0f;
   REAL srcwidth = 100.0f;
   REAL srcheight = 200.0f;
   Unit srcunit = UnitPixel;

   // Draw the image.
   graphics.DrawImage(&image, x, y, srcx, srcy, srcwidth, srcheight, srcunit);
}

PowerBASIC

Code: [Select]
SUB GDIP_GdipDrawImagePointRect (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pImage AS DWORD
   LOCAL strFileName AS STRING
   LOCAL x AS SINGLE
   LOCAL y AS SINGLE
   LOCAL srcx AS SINGLE
   LOCAL srcy AS SINGLE
   LOCAL srcwidth AS SINGLE
   LOCAL srcheight AS SINGLE
   LOCAL srcUnit AS LONG

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

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

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

   ' // Set up the location for the image and the portion of the source to draw.
   x = 200.0!
   y = 30.0!
   srcx = 70.0!
   srcy = 20.0!
   srcwidth = 100.01
   srcheight = 200.0!
   srcunit = %UnitPixel

   ' // Draw the image
   hStatus = GdipDrawImagePointRect(pGraphics, pImage, x, y, srcx, srcy, srcwidth, srcheight, srcunit)

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

END SUB


« Last Edit: August 08, 2011, 12:24:55 AM by José Roca »