Graphics.DrawImage(Image*, RectF*, Matrix*, Effect*, ImageAttributes*, Unit*) method

Applies to: desktop apps only

The method draws a portion of an image after applying a specified effect.

Syntax

Status DrawImage(
  [in]  Image *image,
  [in]  RectF *sourceRect,
  [in]  Matrix *xForm,
  [in]  Effect *effect,
  [in]  ImageAttributes *imageAttributes,
  [in]  Unit *srcUnit
);

Parameters

  • image [in]
    Type: Image*

    Pointer to an Image object that specifies the image to be drawn.

  • sourceRect [in]
    Type: RectF*

    Pointer to a RectF object that specifies the portion of the image to be drawn.

  • xForm [in]
    Type: Matrix*

    Pointer to a Matrix object that specifies the parallelogram in which the image portion is rendered. The destination parallelogram is calculated by applying the affine transformation stored in the matrix to the source rectangle.

  • effect [in]
    Type: Effect*

    Pointer to a instance of a descendant of the Effect class. The descendant specifies an effect or adjustment (for example, a change in contrast) that is applied to the image before rendering. The image is not permanently altered by the effect.

  • imageAttributes [in]
    Type: ImageAttributes*

    Pointer to an ImageAttributes object that specifies color adjustments to be applied when the image is rendered. Can be NULL.

  • srcUnit [in]
    Type: Unit*

    Element of the Unit enumeration that specifies the unit of measure for the source rectangle.

Return value

Type:

Type: Status****

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.

Examples

The following example increases the contrast of an image and then draws a portion of the image transformed to fill a parallelogram. The source rectangle specifies that only the upper-left one-inch square of the image should be adjusted and rendered. The matrix stores an affine transformation that maps the source rectangle to a parallelogram. The last two arguments passed to the Matrix constructor specify that the upper-left corner of that parallelogram is 3 inches to the right and 2 inches below the upper-left corner of the window's client area.

VOID Example_DrawImageRM(HDC hdc)
{
   Graphics graphics(hdc);
   graphics.SetPageUnit(UnitInch);
   Image myImage(L"Photo.jpg");

   REAL srcWidth = (REAL)myImage.GetWidth();
   REAL srcHeight = (REAL)myImage.GetHeight();
   RectF srcRect(0.0f, 0.0f, 1.0f, 1.0f);
   Matrix myMatrix(2.0f, 0.2f, 0.3f, 1.0f, 3.0f, 2.0f);

   BrightnessContrastParams briConParams;
   briConParams.brightnessLevel = 0;
   briConParams.contrastLevel = 30;
   BrightnessContrast briCon;
   briCon.SetParameters(&briConParams);

   // Draw the image with increased contrast and transformed to
   // fill a parallelogram.
   graphics.DrawImage(&myImage, &srcRect, &myMatrix, &briCon, NULL, UnitInch);
}

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusgraphics.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

Graphics

Image

Loading and Displaying Bitmaps

Drawing, Positioning, and Cloning Images

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012