CGpGraphics.DrawImagemethod
Draws an image.
Syntax
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL rc AS GpRectF PTR) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL rc AS GpRect PTR) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL x AS SINGLE, BYVAL y AS SINGLE, BYVAL nWidth AS SINGLE, BYVAL nHeight AS SINGLE) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL x AS INT_, BYVAL y AS INT_ BYVAL nWidth AS INT_, BYVAL nHeight AS INT_) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL pt AS GpPointF PTR) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL pt AS GpPoint PTR) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL x AS SINGLE, BYVAL y AS SINGLE) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL x AS INT_, BYVAL y AS INT_) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destPoints AS GpPointF, BYVAL count AS INT_) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destPoints AS GpPoint, BYVAL count AS INT_) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL x AS SINGLE, BYVAL y AS SINGLE, BYVAL srcx AS SINGLE, BYVAL srcy AS SINGLE, BYVAL nWidth AS SINGLE, BYVAL nHeight AS SINGLE, BYVAL srcUnit AS GpUnit) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL x AS INT_, BYVAL y AS INT_, BYVAL srcx AS INT_, BYVAL srcy AS INT_, BYVAL nWidth AS INT_, BYVAL nHeight AS INT_, BYVAL srcUnit AS GpUnit) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL x AS SINGLE, BYVAL y AS SINGLE, BYVAL srcrect AS GpRectF PTR, BYVAL srcUnit AS GpUnit) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL x AS INT_, BYVAL y AS INT_, BYVAL srcrect AS GpRect PTR, BYVAL srcUnit AS GpUnit) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destRect AS GpRectF PTR, BYVAL sourceRect AS GpRectF PTR, BYVAL srcUnit AS GpUnit, BYVAL pImageAttributes AS CGpImageAttributes PTR = NULL) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destRect AS GpRect PTR, BYVAL sourceRect AS GpRect PTR, BYVAL srcUnit AS GpUnit, BYVAL pImageAttributes AS CGpImageAttributes PTR = NULL) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destx AS SINGLE, BYVAL desty AS SINGLE, BYVAL destWidth AS SINGLE, BYVAL destHeight AS SINGLE, BYVAL sourcex AS SINGLE, BYVAL sourcey AS SINGLE, BYVAL sourceWidth AS SINGLE, BYVAL sourceHeight AS SINGLE, BYVAL srcUnit AS GpUnit, BYVAL pImageAttributes AS CGpImageAttributes PTR = NULL) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destx AS INT_, BYVAL desty AS INT_, BYVAL destWidth AS INT_, BYVAL destHeight AS INT_, BYVAL sourcex AS INT_, BYVAL sourcey AS INT_, BYVAL sourceWidth AS INT_, BYVAL sourceHeight AS INT_, BYVAL srcUnit AS GpUnit, BYVAL pImageAttributes AS CGpImageAttributes PTR = NULL) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destRect AS GpRectF PTR, BYVAL srcx AS SINGLE, BYVAL srcy AS SINGLE, BYVAL srcwidth AS SINGLE, BYVAL srcheight AS SINGLE, BYVAL srcUnit AS GpUnit, BYVAL pImageAttributes AS CGpImageAttributes PTR = NULL, BYVAL pcallback AS DrawImageAbort = NULL, BYVAL pcallbackData AS ANY PTR = NULL) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destRect AS GpRect PTR, BYVAL srcx AS INT_, BYVAL srcy AS INT_, BYVAL srcwidth AS INT_, BYVAL srcheight AS INT_, BYVAL srcUnit AS GpUnit, BYVAL pImageAttributes AS CGpImageAttributes PTR = NULL, BYVAL pcallback AS DrawImageAbort = NULL, BYVAL pcallbackData AS ANY PTR = NULL) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destx AS SINGLE, BYVAL desty AS SINGLE, BYVAL destWidth AS SINGLE, BYVAL destHeigh AS SINGLE, BYVAL srcx AS SINGLE, BYVAL srcy AS SINGLE, BYVAL srcwidth AS SINGLE, BYVAL srcheight AS SINGLE, BYVAL srcUnit AS GpUnit, BYVAL pImageAttributes AS CGpImageAttributes PTR = NULL, BYVAL pcallback AS DrawImageAbort = NULL, BYVAL pcallbackData AS ANY PTR = NULL) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destx AS INT_, BYVAL desty AS INT_, BYVAL destWidth AS INT_, BYVAL destHeigh AS INT_, BYVAL srcx AS INT_, BYVAL srcy AS INT_, BYVAL srcwidth AS INT_, BYVAL srcheight AS INT_, BYVAL srcUnit AS GpUnit, BYVAL pImageAttributes AS CGpImageAttributes PTR = NULL, BYVAL pcallback AS DrawImageAbort = NULL, BYVAL pcallbackData AS ANY PTR = NULL) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destPoints AS GpPointF PTR, BYVAL nCount AS INT_, BYVAL srcx AS SINGLE, BYVAL srcy AS SINGLE, BYVAL srcwidth AS SINGLE, BYVAL srcheight AS SINGLE, BYVAL srcUnit AS GpUnit, BYVAL pImageAttributes AS CGpImageAttributes PTR = NULL, BYVAL pcallback AS DrawImageAbort = NULL, BYVAL pcallbackData AS ANY PTR = NULL) AS GpStatus
FUNCTION DrawImage (BYVAL pImage AS CGpImage PTR, BYVAL destPoints AS GpPoint PTR, BYVAL nCount AS INT_, BYVAL srcx AS INT_, BYVAL srcy AS INT_, BYVAL srcwidth AS INT_, BYVAL srcheight AS INT_, BYVAL srcUnit AS GpUnit, BYVAL pImageAttributes AS CGpImageAttributes PTR = NULL, BYVAL pcallback AS DrawImageAbort = NULL, BYVAL pcallbackData AS ANY PTR = NULL) AS GpStatus
Parameters
| Name | Description | |
|---|---|---|
pImage | Pointer to an Image object that specifies the source image. | |
x | The x-coordinate of the upper-left corner of the destination rectangle at which to draw the image. | |
y | The y-coordinate of the upper-left corner of the destination rectangle at which to draw the image. | |
nWidth | Optional. The width of the destination rectangle at which to draw the image. | |
nHeight | Optional. The height of the destination rectangle at which to draw the image. | |
pt | Reference to a GpPointF object that specifies the coordinates of the upper-left corner of the destination position at which to draw the image. | |
srcx | The x-coordinate of the upper-left corner of the portion of the source image to be drawn. | |
srcy | The y-coordinate of the upper-left corner of the portion of the source image to be drawn. | |
srcwidth | The width of the portion of the source image to be drawn. | |
srcheight | The height of the portion of the source image to be drawn. | |
srcrect | The coordinates, width and height of the portion of the source image to be drawn. | |
srcUnit | Element of the Unit enumeration that specifies the unit of measure for the image. The default value is UnitPixel. | |
destPoints | Pointer to an array of GpPointF objects that specify the area, in a parallelogram, in which to draw the image. | |
nCount | Integer that specifies the number of elements in the destPoints array. | |
pImageAttributes | Pointer to an ImageAttributes object that specifies the color and size attributes of the image to be drawn. The default value is NULL. | |
pCallback | Callback method used to cancel the drawing in progress. The default value is NULL. | |
pCallbackData | Pointer to additional data used by the method specified by the pCallback parameter. The default value is NULL. |
Return value
If the function succeeds, it returns StatusOk, which is an element of the GpStatus enumeration.
If the function fails, it returns one of the other elements of the GpStatus enumeration.
Description
Draws an image.
Examples
' ======================================================================================== ' The following example draws an image ' ======================================================================================== SUB Example_DrawImage (BYVAL hdc AS HDC)
' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform graphics.ScaleTransformForDpi
' // Create an Image object. DIM image AS CGpBitmap = "climber.jpg" image.SetResolutionForDpi
' // Draw the image. graphics.DrawImage(@image, 10, 10)
END SUB ' ========================================================================================
' ======================================================================================== ' The following example draws a portion of an image. The portion of the source image to be ' drawn is scaled to fit a specified parallelogram. ' ======================================================================================== SUB Example_DrawImage (BYVAL hdc AS HDC)
' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform graphics.ScaleTransformForDpi
' // Create an Image object. DIM image AS CGpBitmap = "climber.jpg" image.SetResolutionForDpi
' // Draw the original source image. graphics.DrawImage(@image, 10, 10)
' // Draw the scaled image. graphics.DrawImage(@image, 200.0, 30.0, 70.0, 20.0, 100.0, 200.0, UnitPixel)
END SUB ' ========================================================================================
' ======================================================================================== ' The following example draws an image. ' ======================================================================================== SUB Example_DrawImage (BYVAL hdc AS HDC)
' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform graphics.ScaleTransformForDpi
' // Create an Image object. DIM image AS CGpBitmap = "climber.jpg" image.SetResolutionForDpi
' // Create an array of PointF objects that specify the destination of the image. DIM destPoints(0 TO 2) AS GpPointF destPoints(0).x = 30 : destPoints(0).y = 30 destPoints(1).x = 250 : destPoints(1).y = 50 destPoints(2).x = 175 : destPoints(2).y = 120
' // Draw the image. graphics.DrawImage(@image, @destPoints(0), 3)
END SUB ' ========================================================================================
' ======================================================================================== ' The following example draws the original source image and then draws a portion of the ' image in a specified parallelogram. ' ======================================================================================== SUB Example_DrawImageRectRect (BYVAL hdc AS HDC)
' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform graphics.ScaleTransformForDpi
' // Create an Image object. DIM image AS CGpBitmap = "pattern.png" image.SetResolutionForDpi
' // Draw the original source image. graphics.DrawImage(@image, 10, 10)
' // Define the portion of the image to draw. DIM srcX AS SINGLE = 70.0 DIM srcY AS SINGLE = 20.0 DIM srcWidth AS SINGLE = 100.0 DIM srcHeight AS SINGLE = 100.0
' // Create an array of Point objects that specify the destination of the cropped image. DIM destPoints(0 TO 2) AS GpPointF destPoints(0).x = 230 : destPoints(0).y = 30 destPoints(1).x = 350 : destPoints(1).y = 50 destPoints(2).x = 275 : destPoints(2).y = 120
' // GDIP_COLORMAP is an union that solves the 32/64-bit incompatibility DIM redToBlue AS GpColorMap = (ARGB_RED, ARGB_BLUE)
' // Create an ImageAttributes object that specifies a recoloring from red to blue. DIM remapAttributes AS CGpImageAttributes RemapAttributes.SetRemapTable(1, @redToBlue)
' // Draw the cropped image graphics.DrawImage(@image, @destPoints(0), 3, srcX, srcY, srcWidth, srcHeight, _
UnitPixel, @remapAttributes, NULL, NULL)
END SUB ' ========================================================================================
' ======================================================================================== ' The following example draws part of an image. ' ======================================================================================== SUB Example_DrawImage (BYVAL hdc AS HDC)
' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform graphics.ScaleTransformForDpi
' // Create an Image object. DIM image AS CGpBitmap = "climber.jpg" image.SetResolutionForDpi
' // Draw the original source image. graphics.DrawImage(@image, 10, 10)
' // Part of the source image to draw DIM rcsrc AS GpRectF = (80, 30, 80, 80) ' // Destination recangle DIM rcdest AS GpRectF = (200, 10, 80, 80)
' // Draw the scaled image. graphics.DrawImage(@image, @rcdest, @rcsrc, UnitPixel)
END SUB ' ========================================================================================
' ======================================================================================== ' The following example draws part of an image loaded from a resource file. ' ======================================================================================== SUB Example_DrawImage (BYVAL hdc AS HDC)
' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform graphics.ScaleTransformForDpi
' // Create an Image object from a resource by name ' DIM image AS CGpBitmap = CGpBitmap(GetModuleHandle(NULL), "#998") ' // load from resource by ordinal DIM image AS CGpBitmap = CGpBitmap(GetModuleHandle(NULL), "IDI_CLIMBER") ' // load from resource by name image.SetResolutionForDpi
' // Draw the original source image. graphics.DrawImage(@image, 10, 10)
' // Part of the source image to draw DIM rcsrc AS GpRectF = (80, 30, 80, 80) ' // Destination rectangle DIM rcdest AS GpRectF = (200, 10, 80, 80)
' // Draw the scaled image. graphics.DrawImage(@image, @rcdest, @rcsrc, UnitPixel)
END SUB ' ========================================================================================
Reference
- Include file
CGpGraphics.inc - Defined in AfxNova/CGpGraphics.inc:1034
- Documented in Graphics/GdiPlus Classes/CGpGraphics Classes.md
- Topic: CGpGraphics Class