导航:  GdiPlus Classes > GdiPlus Classes > CGpGraphics Class > Graphics Object >

DrawImage

上一页返回章节概述下一页

描述

 

绘制图像.

 

C++ Syntax

 

Status DrawImage(

[in]       Image *image,

[in, ref]  const RectF &rect

);

 

Status DrawImage(

[in]       Image *image,

[in, ref]  const Rect &rect

);

 

Status DrawImage(

[in]  Image *image,

[in]  REAL x,

[in]  REAL y,

[in]  REAL width,

[in]  REAL height

);

 

Status DrawImage(

[in]  Image *image,

[in]  INT x,

[in]  INT y,

[in]  INT width,

[in]  INT height

);

 

Status DrawImage(

[in]       Image *image,

[in, ref]  const PointF &point

);

 

Status DrawImage(

[in]       Image *image,

[in, ref]  const Point &point

);

 

Status DrawImage(

[in]  Image *image,

[in]  REAL x,

[in]  REAL y

);

 

Status DrawImage(

[in]  Image *image,

[in]  INT x,

[in]  INT y

);

 

Status DrawImage(

[in]  Image *image,

[in]  const PointF *destPoints,

[in]  INT count

);

 

Status DrawImage(

[in]  Image *image,

[in]  const Point *destPoints,

[in]  INT count

);

 

Status DrawImage(

[in]  Image *image,

[in]  REAL x,

[in]  REAL y,

[in]  REAL srcx,

[in]  REAL srcy,

[in]  REAL srcwidth,

[in]  REAL srcheight,

[in]  Unit srcUnit

);

 

Status DrawImage(

[in]  Image *image,

[in]  REAL x,

[in]  REAL y,

[in]  REAL srcx,

[in]  REAL srcy,

[in]  REAL srcwidth,

[in]  REAL srcheight,

[in]  Unit srcUnit

);

 

Status DrawImage(

[in]  Image *image,

[in]  REAL x,

[in]  REAL y,

[in]  REAL srcx,

[in]  REAL srcy,

[in]  REAL srcwidth,

[in]  REAL srcheight,

[in]  Unit srcUnit

);

 

Status DrawImage(

[in]       Image *image,

[in, ref]  RectF &destRect,

[in, ref]  RectF &sourceRect,

[in]       Unit srcUnit,

[in]       ImageAttributes *imageAttributes

);

 

Status DrawImage(

[in]       Image *image,

[in, ref]  Rect &destRect,

[in, ref]  Rect &sourceRect,

[in]       Unit srcUnit,

[in]       ImageAttributes *imageAttributes

);

 

Status DrawImage(

[in]  Image *image,

[in]  const RectF &destRect

[in]  REAL srcx,

[in]  REAL srcy,

[in]  REAL srcwidth,

[in]  REAL srcheight,

[in]  Unit srcUnit,

[in]  ImageAttributes *imageAttributes,

[in]  DrawImageAbort callback,

[in]  VOID *callbackData

);

 

Status DrawImage(

[in]  Image *image,

[in]  const Rect &destRect

[in]  REAL srcx,

[in]  REAL srcy,

[in]  REAL srcwidth,

[in]  REAL srcheight,

[in]  Unit srcUnit,

[in]  ImageAttributes *imageAttributes,

[in]  DrawImageAbort callback,

[in]  VOID *callbackData

);

 

Status DrawImage(

[in]  Image *image,

[in]  const PointF *destPoints,

[in]  INT count,

[in]  REAL srcx,

[in]  REAL srcy,

[in]  REAL srcwidth,

[in]  REAL srcheight,

[in]  Unit srcUnit,

[in]  ImageAttributes *imageAttributes,

[in]  DrawImageAbort callback,

[in]  VOID *callbackData

);

 

Status DrawImage(

[in]  Image *image,

[in]  const Point *destPoints,

[in]  INT count,

[in]  INT srcx,

[in]  INT srcy,

[in]  INT srcwidth,

[in]  INT srcheight,

[in]  Unit srcUnit,

[in]  ImageAttributes *imageAttributes,

[in]  DrawImageAbort callback,

[in]  VOID *callbackData

);

 

FreeBASIC 语法

 

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 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

 

参数

 

pImage

 

[in]指针指向一个图像对象,指定源图像.

 

x

 

[in]简单精确指定要绘制的图像在目标矩形左上角的x坐标.

 

y

 

[in]单精度数指定要绘制的图像在目标矩形左上角的y坐标.

 

nWidth

 

[in, optional]简单精度数指定要绘制的图像,目标矩形的宽度.

 

nHeight

 

[in, optional]简单精度数指定要绘制的图像,目标矩形的高度.

 

pt

 

[in]参考一PointF对象指定的目的地的位置来绘制图像的左上角的坐标.

 

srcx

 

[in]单精度数,指定要绘制的源图像的部分左上角的x坐标.

 

srcy

 

[in]单精度数,指定要绘制的源图像的部分左上角的y坐标.

 

srcwidth

 

[in]单精度数,指定要绘制的源图像的部分的宽度.

 

srcheight

 

[in]单精度数,指定要绘制的源图像的部分的高度.

 

srcUnit

 

本单位指定的图像度量单位[in]元.默认值是unitpixel.

 

destPoints

 

[in]指向PointF对象指定地区的数组,在一个平行四边形,在绘制图像.

 

nCount

 

[in]整数,指定在destPoints数组元素个数.

 

pImageAttributes

 

[in]指针指向一个ImageAttributes对象指定要绘制的颜色与图像大小属性.默认值是NULL.

 

pCallback

 

[in]回调方法用于取消正在进行的绘画.默认值是NULL.

 

pCallbackData

 

[in]指针由pCallback参数指定的方法使用额外的数据.默认值是NULL.

 

返回值

 

如果该方法成功,则返回Ok,这是对Status枚举元素.

如果这个方法失败,它返回一个枚举的其他元素的Status.

 

引用文件

 

CGpBitmap.inc (include CGdiPlus.inc)

 

示例

 

' ========================================================================================

' 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

  ' // Get the DPI scaling ratio

  DIM rxRatio AS SINGLE = graphics.GetDpiX / 96

  DIM ryRatio AS SINGLE = graphics.GetDpiY / 96

  ' // Set scaling

  graphics.SetPageUnit(UnitPixel)

  graphics.SetPageScale(rxRatio)

 

  ' // Create an Image object.

  DIM pImage AS CGpImage = "climber.jpg"

 

  ' // Draw the original source image.

  graphics.DrawImage(@pImage, 10, 10)

 

  ' // Draw the scaled image.

  graphics.DrawImage(@pImage, 200, 50, 150, 75)

 

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

  ' // Get the DPI scaling ratio

  DIM rxRatio AS SINGLE = graphics.GetDpiX / 96

  DIM ryRatio AS SINGLE = graphics.GetDpiY / 96

  ' // Set scaling

  graphics.SetPageUnit(UnitPixel)

  graphics.SetPageScale(rxRatio)

 

  ' // Create an Image object.

  DIM pImage AS CGpImage = "climber.jpg"

 

  ' // Draw the original source image.

  graphics.DrawImage(@pImage, 10, 10)

 

  ' // Draw the scaled image.

  graphics.DrawImage(@pImage, 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

  ' // Get the DPI scaling ratio

  DIM rxRatio AS SINGLE = graphics.GetDpiX / 96

  DIM ryRatio AS SINGLE = graphics.GetDpiY / 96

  ' // Set scaling

  graphics.SetPageUnit(UnitPixel)

  graphics.SetPageScale(rxRatio)

 

  ' // Create an Image object.

  DIM pImage AS CGpImage = "climber.jpg"

 

  ' // 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(@pImage, @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

  ' // Get the DPI scaling ratio

  DIM rxRatio AS SINGLE = graphics.GetDpiX / 96

  DIM ryRatio AS SINGLE = graphics.GetDpiY / 96

  ' // Set scaling

  graphics.SetPageUnit(UnitPixel)

  graphics.SetPageScale(rxRatio)

 

  ' // Create an Image object.

  DIM pImage AS CGpImage = "pattern.png"

 

  ' // Draw the original source image.

  graphics.DrawImage(@pImage, 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

 

  ' Yet another mess of the FB GdiPlus declares.

'#ifdef __FB_64BIT__

'   DIM redToBlue AS ColorMap_

'   redToBlue.oldColor.value = GDIP_ARGB(255, 255, 0, 0)

'   redToBlue.newColor.value = GDIP_ARGB(255, 0, 0, 255)

'#else

'   DIM redToBlue AS ColorMap

'   redToBlue.from = GDIP_ARGB(255, 255, 0, 0)

'   redToBlue.to = GDIP_ARGB(255, 0, 0, 255)

'#endif

 

  ' // GDIP_COLORMAP is an union that solves the 32/64-bit incompatibility

  DIM redToBlue AS GDIP_COLORMAP = (GDIP_ARGB(255, 255, 0, 0), GDIP_ARGB(255, 0, 0, 255))

 

  ' // 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(@pImage, @destPoints(0), 3, srcX, srcY, srcWidth, srcHeight, _

                    UnitPixel, @remapAttributes, NULL, NULL)

 

 

END SUB

' ========================================================================================