Professional Documents
Culture Documents
6.1
GDI+ GDI GDI+
GDI+
GDI+
.NET
Win32/64 (C++)
GDI+
GDI
GDI+
GDI+ Windows
VC++ GDI+
1GDI+
GDI+
GDI+
Rectangle Pen Graphics
GDI+ Metafile
MetafileHeader MetaHeader
3
GDI +GDI+
LCD
4
GDI+ C++ 54 12 6 226 55 19 GDI+
60 50 8 Graphics GDI+
2GDI+
1
gradient brush
GDI+ GDI
6-1
6-1
6-2
6-2
2
GDI+ GDI cardinal spines
6-3
6-3
3
GDI GDI + Graphics
Graphics persistent path object GraphicsPath
GraphicsPath GraphicsPath
4
GDI+ Matrix transformation
GraphicsPath Transform
Matrix 33 6-4
6-4
5
GDI+ Scalable Regions GDI GDI
GDI+
6-5
6-5
6
6-5 GDI+
Alpha Blending
6-6
6-6
7
GDI+ Image Bitmap Metafile GDI+
BMP GIFJPEGEXIFPNGTIFFICONWMFEMF 9
8GDI+
GDI GDI+
GDI+ GDI
GDI+ GDI+ GDI GDI+ GDI GDI+
VC GDI+ DC
DC GDI+
3
GDI+ GDI GDI+ GDI
DC
1DC
DC = Device Context GDI
DC GDI API
DC HDC = Handle to a DC
GDI DC GDI
GDI+ HDC Graphics
Graphics DC
SmoothingMode TextRenderingHintGraphics
SelectObject DC
DC GDI+ Pen
Graphics DrawLine DrawLine
Pen Pen Graphics
2
(20, 10)(200, 100) 3 GDI
GDI+ API MFC
1 GDI
API
GDI WM_PAINT
BeginPaint CreatePen SelectObject
MoveToEx(20, 10) LineTo
(200, 100) MoveToEx LineTo
hdc
WM_PAINT:
HDC hdc; // DC
PAINTSTRUCT ps; //
HPEN hPen; //
HPEN hPenOld; //
hdc = BeginPaint (hWnd , &ps); // DC hWnd
hPen = CreatePen(PS_SOLID, 3, RGB(255, 0, 0) ); // 3
hPenOld = SelectObject(hdc, hPen); // DC
MoveToEx(hdc, 20, 10, NULL); //
LineTo(hdc, 200, 100) ; //
SelectObject(hdc, hPenOld); // DC
DeleteObject(hPen); //
EndPaint(hWnd, &ps) ; //
break;
MFC
MFC GDI API MFC GDI
CPen CPoint CDC CDC
HDC
void CGdipDemoView::OnDraw(CDC* pDC) {
CGdipDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc) return;
// TODO:
CPen pen(PS_SOLID, 3, RGB(255, 0, 0)); // 3
pDC->SelectObject(&pen); // DC
//pDC->SelectObject(new CPen(PS_SOLID, 3, RGB(255, 0, 0))); //
pDC->MoveTo(20, 10); //
pDC->LineTo(200, 100); //
2 GDI+
API
GDI+ Graphics Pen Graphics
DrawLine DrawLine Pen GDI
WM_PAINT:
HDC hdc;
PAINTSTRUCT ps; // paint_struct
Pen *myPen;
Graphics *myGraphics;
hdc = BeginPaint(hWnd, &ps);
myPen = new Pen(0xffff0000, 3); // 3
myGraphics = new Graphics(hdc); // DC
myGraphics->DrawLine(myPen, 20, 10, 200, 100); //
EndPaint(hWnd, &ps);
break; // delete .
MFC
MFC GDI+ API OnDraw DC
3
Pen Graphics
Brush GraphicsPathImage Font Graphics Graphics
4
GDI+ MFC
GDI GDI+ .NETC#Java VB
C++.NET
Status DrawLine(const Pen* pen, REAL x1, REAL y1, REAL x2, REAL y2);
Status DrawLine(const Pen* pen, const PointF& pt1, const PointF& pt2);
Status DrawLine(const Pen* pen, INT x1, INT y1, INT x2, INT y2);
Status DrawLine(const Pen* pen, const Point& pt1, const Point& pt2);
typedef int INT; class Point {public: INT X; INT Y; };
typedef float REAL; class PointF {public: REAL X; REAL Y; };
5
DrawLine GDI GDI
6
GDI+ GDI GDI Rectangle
7
GDI MFC CRng CreateRectRgnCreateEllpticRgnCreateRoundRectRgn
CreatePolygonRgn CreatePolyPolygonRgn
GDI+ Region
GDI+ Region Rectangle GraphicsPath
GraphicsPath
Region
GDI+Region Union Intersect
GDI+ GraphicsPath
Region GDI PathToRegion
GraphicsPath Union Intersect
Region region1(rect1);
Region region2(rect2);
region1.Union(onePath);
region2.Intersect(onePath);
4GDI+
GDI+
1GDI+
Visual C++ 2005 GDI+
gdiplus.dll
gdiplus.lib
gdiplus*.h
gdicpp.chm gdicpp.chi
Windows XP Windows Server 2003 GDI+
gdiplus.dll WinSxSWindows side-by-side assembly
C:\WINDOWS\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.0.0_xww_8d353f13\gdiplus.dll1661KB2002.10.8
C:\WINDOWS\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.2600.2180_xww_522f9f82\gdiplus.dll1672KB2004.8.4
GDI gdi32.dll 32
F:\WINDOWS\system32\gdi32.dll272KB2004.8.4
Visual C++ 6.0 Windows 2000 GDI+
.NET GDI+
.NET
2VC
VS05 /* /
/ GdiPlus.lib
3
VC05 GDI+
1
GDI+ OnDraw
CWnd RedrawWindow
BOOL RedrawWindow(LPCRECT lpRectUpdate = NULL, CRgn* prgnUpdate = NULL,
UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
lpRectUpdate NULL prgnUpdate
NULL flags RDW_INVALIDATE
RDW_UPDATENOW RDW_ERASE
Graphics graph(pDC->m_hDC);
RedrawWindow(); //
// Invalidate(); UpdateWindow(); // this->Invalidate();
OnDraw OnPaint RedrawWindow
GDI+ CWinApp:: InitInstance ();
4
2new
new GDI+
C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include GdiplusBase.h
GdiplusBase newnew[]delete delete[]
GdiplusBase.h
GdiplusBase
#include <gdiplus.h>"GdiplusBase.h"
#include "gdiplusBase.h"
#include <gdiplus.h>
gdiplusBase.h SDK Include
//
new &
Pen *pPen = new Pen(Color::Red); // C#
Pen pen(Color::Green);
graphics.DrawPolygon(&pen, points, n);
3
VC05 Bug GDI+
Debug Release
F5Ctrl +F5
MFC DLL
MessageBox
MessageBox(L"");
4 MFC GDI+
GDIPlusDemo MFC
GDI+ CGDIPlusDemoApp
ULONG_PTR m_gdiplusToken; // ULONG PTR int64
CGDIPlusDemoApp::InitInstance() GDI+
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
InitInstance
CWinApp:: InitInstance (); //
CGDIPlusDemoApp::ExitInstance() GDI +
GdiplusShutdown(m_gdiplusToken);
InitInstance ExitInstance ExitInstance
GDI+
OnDraw
CGDIPlusDemoView::OnDraw (CDC* pDC) {
Graphics graph(pDC->m_hDC); //
Pen bluePen(Color(255, 0, 0, 255)); //
Pen redPen(Color(255, 255, 0, 0)); //
int y = 255; // y
for (int x = 0; x < 256; x += 5) { //
graph.DrawLine(&bluePen, 0, y, x, 0);
graph.DrawLine(&redPen, 255, x, y, 255);
y -= 5;
}
for (y = 0; y < 256; y++) { //
Pen pen(Color(y, 0, 255, 0)); // A green pen with shifting alpha
graph.DrawLine(&pen, 0, y, 255, y);
}
for (int x = 0; x < 256; x++) { //
Pen pen(Color (x, 255, 0, 255)); // A magenta pen with shifting alpha
graph.DrawLine(&pen, x, 100, x, 200);
}
}
6-7
6-7
5GDI+
GDI+ VS05 /Win32 COM /Graphics and Multimedia/ GDI+
GDI+ Reference
GDI+ VS05 //Visual Studio / Windows
/ Windows /Windows Windows Forms/ Windows
/Windows Windows GDI+
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.WIN32COM.v10.en/gdicpp/GDIPlus/GDIPlus.htm
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_fxmclignrl/html/362532c51a06-4257-bdc8-723461009ede.htm
5GDI+
GDI+ API 54 12 6 226 55 19
1
GDI+ API 54 Graphics
AdjustableArrowCap
Bitmap
BitmapData
Blur
BrightnessContrast
Brush
CachedBitmap
CharacterRange
Color
ColorBalance
ColorCurve
ColorLUT
ColorMatrixEffect
CustomLineCap
Effect
EncoderParameter
EncoderParameters
Font
FontCollection
FontFamily
GDI+
GdiplusBase
Graphics
GraphicsPath
GraphicsPathIterator
HatchBrush
HueSaturationLightn
ess
Image
ImageAttributes
ImageCodecInfo
ImageItemData
InstalledFontCollecti
on
Levels
LinearGradientBrush
Matrix
Metafile
MetafileHeader
PathData
PathGradientBrush
Pen
Point
32
GDI+
GDI+
GraphicsPath
/
H S L
33
API
GraphicsPath GraphicsPathIterator
2D
PointF
PrivateFontCollection
PropertyItem
Rect
RectF
RedEyeCorrection
Region
Sharpen
Size
SizeF
SolidBrush
StringFormat
TextureBrush
Tint
2D
Image Bitmap
piece
2D
2D
layout
GDI+ API
GdiplusBase
Graphics
Point
PointF
Color
Size
SizeF
Rect
RectF
GraphicsPath
GraphicsPathIterator
ImageItemData
Pen
BitmapData
CustomLineCap
MetafileHeader
AdjustableArrowCap
PropertyItem
Brush
EncoderParameter
SolidBrush
EncoderParameters
HatchBrush
ImageCodecInfo
TextureBrush
LinearGradientBrush
CharacterRange
PathGradientBrush
PathData
Image
Bitmap
Effect
Metafile
Blur
CachedBitmap
BrightnessContrast
ImageAttribute
s
ColorBalance
Font
ColorCurve
FontFamily
ColorLUT
FontCollection
ColorMatrixEffect
InstalledFontCollection
HueSaturationLightness
PrivateFontCollection
Levels
StringFormat
RedEyeCorrection
Region
Sharpen
Matrix
Tint
GDI+
GDI+
GDI+
GDI+12
GdiplusShutdown
GDI+
GdiplusStartup
GDI+
GetImageDecoders
GetImageDecodersSi
ze
GetImageEncoders
GetImageEncodersSi
ze
GetPixelFormatSize
IsAlphaPixelFormat
IsCanonicalPixelForm
at
IsExtendedPixelForm
at
IsIndexedPixelForma
t
ObjectTypeIsValid
ImageCodecInfo
ImageCodecInfo
16
ObjectType
3
GDI+ 6 226 GdiplusImaging.h
ImageFormatBMP
BMPBitMaP
ImageFormatEMF
EMFEnhanced MetaFile
Exif Exchangeable Image File
ImageFormatEXIF
Icon
ImageFormatIcon
ImageF ImageFormatMemoryBM
ormat* P
(11 )
PNGPortable Network Graphics
ImageFormatPNG
ImageFormatUndefined
TIFF
FrameDimensionPage
FrameDimensionTime
GIF
EncoderChrominanceTabl
e
EncoderColorDepth
EncoderColorSpace
EncoderCompression
EncoderLuminanceTable
EncoderQuality
EncoderRenderMethod
(13 ) EncoderSaveFlag
EncoderScanMethod
EncoderTransformation
EncoderVersion
EncoderImageItems
PixelFormat8bppIndexed
PixelFormat16bppARGB1
555
PixelFormat16bppGraySc
ale
PixelFormat16bppRGB55
5
PixelFormat16bppRGB56
5
PixelFormat24bppRGB
(14 ) PixelFormat32bppARGB
PixelFormat32bppPARGB
PixelFormat32bppRGB
PixelFormat48bppRGB
PixelFormat64bppARGB
PixelFormat64bppPARGB
(9 )
(217
)
PixelFormat4bppIndexed
PropertyTagTypeASCII
PropertyTagTypeByte
PropertyTagTypeLong
PropertyTagTypeRational
PropertyTagTypeShort
PropertyTagTypeSLONG
PropertyTagTypeSRationa
l
PropertyTagTypeUndefine
d
PropertyTagGpsVer ~
PropertyTagGpsDestDist
PropertyTagNewSubfileTy
pe ~
PropertyTagPageNumber
PropertyTagTransferFunct
ion
PropertyTagSoftwareUsed
PropertyTagDateTime
PropertyTagArtist ~
PropertyTagTileByteCoun
ts
PropertyTagInkSet ~
PropertyTagNumberOfInk
s
PropertyTagDotRange ~
PropertyTagTransferRang
e
PropertyTagJPEGProc ~
PropertyTagImageTitle
PropertyTagResolutionXU
nit ~
PropertyTagThumbnailDa
ta
PropertyTagThumbnailIm
8
16 1 RGB 5
16
16 RGB 5 1
16 RB 5 G 6
24 RGB 8
32 RGB 8
32 RGB 8 RGB
24 RGB 8 8
48 RGB 16
64 RGB 16
64 RGB 16 RGB
4
null ASCII
32
32
16
32
32
0x0000~ 0x001A27
0x00FE~
0x012944
0x012D
null 0x0131
0x0132
null
0x013B
~ 0x014511
0x014C
~ 0x014D3
0% 100%
0x0150~
0x01567
JPEG 0x0200~
null 0x032017
0x5001~27
RGB JPEG
0x501B
0x5020~28
age
Width ~
PropertyTagThumbnailCo
py
Right
PropertyTagLuminanceTa
ble
PropertyTagFrameDelay
~
PropertyTagPaletteHistog
ram
PropertyTagCopyright ~
PropertyTagExifCfaPatter
n
null
0x503B
0x5090
GIF 10
0x5100
~ 0x51139
null 0x8298B~
0xA30248
4
GDI+ 55 LineJoin BevelMiter Round
CombineMode
CompositingMode
CompositingQuality
GDI+55
ImageType
InterpolationMod
e
ItemDataPosition
LinearGradientMo
de
LineCap
LineJoin
MatrixOrder
CoordinateSpace
CurveAdjustments
CurveChannel
DashCap
DashStyle
DitherType
DriverStringOptions
EmfType
EncoderParameterValueTy
pe
EncoderValue
FillMode
FlushIntention
EMF+
EMF WMF
EMF
FontStyle
HatchStyle
HistogramFormat
HotkeyPrefix
ImageCodecFlags
ImageFlags
ImageLockMode
BrushType
ColorAdjustType
ColorChannelFlags
ColorMatrixFlags
EmfPlusRecordType
EmfToWmfBitsFlags
MetafileFrameUni
t
MetafileType
ObjectType
PaletteFlags
PaletteType
PathPointType
PenAlignment
(
)
PenType
PixelOffsetMode
RotateFlipType
SmoothingMode
Status
StringAlignment
StringDigitSubstit
ute
StringFormatFlag
s
StringTrimming
TextRenderingHin
t
Unit
WarpMode
WrapMode
5
GDI+ API 19 GDI+ GDI+ API
GDI+ API 19
BlurParams
BrightnessContrastParams
ColorBalanceParams
ColorCurveParams
ColorLUTParams
ColorMap
ColorMatrix
ColorPalette
ENHMETAHEADER3
GdiplusAbort
GDI+
GdiplusStartupInput
GDI+
GdiplusStartupOutput
GDI+
HueSaturationLightnessPar
ams
LevelsParams
PWMFRect16
WMF INT16
RedEyeCorrectionParams
SharpenParams
TintParams
WmfPlaceableFileHeader
WMF
6GDI+ API
GDI+exposesflatAPI 600 Gdiplus.dll
Gdiplusflat.h GDI+ API 54 C++
Microsoft Product Support Services
API
C++Microsoft .NET Framework GDI+
60 50 8 // C#
System.Drawing
System.Drawing.Drawing2D
System.Drawing.Imaging
System.Drawing.Text
System.Drawing.Printing
C++
C# VB J#
afxwin.h
Gdiplus.h
GDI
C++
(MFC)
Gdiplus
GDI+
GDI+ API
C++
System.Drawing[.dll]
DllExports
GDI API
Gdiplus.dll
Gdi32.dll
GDI+
C++
API
C++ Matrix nativeMatrix field GpMatrix
Matrix API
nativeMatrix API
}
API GdipShearMatrix
GpStatus WINGDIPAPI GdipShearMatrix(GpMatrix *matrix, REAL shearX, REAL shearY,
GpMatrixOrder order)
Matrix GpMatrix API
GpStatus WINGDIPAPI GdipCreateMatrix(GpMatrix **matrix);
GpMatrix GpMatrix
nativeMatrix
Matrix() {
GpMatrix *matrix = NULL;
lastResult = DllExports::GdipCreateMatrix(&matrix);
SetNativeMatrix(matrix);
}
VOID SetNativeMatrix(GpMatrix *nativeMatrix) {
this->nativeMatrix = nativeMatrix;
}
Clone GDI+ API
Matrix::Clone nativeMatrix GpMatrix API
GdipCloneMatrix
GpStatus WINGDIPAPI GdipCloneMatrix(GpMatrix *matrix, GpMatrix **cloneMatrix);
// * Clone() const { }
Matrix *Clone() const {
GpMatrix *cloneMatrix = NULL;
GdipCloneMatrix(nativeMatrix, &cloneMatrix));
Matrix IsInvertible
BOOL IsInvertible() const {
BOOL result = FALSE;
GdipIsMatrixInvertible(nativeMatrix, &result);
return result;
}
API GdipIsMatrixInvertible
GpStatus WINGDIPAPI GdipIsMatrixInvertible(GDIPCONST GpMatrix *matrix, BOOL *result);
Color DWORD ARGB Color
ARGB GDI+ API Pen::SetColor
Status SetColor(const Color& color) {
GdipSetPenColor(nativePen, color.GetValue());
}
Color::GetValue ARGB API GdipSetPenColor
GpStatus WINGDIPAPI GdipSetPenColor(GpPen *pen, ARGB argb);
#include <gdiplus.h>
#pragma comment(lib, Gdiplus.lib); //
using namespace Gdiplus;
1GdiPlus.h
/*********************************************************************\
* Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
* Module Name:
* Gdiplus.h
* Abstract:
* GDI+ public header file
\*********************************************************************/
#ifndef _GDIPLUS_H
#define _GDIPLUS_H
struct IDirectDrawSurface7;
typedef signed short INT16;
typedef unsigned short UINT16;
#include <pshpack8.h> // set structure packing to 8
namespace Gdiplus
{
namespace DllExports {
#include "GdiplusMem.h"
};
#include "GdiplusBase.h"
#include "GdiplusEnums.h"
#include "GdiplusTypes.h"
#include "GdiplusInit.h"
#include "GdiplusPixelFormats.h"
#include "GdiplusColor.h"
#include "GdiplusMetaHeader.h"
#include "GdiplusImaging.h"
#include "GdiplusColorMatrix.h"
#include "GdiplusGpStubs.h"
#include "GdiplusHeaders.h"
namespace DllExports {
#include "GdiplusFlat.h"
};
#include "GdiplusImageAttributes.h"
#include "GdiplusMatrix.h"
#include "GdiplusBrush.h"
#include "GdiplusPen.h"
#include "GdiplusStringFormat.h"
#include "GdiplusPath.h"
#include "GdiplusLineCaps.h"
#include "GdiplusMetafile.h"
#include "GdiplusGraphics.h"
#include "GdiplusCachedBitmap.h"
#include "GdiplusRegion.h"
#include "GdiplusFontCollection.h"
#include "GdiplusFontFamily.h"
#include "GdiplusFont.h"
#include "GdiplusBitmap.h"
#include "GdiplusImageCodec.h"
}; // namespace Gdiplus
#include <poppack.h> // pop structure packing back to previous state
#endif // !_GDIPLUS_HPP
2GDI+
MFC C++ GDI+ API MFC GDI+
GDI+ GdiplusStartup GDI+ GdiplusShutdown GDI+
Gdiplus.dll+1 Gdiplus.dll-1
InitInstance ExitInstance
GdiplusStartup GdiplusShutdown GdiplusInit.h
Status WINAPI GdiplusStartup(
OUT ULONG_PTR *token,
const GdiplusStartupInput *input,
OUT GdiplusStartupOutput *output);
void GdiplusShutdown(ULONG_PTR token);
ULONG_PTR basetsd.h
typedef _W64 unsigned long ULONG_PTR;
token GDI+
GDI+ input
// GdipDraw.h
};
// GdipDraw.cpp
#include <gdiplus.h>
// #pragma comment(lib, Gdiplus.lib); //
using namespace Gdiplus;
BOOL CGdipDrawApp::InitInstance()
{
// Windows XP
// ComCtl32.dll 6
// InitCommonControlsEx()
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
//
//
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
/* CWinApp:: InitInstance ();
*/ // _
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
CWinApp::InitInstance();
int CGdipDrawApp::ExitInstance() //
{
// TODO: /
GdiplusShutdown(m_gdiplusToken);
return CWinApp::ExitInstance();
}
3
GDI+ API
GdiplusTypes.h
1Point[F]
GDI+ Point PointF
Point
class Point {
public:
Point() {X = Y = 0;}
Point(const Point &point) {X = point.X; Y = point.Y;}
Point(const Size &size) {X = size.Width; Y = size.Height;}
Point(INT x, INT y) {X = x; Y = y;}
Point operator+(const Point& point) const {return Point(X + point.X, Y + point.Y);}
Point operator-(const Point& point) const {return Point(X - point.X, Y - point.Y);}
BOOL Equals(const Point& point) {return (X == point.X) && (Y == point.Y);}
public:
INT X; // XY
INT Y;
};
2Size[F]
GDI+ Size SizeF
Size
class Size {
public:
Size() {Width = Height = 0;}
Size(const Size& size) {Width = size.Width; Height = size.Height;}
Size(INT width, INT height) {Width = width; Height = height;}
Size operator+(const Size& sz) const {
return Size(Width + sz.Width, Height + sz.Height);
}
Size operator-(const Size& sz) const {
return Size(Width - sz.Width, Height - sz.Height);
}
BOOL Equals(const Size& sz) const {
return (Width == sz.Width) && (Height == sz.Height);
}
3Rect[F]
GDI+ Rect RectF
Rect
class Rect {
public:
Rect() {X = Y = Width = Height = 0;}
Rect(INT x, INT y, INT width, INT height);
Rect(const Point& location, const Size& size);
Rect* Clone() const;
// _
VOID GetLocation(OUT Point* point) const;
VOID GetSize(OUT Size* size) const;
VOID GetBounds(OUT Rect* rect) const;
INT GetLeft() const {return X;}
INT GetTop() const {return Y;}
INT GetRight() const {return X+Width;}
INT GetBottom() const {return Y+Height;}
BOOL IsEmptyArea() const{return (Width <= 0) || (Height <= 0);}
BOOL Equals(const Rect & rect) const;
BOOL Contains(INT x, INT y) const;
BOOL Contains(const Point& pt) const;
BOOL Contains(Rect& rect) const;
VOID Inflate(INT dx, INT dy) { // inflate
X -= dx;
Y -= dy;
Width += 2*dx;
Height += 2*dy;
}
VOID Inflate(const Point& point) {Inflate(point.X, point.Y);}
BOOL Intersect(const Rect& rect) {return Intersect(*this, *this, rect);}
static BOOL Intersect(OUT Rect& c, const Rect& a, const Rect& b);
BOOL IntersectsWith(const Rect& rect) const;
atltypes.h
class CPoint : public tagPOINT { //
public:
CPoint() throw();
CPoint(int initX, int initY) throw();
}
class CSize : public tagSIZE {
public:
CSize() throw();
CSize(int initCX, int initCY) throw();
}
class CRect : public tagRECT {
public:
CRect() throw();
CRect(int l, int t, int r, int b) throw();
}
GDI
GDI API
GDI GDI+ GDI+ GDI
2
GDI GDI+
1Color
GDI+ GDI 8 alpha
0 ~255
1
GDI+
R G B
B
G
R
Intel CPU //
GDI+ 4 DWORD
typedef DWORD ARGB; // gdipluspixelformats.h
typedef unsigned long DWORD; // windef.h double word
GDI COLORREF
typedef DWORD COLORREF; // 0x00bbggrr (windef.h)
Color
Color(BYTE a, BYTE r, BYTE g, BYTE b); // a alpha
ARGB GetValue(VOID);
Color
COLORREF ToCOLORREF() const;
Color GDI
Color
BYTE GetAlpha() const; BYTE GetA() const;
BYTE GetRed() const;
BYTE GetR() const;
BYTE GetGreen() const; BYTE GetG() const;
BYTE GetBlue() const;
BYTE GetB() const;
2
/*********************************************************************\
** Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
** Module Name:
** GdiplusColor.h
** Abstract:
** GDI+ Color Object
\*********************************************************************/
#ifndef _GDIPLUSCOLOR_H
#define _GDIPLUSCOLOR_H
//---------------------------------------------------------------------------// Color mode
//---------------------------------------------------------------------------enum ColorMode {
ColorModeARGB32 = 0,
ColorModeARGB64 = 1
};
//---------------------------------------------------------------------------// Color Channel flags
//---------------------------------------------------------------------------enum ColorChannelFlags {
ColorChannelFlagsC = 0,
ColorChannelFlagsM,
ColorChannelFlagsY,
ColorChannelFlagsK,
ColorChannelFlagsLast
};
//---------------------------------------------------------------------------// Color
//---------------------------------------------------------------------------class Color {
public:
Color() { Argb = (ARGB)Color::Black; }
// Construct an opaque Color object with the specified Red, Green, Blue values.
// Color values are not premultiplied.
Color(BYTE r, BYTE g, BYTE b) { Argb = MakeARGB(255, r, g, b); }
Color(BYTE a, BYTE r, BYTE g, BYTE b) {Argb = MakeARGB(a, r, g, b);}
Color(ARGB argb) { Argb = argb; }
//
BYTE GetAlpha() const { return (BYTE) (Argb >> AlphaShift); }
BYTE GetA() const { return GetAlpha(); }
BYTE GetRed() const { return (BYTE) (Argb >> RedShift); }
3
public:
// Common color constants 141
enum {
AliceBlue
= 0xFFF0F8FF, //
AntiqueWhite
= 0xFFFAEBD7, //
Aqua
= 0xFF00FFFF, //
Aquamarine
= 0xFF7FFFD4, //
Azure
= 0xFFF0FFFF, //
Beige
= 0xFFF5F5DC, //
Bisque
= 0xFFFFE4C4, //
Black
= 0xFF000000, //
BlanchedAlmond = 0xFFFFEBCD, //
Blue
= 0xFF0000FF, //
BlueViolet
= 0xFF8A2BE2, //
Brown
= 0xFFA52A2A, //
BurlyWood
= 0xFFDEB887, //
CadetBlue
= 0xFF5F9EA0, //
Chartreuse
= 0xFF7FFF00, //
Chocolate
= 0xFFD2691E, //
Coral
= 0xFFFF7F50, //
CornflowerBlue
= 0xFF6495ED, //
Cornsilk
= 0xFFFFF8DC, //
Crimson
= 0xFFDC143C,//
Cyan
= 0xFF00FFFF, //
DarkBlue
= 0xFF00008B, //
DarkCyan
= 0xFF008B8B, //
DarkGoldenrod
= 0xFFB8860B, //
DarkGray
= 0xFFA9A9A9, //
DarkGreen
= 0xFF006400, //
DarkKhaki
= 0xFFBDB76B,//
DarkMagenta
= 0xFF8B008B, //
DarkOliveGreen
= 0xFF556B2F, //
DarkOrange
= 0xFFFF8C00, //
DarkOrchid
= 0xFF9932CC, //
DarkRed
= 0xFF8B0000, //
DarkSalmon
= 0xFFE9967A, //
DarkSeaGreen
= 0xFF8FBC8B, //
DarkSlateBlue
= 0xFF483D8B, //
DarkSlateGray
= 0xFF2F4F4F, //
DarkTurquoise = 0xFF00CED1, //
DarkViolet
= 0xFF9400D3, //
DeepPink
= 0xFFFF1493, //
DeepSkyBlue
= 0xFF00BFFF, //
DimGray
= 0xFF696969, //
DodgerBlue
= 0xFF1E90FF, //
Firebrick
= 0xFFB22222, //
FloralWhite
= 0xFFFFFAF0, //
ForestGreen
= 0xFF228B22, //
Fuchsia
= 0xFFFF00FF, //
Gainsboro
= 0xFFDCDCDC,
//
GhostWhite
= 0xFFF8F8FF, //
Gold
= 0xFFFFD700, //
Goldenrod
= 0xFFDAA520,//
Gray
= 0xFF808080, //
Green
= 0xFF008000, //
GreenYellow
= 0xFFADFF2F, //
Honeydew
= 0xFFF0FFF0, //
HotPink
= 0xFFFF69B4, //
IndianRed
= 0xFFCD5C5C,//
Indigo
= 0xFF4B0082, //
Ivory
= 0xFFFFFFF0, //
Khaki
= 0xFFF0E68C, //
Lavender
= 0xFFE6E6FA, //
LavenderBlush= 0xFFFFF0F5, //
LawnGreen
= 0xFF7CFC00, //
LemonChiffon
= 0xFFFFFACD, //
LightBlue
= 0xFFADD8E6, //
LightCoral
= 0xFFF08080, //
LightCyan
= 0xFFE0FFFF, //
LightGoldenrodYellow =0xFFFAFAD2, //
LightGray
= 0xFFD3D3D3,
//
LightGreen
= 0xFF90EE90, //
LightPink
= 0xFFFFB6C1, //
LightSalmon
= 0xFFFFA07A, //
LightSeaGreen= 0xFF20B2AA, //
LightSkyBlue
= 0xFF87CEFA, //
LightSlateGray= 0xFF778899, //
LightSteelBlue = 0xFFB0C4DE,//
LightYellow
= 0xFFFFFFE0, //
Lime
= 0xFF00FF00, //
LimeGreen
= 0xFF32CD32, //
Linen
= 0xFFFAF0E6, //
Magenta
= 0xFFFF00FF, //
Maroon
= 0xFF800000, //
MediumAquamarine =0xFF66CDAA, //
MediumBlue
= 0xFF0000CD, //
MediumOrchid = 0xFFBA55D3,//
MediumPurple
= 0xFF9370DB, //
MediumSeaGreen = 0xFF3CB371, //
MediumSlateBlue = 0xFF7B68EE, //
MediumSpringGreen =0xFF00FA9A,
//
MediumTurquoise = 0xFF48D1CC,//
MediumVioletRed = 0xFFC71585, //
MidnightBlue
= 0xFF191970, //
MintCream
= 0xFFF5FFFA, //
MistyRose
= 0xFFFFE4E1, //
Moccasin
= 0xFFFFE4B5, //
NavajoWhite
= 0xFFFFDEAD, //
Navy
= 0xFF000080, //
OldLace
= 0xFFFDF5E6, //
Olive
= 0xFF808000, //
OliveDra
= 0xFF6B8E23, //
Orange
= 0xFFFFA500, //
OrangeRed
= 0xFFFF4500, //
Orchid
= 0xFFDA70D6,//
PaleGoldenrod
= 0xFFEEE8AA, //
PaleGreen
PaleTurquoise
PaleVioletRed
PapayaWhip
PeachPuff
Peru
Pink
Plum
PowderBlue
Purple
Red
RosyBrown
RoyalBlue
SaddleBrown
Salmon
SandyBrown
SeaGreen
SeaShell
Sienna
Silver
SkyBlue
SlateBlue
SlateGray
Snow
SpringGreen
SteelBlue
Tan
Teal
Thistle
Tomato
Transparent
Turquoise
Violet
Wheat
White
WhiteSmoke
Yellow
YellowGreen
= 0xFF98FB98, //
= 0xFFAFEEEE, //
= 0xFFDB7093, //
= 0xFFFFEFD5, //
= 0xFFFFDAB9, //
= 0xFFCD853F, //
= 0xFFFFC0CB, //
= 0xFFDDA0DD,
//
= 0xFFB0E0E6, //
= 0xFF800080, //
= 0xFFFF0000, //
= 0xFFBC8F8F, //
= 0xFF4169E1, //
= 0xFF8B4513, //
= 0xFFFA8072, //
= 0xFFF4A460, //
= 0xFF2E8B57, //
= 0xFFFFF5EE, //
= 0xFFA0522D, //
= 0xFFC0C0C0, //
= 0xFF87CEEB, //
= 0xFF6A5ACD,//
= 0xFF708090, //
= 0xFFFFFAFA, //
= 0xFF00FF7F, //
= 0xFF4682B4, //
= 0xFFD2B48C,//
= 0xFF008080, //
= 0xFFD8BFD8,//
= 0xFFFF6347, //
= 0x00FFFFFF, //
= 0xFF40E0D0, //
= 0xFFEE82EE, //
= 0xFFF5DEB3, //
= 0xFFFFFFFF, //
= 0xFFF5F5F5, //
= 0xFFFFFF00, //
= 0xFF9ACD32 //
};
// Shift count and bit mask for A, R, G, B components
enum { //
AlphaShift = 24,
RedShift = 16,
GreenShift = 8,
BlueShift = 0
};
enum { //
AlphaMask = 0xff000000,
RedMask
= 0x00ff0000,
GreenMask = 0x0000ff00,
BlueMask = 0x000000ff
};
// Assemble A, R, G, B values into a 32-bit integer
static ARGB MakeARGB(BYTE a, BYTE r, BYTE g, BYTE b) {
return (((ARGB) (b) << BlueShift) |
((ARGB) (g) << GreenShift) |
((ARGB) (r) << RedShift) |
((ARGB) (a) << AlphaShift));
}
protected:
ARGB Argb; // 32 DWORD
};
#endif
GDI+
2Graphics
Graphics GDI+/ GDI
CDC Graphics
Gdiplusgraphics.h
1 Graphics
Graphics 4
Graphics(Image* image); //
Graphics(HDC hdc); //
Graphics(HDC hdc, HANDLE hdevice); //
//
Graphics(HWND hwnd, BOOL icm = FALSE);
CDC CDC
CDC HDC m_hDC;
GetDC CDC DC
// GetDC()_
Graphics graph(GetDC()->m_hDC);
2 status
Graphics status
0 0 GdiplusTypes.h
typedef enum { //
Ok = 0,
GenericError = 1,
InvalidParameter = 2,
OutOfMemory = 3,
ObjectBusy = 4,
InsufficientBuffer = 5,
NotImplemented = 6,
Win32Error = 7,
WrongState = 8,
Aborted = 9,
FileNotFound = 10,
ValueOverflow = 11,
AccessDenied = 12,
UnknownImageFormat = 13,
FontFamilyNotFound = 14,
FontStyleNotFound = 15,
NotTrueTypeFont = 16,
UnsupportedGdiplusVersion = 17,
GdiplusNotInitialized = 18,
PropertyNotFound = 19,
PropertyNotSupported = 20,
ProfileNotFound = 21
} Status;
Graphics
3[] DrawLine[s]
GDI+ 6 //
DrawLines
Status DrawLine(const Pen* pen, INT x1, INT y1, INT x2, INT y2);
Status DrawLine(const Pen* pen, const Point& pt1, const Point& pt2);
Status DrawLines(const Pen* pen, const Point* points, INT count); //
Status DrawLine(const Pen* pen, REAL x1, REAL y1, REAL x2, REAL y2);
Status DrawLine(const Pen* pen, const PointF& pt1, const PointF& pt2);
Status DrawLines(const Pen* pen, const PointF* points, INT count);
DrawLine4
pen
(x1, y1) pt1
(x2, y2) pt2
GDI
CPoint MoveTo( int x, int y ); BOOL LineTo( int x, int y );
CPoint MoveTo( POINT point ); BOOL LineTo( POINT point );
DrawLines2
points
count
GDI BOOL Polyline( LPPOINT lpPoints, int nCount );
GDI+ GDI
GDI SelectObject CDC
GDI MoveTo LineTo
GDI
4[] DrawRectangle[s]
GDI+ 6 //
Rectangle = rect angle
Status DrawRectangle(const Pen* pen, const Rect& rect);
Status DrawRectangle(const Pen* pen, INT x, INT y, INT width, INT height);
Status DrawRectangles(const Pen* pen, const Rect* rects, INT count);
Status DrawRectangle(const Pen* pen, const RectF& rect);
Status DrawRectangle(const Pen* pen, REAL x, REAL y, REAL width, REAL height);
Status DrawRectangles(const Pen* pen, const RectF* rects, INT count);
DrawRectangle4
pen
rect
(x, y)
(width, height)
DrawRectangles2
rects
count
GDI Rectangle
BOOL Rectangle(int x1, int y1, int x2, int y2);
GDI+ 2 4 GDI
GDI
5[] DrawEllipse
GDI+ 4
6[] DrawArc
GDI+ 4
Status DrawArc(const Pen* pen, INT x, INT y, INT width, INT height, REAL startAngle, REAL
sweepAngle); // sweep
Status DrawArc(const Pen* pen, const Rect& rect, REAL startAngle, REAL sweepAngle);
Status DrawArc(const Pen* pen, REAL x, REAL y, REAL width, REAL height, REAL
startAngle, REAL sweepAngle);
Status DrawArc(const Pen* pen, const RectF& rect, REAL startAngle, REAL sweepAngle);
//
GDI Arc
BOOL Arc( int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4 );
BOOL Arc( LPCRECT lpRect, POINT ptStart, POINT ptEnd );
GDI
(x, y)nRadius fStartAngle fSweepAngle
BOOL AngleArc(int x, int y, int nRadius, float fStartAngle, float fSweepAngle);
GDI+
C++
x //
7 DrawPolygon
GDI+ 2
Status DrawPolygon(const Pen* pen, const Point* points, INT count);
Status DrawPolygon(const Pen* pen, const PointF* points, INT count);
DrawLines DrawPolygon
GDI Polygon
BOOL Polygon( LPPOINT lpPoints, int nCount );
GDI+ GDI RoundRect Chord
++
8
GDI+ GDI DC GDI+
[] FillRectangle[s]
Status FillRectangle(const Brush* brush, const Rect& rect);
Status FillRectangle(const Brush* brush, INT x, INT y, INT width, INT height);
Status FillRectangles(const Brush* brush, const Rect* rects, INT count);
Status FillRectangle(const Brush* brush, const RectF& rect);
Status FillRectangle(const Brush* brush, REAL x, REAL y, REAL width, REAL height);
Status FillRectangles(const Brush* brush, const RectF* rects, INT count);
Brush rect
GDI FillRect
void FillRect( LPCRECT lpRect, CBrush* pBrush );
GDI GDI GDI+
FillSolidRect
[] FillEllipse
Status FillEllipse(const Brush* brush, const Rect& rect);
Status FillEllipse(const Brush* brush, INT x, INT y, INT width, INT height);
Status FillEllipse(const Brush* brush, const RectF& rect);
Status FillEllipse(const Brush* brush, REAL x, REAL y, REAL width, REAL height);
GDI Ellipse
DrawPie
// pie DrawPie FillPie
Status DrawPie(const Pen* pen, const Rect& rect, REAL startAngle, REAL sweepAngle);
Status DrawPie(const Pen* pen, INT x, INT y, INT width, INT height, REAL startAngle, REAL
sweepAngle);
Status DrawPie(const Pen* pen, const RectF& rect, REAL startAngle, REAL sweepAngle);
Status DrawPie(const Pen* pen, REAL x, REAL y, REAL width, REAL height, REAL startAngle,
REAL sweepAngle);
GDI
BOOL Pie( int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4 );
BOOL Pie( LPCRECT lpRect, POINT ptStart, POINT ptEnd );
void DrawPies(Graphics &graph, const Color cols[], Point &O, int r, const float data[], int
n) {
// const Color *cols
Rect rect(O.X - r, O.Y - r, 2 * r, 2 * r);
float startAngle = 0, sweepAngle;
for (int i = 0; i < n; i++) {
sweepAngle = data[i] * 360.0f;
graph.FillPie(new SolidBrush(cols[i]), rect, startAngle, sweepAngle);
startAngle += sweepAngle;
}
}
void CGdipDrawView::OnDraw(CDC* pDC) {
FillPolygon
Status FillPolygon(const Brush* brush, const Point* points, INT count);
Status FillPolygon(const Brush* brush, const Point* points, INT count, FillMode fillMode);
Status FillPolygon(const Brush* brush, const PointF* points, INT count);
Status FillPolygon(const Brush* brush, const PointF* points, INT count, FillMode fillMode);
GDI Polygon
FillMode
typedef enum {
FillModeAlternate, //
FillModeWinding //
} FillMode;
FillModeAlternate
FillModeWinding
GDI []
GDI+ GDI+
GDI GDI+
9
GDI+ GDI Draw
Fill
GDI+
Bezierspline
1
TrueType B
B Hermite
Kochanek-Bartels Catmull-Rom
GDI+
void DrawPoints(Graphics &graph, const Color &col, int r, const Point* points, INT count)
{
SolidBrush brush(col);
for (int i = 0; i < count; i++)
graph.FillEllipse(&brush, Rect(points[i].X - r, points[i].Y - r, 2 * r, 2 * r));
}
void Example_DrawCurve(HDC hdc) {
Graphics graphics(hdc);
// Define a Pen object and an array of Point objects.
Pen greenPen(Color::Green, 3);
Point point1(100, 100);
Point point2(200, 50);
Point point3(400, 10);
Point point4(500, 100);
Point curvePoints[4] = {point1, point2, point3, point4};
// Draw the curve.
graphics.DrawCurve(&greenPen, curvePoints, 4, 1.0);
graphics.DrawCurve(new Pen(Color::Magenta), curvePoints, 4, 0.5);
graphics.DrawCurve(new Pen(Color::Blue), curvePoints, 4, 0.0);
//graphics.DrawCurve(&greenPen, curvePoints, 4);
//graphics.DrawClosedCurve(new Pen(Color::Aqua), curvePoints, 4);
//graphics.DrawBeziers(new Pen(Color::Chocolate), curvePoints, 4);
DrawPoints(graphics, Color::Red, 5, curvePoints, 4); // Draw the points in the curve.
}
DrawCurve
tension = 0.00.51.0
// DrawCurve/DrawClosedCurve/DrawBeziers
()()()
10
Graphics
Status SetSmoothingMode(SmoothingMode smoothingMode);
typedef enum {
SmoothingModeInvalid = QualityModeInvalid, //
SmoothingModeDefault = QualityModeDefault, //
SmoothingModeHighSpeed = QualityModeLow, //
SmoothingModeHighQuality = QualityModeHigh, // 8*4
SmoothingModeNone, //
SmoothingModeAntiAlias8x4, // 8*4
SmoothingModeAntiAlias=SmoothingModeAntiAlias8x4, // 8*4
SmoothingModeAntiAlias8x8 // 8*8
} SmoothingMode;
Graphics graph(pDC->m_hDC);
Pen pen(Color::Black, 4);
Rect rect(10, 10, 200, 200);
graph.DrawRectangle(&pen, rect);
graph.RotateTransform(1);
graph.TranslateTransform(20, 20);
//graph.SetSmoothingMode(SmoothingModeNone);
graph.DrawRectangle(&pen, rect);
graph.TranslateTransform(20, 20);
graph.SetSmoothingMode(SmoothingModeAntiAlias);
graph.DrawRectangle(&pen, rect);
11 Clear
GDI Invalidate
UpdateWindow GDI+ Clear
Status Clear(const Color &color);
color
Graphics graph(GetDC()->m_hDC);
graph.Clear(Color::White); // Graphics
3Pen
GDI GDI+pen /
0
1 Pen
Status SetAlignment(PenAlignment penAlignment);
PenAlignment
typedef enum {
PenAlignmentCenter = 0, //
PenAlignmentInset = 1 //
} PenAlignment;
Graphics graph(pDC->m_hDC);
Rect rect(20, 20, 300, 200);
Pen pen(Color::Green, 30), redPen(Color::Red);
graph.DrawEllipse(&pen, rect);
graph.DrawRectangle(&redPen, rect);
pen.SetAlignment(PenAlignmentInset); //
graph.TranslateTransform(340, 0);
graph.DrawEllipse(&pen, rect);
graph.DrawRectangle(&redPen, rect);
SetAlignment
1
Pen
// Hatch HatchBrush
HatchBrush hBrush(HatchStyleCross, Color::Green, Color::Red); //
Pen hPen(&hBrush, 40); // 40
graph.DrawEllipse(&hPen, 20, 20, 400, 250); //
// TextureBrush
Image img(L".bmp"); //
TextureBrush tBrush(&img); //
Pen tPen(&tBrush, 80); // 80
Graphics graph(GetDC()->m_hDC); //
graph.DrawEllipse(&tPen, 40, 40, 640, 400); //
2
GDI GDI+
Status SetDashStyle(DashStyle dashStyle); // dash
DashStyleGdiplusEnums.h
enum DashStyle {
DashStyleSolid,
// 0
DashStyleDash,
// 1
DashStyleDot,
// 2
DashStyleDashDot,
// 3
DashStyleDashDotDot, // 4
DashStyleCustom // 5
}; // SetDashStyle
Pen
DashStyle GetDashStyle() const;
GDI+ GDI
GDI >1 GDI+
GDI+
Pen
Status SetDashPattern(const REAL *dashArray, INT count);
dashArray
count >0
Graphics graph(pDC->m_hDC);
Pen pen(Color::Black, 8); // 8
REAL dashVals[4] = {5.0f, 2.0f, 15.0f, 4.0f}; // 5 2 15 4
FontFamily fontFamily(L"Times New Roman"); //
Font font(&fontFamily, 10.5); // 5 Times New Roman
SolidBrush brush(Color(0, 128, 0)); //
//
CString strs[] = {L"DashStyleSolid", L"DashStyleDash", L"DashStyleDot",
L"DashStyleDashDot", L"DashStyleDashDotDot", L"DashStyleCustom"};
for (int i = 0; i <= 5; i++) { //
pen.SetDashStyle((DashStyle)i); //
if (i == 5) pen.SetDashPattern(dashVals, 4); //
graph.DrawLine(&pen, 10, 10 + i * 20, 400, 10 + i * 20); //
//
graph.DrawString(strs[i], -1, &font, PointF(410, 2 + i * 20), &brush);
}
Pen
INT GetDashPatternCount(VOID); //
Status GetDashPattern(REAL *dashArray, INT count); //
3
line cap Pen
//
GraphicsPath startPath, endPath; //
startPath.AddRectangle(Rect(-10, -5, 20, 10)); //
Point polygonPoints[4] = {Point(0, -20), Point(10, 0), Point(0, -10), Point(-10, 0)};
endPath.AddPolygon(polygonPoints, 4);//
CustomLineCap startCap(NULL, &startPath); //
CustomLineCap endCap(NULL, &endPath); //
//
Pen pen(Color::Black, 20); //
Pen redPen(Color::Red); //
//
CString cstrs[] = {L"", L"", L"", L"", L"", L"", L"
", L"", L"", L""};
CString estrs[] = {L"LineCapFlat", L"LineCapSquare", L"LineCapRound",
L"LineCapTriangle", L"LineCapNoAnchor", L"LineCapSquareAnchor",
L"LineCapRoundAnchor", L"LineCapDiamondAnchor",
L"LineCapArrowAnchor", L"LineCapCustom"};
// FontFamily fontfamily(L""); //
// Font font(&fontfamily, );
FontFamily fontFamily(L"Times New Roman"); // _GB2312""
Font font(&fontFamily, 10.5); //
//
Graphics graph(pDC->m_hDC);
for (int i = 0; i <= 9; i++) { //
LineCap lc = (LineCap)(i < 4 ? i : i + 12);//()
if ( i < 9) pen.SetLineCap(lc, lc, DashCapFlat); //
else { // i = 9
pen.SetCustomStartCap(&startCap); //
pen.SetCustomEndCap(&endCap); //
pen.SetWidth(3.0f); // 3
}
int y = 20 + i * 40; //
graph.DrawLine(&pen, 100, y, 400, y); //
graph.DrawLine(&redPen, 100, y, 400, y); //
//
graph.DrawString(cstrs[i], -1, &font, PointF(15.0f, y - 8.0f), &brush);
graph.DrawString(estrs[i], -1, &font, PointF(425.0f, y - 8.0f), &brush);
}
startCap endCap <math.h>
Pen pen(Color::DarkGreen, 2);
pen.SetCustomStartCap(&startCap);
pen.SetCustomEndCap(&endCap);
double radian = 3.14159265358979323846 / 180.0;
for (int i = 0; i < 360; i += 10)
graph.DrawLine(&pen, 220, 220, 220 + (INT) (200 * cos(i * radian)),
220 + (INT) (200 * sin(i * radian)));
DashCapRound = 2, //
DashCapTriangle = 3 //
} DashCap;
LineCap
SetLineCap
Graphics graph(pDC->m_hDC);
Pen pen(Color::Black, 10);
pen.SetLineCap(LineCapFlat, LineCapFlat, DashCapFlat); //
//pen.SetLineCap(LineCapFlat, LineCapFlat, DashCapRound);
//pen.SetLineCap(LineCapFlat, LineCapFlat, DashCapTriangle);
REAL dashVals[4] = {5.0f, 2.0f, 15.0f, 4.0f};
for (int i = 0; i <= 5; i++) {
pen.SetDashStyle((DashStyle)i);
if (i == 5) pen.SetDashPattern(dashVals, 4);
graph.DrawLine(&pen, 10, 10 + i * 20, 400, 10 + i * 20);
}
DashCapFlat
DashCapRound
DashCapTriangle
4
GDI+ Pen LineJoin
Status SetLineJoin(LineJoin lineJoin);
LineJoin
enum LineJoin {
LineJoinMiter
= 0, //
LineJoinBevel
= 1, //
LineJoinRound
= 2, //
LineJoinMiterClipped = 3 //
};
Graphics graph(pDC->m_hDC);
Pen pen(Color::DarkGreen, 40);
LineJoinMiter
LineJoinBevel
LineJoinRound
ineJoinMiterClipped
LineJoinMiterClipped
Pen
Status SetMiterLimit(REAL miterLimit);
10.0
LineJoinMiterClipped() miterLimit <
miterLimit = 1.0 miterLimit >=
LineJoinMiter() miterLimit < miterLimit
miterLimit >=
Graphics graph(pDC->m_hDC);
Pen redPen(Color::Red); //
Pen pen(Color::DarkGreen, 40.0f); //
Point points[] = {Point(20, 100), Point(400,130),Point(20,160)};//
pen.SetLineJoin(LineJoinMiter); //
//pen.SetLineJoin(LineJoinBevel); //
//pen.SetLineJoin(LineJoinRound); //
//pen.SetLineJoin(LineJoinMiterClipped); //
//pen.SetMiterLimit(20.0f); //
graph.DrawLines(&pen, points, 3); //
graph.DrawLines(&redPen, points, 3); //
LineJoinMiter 0.0f~13.0f
pen.SetLineJoin(LineJoinMiter); //
pen.SetMiterLimit(1.0f/*~13.0f*/); //
LineJoinMiter
4Brush
GDI GDI+brush /GDI+ GDI
GDI+
Brush
GDI+
GdiplusBase
Brush
SolidBrush
HatchBrush
TextureBrus
h
LinearGradientBrush
PathGradientBrush
GDI+
// (1) SolidBrush
// (2) HatchBrush
// (3) TextureBrush
// (4) LinearGradientBrush // gradient ,
// (5) PathGradientBrush
GdiplusBrush.h
0 Brush
Brush GDI+Brush
Brush
Brush *Clone(VOID) const; // Brush // *
Status GetLastStatus(VOID); //
BrushType GetType(VOID); //
BrushType GdiplusEnums.h
typedef enum {
BrushTypeSolidColor = 0, //
BrushTypeHatchFill = 1, //
BrushTypeTextureFill = 2, //
BrushTypePathGradient = 3, //
BrushTypeLinearGradient = 4 //
} BrushType;
1 SolidBrush
GDI+ SolidBrush
SolidBrush(const Color &color);
n
r =| l cos | // mathtype
2
l n
x = r cos
0 2
y = r sin
GDI+
void DrawLeaves(Graphics &graph, Color col, Point &O, int l, int n);
Graphics graph(pDC->m_hDC);
Color cols[] = {Color::Aqua, Color::Aquamarine, Color::DarkBlue, Color::DarkKhaki,
Color::DeepPink, Color::BlueViolet, Color::Brown, Color::BurlyWood,
Color::CadetBlue, Color::Chartreuse, Color::Turquoise, Color::Coral,
Color::CornflowerBlue, Color::Crimson, Color::DarkCyan};
bool color = true; // false;
for (int i = 0; i < 15; i++) DrawLeaves(graph, color ? cols[i] : Color::Green,
Point(100 + 200* (i % 5), 100 + 200 * (i / 5)), 100, i + 1);
2 HatchBrush
HatchBrush
HatchStyle GetHatchStyle(VOID) const;
Status GetForegroundColor(Color *color) const;
Status GetBackgroundColor(Color *color) const;
GDI+ 53 GDI 6 HatchStyle
GdiplusEnums.h
enum HatchStyle {
HatchStyleHorizontal,
// 0
HatchStyleVertical,
// 1
HatchStyleForwardDiagonal,
// 2
HatchStyleBackwardDiagonal,
// 3
HatchStyleCross,
//
HatchStyleDiagonalCross,
HatchStyle05Percent,
HatchStyle10Percent,
HatchStyle20Percent,
HatchStyle25Percent,
HatchStyle30Percent,
HatchStyle40Percent,
HatchStyle50Percent,
HatchStyle60Percent,
HatchStyle70Percent,
HatchStyle75Percent,
HatchStyle80Percent,
HatchStyle90Percent,
HatchStyleLightDownwardDiagonal,
HatchStyleLightUpwardDiagonal,
HatchStyleDarkDownwardDiagonal,
HatchStyleDarkUpwardDiagonal,
HatchStyleWideDownwardDiagonal,
HatchStyleWideUpwardDiagonal,
HatchStyleLightVertical,
HatchStyleLightHorizontal,
HatchStyleNarrowVertical,
HatchStyleNarrowHorizontal,
//
HatchStyleDarkVertical,
HatchStyleDarkHorizontal,
HatchStyleDashedDownwardDiagonal,
HatchStyleDashedUpwardDiagonal,
HatchStyleDashedHorizontal,
HatchStyleDashedVertical,
HatchStyleSmallConfetti,
//
HatchStyleLargeConfetti,
//
HatchStyleZigZag,
HatchStyleWave,
//
HatchStyleDiagonalBrick,
//
HatchStyleHorizontalBrick,
HatchStyleWeave,
HatchStylePlaid,
//
HatchStyleDivot,
//
HatchStyleDottedGrid,
HatchStyleDottedDiamond,
HatchStyleShingle,
HatchStyleTrellis,
//
HatchStyleSphere,
HatchStyleSmallGrid,
//
HatchStyleSmallCheckerBoard,
HatchStyleLargeCheckerBoard,
HatchStyleOutlinedDiamond,
HatchStyleSolidDiamond,
//
4
// 5
// 65%
// 710%
// 820%
// 925%
// 1030%
// 1140%
// 1250%
// 1360%
// 1470%
// 1575%
// 1680%
// 1790%
// 18
// 19
// 20
// 21
// 22
// 23
// 24
// 25
// 26
27
// 28
// 29
// 30
// 31
// 32
// 33
34
35
// 36
37
38
// 39
// 40
41
42
// 43
// 44
// 45
46
// 47
48
// 49
// 50
// 51
52
HatchStyleTotal, // = 530 ~ 52
HatchStyleLargeGrid = HatchStyleCross, // 4
HatchStyleMin
HatchStyleMax
= HatchStyleHorizontal, // 0
= HatchStyleTotal - 1, // 52
};
Graphics graph(pDC->m_hDC);
Pen pen(Color::Black);
SolidBrush textBrush(Color::Red);
FontFamily fontFamily(L"Times New Roman");
Font font(&fontFamily, 18);
CString str;
StringFormat sfmt; //
sfmt.SetAlignment(StringAlignmentCenter); //
sfmt.SetLineAlignment(StringAlignmentCenter); //
int w = 50, h = 50, s = 5;
for (int i = 0; i < 53; i++) { //
// (HatchStyle)
HatchBrush brush(HatchStyle(i), Color::Black, Color::White);
RectF rect(REAL(s + (i % 10) * (w + s)),
REAL(s + (i / 10) * (h + s)), REAL(w), REAL(h));
graph.FillRectangle(&brush, rect); //
str.Format(L"%d", i); //
graph.DrawString(str, str.GetLength(), &font, rect, &sfmt, &textBrush);
}
0 52 // (HatchStyle)i
SolidBrush textBrush(Color::Yellow);
GDI GDI+ Graphics //
Rendering
Status SetRenderingOrigin(INT x, INT y);
(x, y)(0, 0)
GDI CDC SetBrushOrg
CPoint SetBrushOrg( int x, int y );
CPoint SetBrushOrg( POINT point );
3 TextureBrush
texture brush
GDI BMP
GDI+ TextureBrush 7
TextureBrush(Image* image, WrapMode wrapMode = WrapModeTile);
TextureBrush(Image* image, WrapMode wrapMode, const RectF &dstRect);
TextureBrush(Image
*image,
const
RectF
&dstRect,
const
ImageAttributes
*imageAttributes = NULL);
TextureBrush(Image *image, const Rect &dstRect, const ImageAttributes *imageAttributes
= NULL);
TextureBrush(Image* image, WrapMode wrapMode, const Rect &dstRect);
TextureBrush(Image* image, WrapMode wrapMode, REAL dstX, REAL dstY, REAL dstWidth,
REAL dstHeight);
TextureBrush(Image* image, WrapMode wrapMode, N INT dstX, INT dstY, INT dstWidth, INT
dstHeight);
GdiplusEnums.h
typedef enum {
WrapModeTile = 0, //
WrapModeTileFlipX = 1, // X
WrapModeTileFlipY = 2, // Y
WrapModeTileFlipXY = 3, // XY
WrapModeClamp = 4 //
} WrapMode;
Graphics graph(pDC->m_hDC);
Image img(L".bmp");
TextureBrush brush(&img, WrapModeTile/*FlipXY*/ ); // WrapModeClamp
RECT rect;
GetClientRect(&rect);
graph.FillRectangle(&brush, RectF(0.0f, 0.0f, REAL(rect.right), REAL(rect.bottom)));
WrapModeTile
X WrapModeTileFlipX
Y WrapModeTileFlipY
XY WrapModeTileFlipXY
WrapModeClamp
TextureBrush translate
rotatescaletransform GDI
Status TranslateTransform(REAL dx, REAL dy, MatrixOrder order = MatrixOrderPrepend);
Status RotateTransform(REAL angle, MatrixOrder order = MatrixOrderPrepend);
Status ScaleTransform(REAL sx, REAL sy, MatrixOrder order = MatrixOrderPrepend);
Graphics graph(pDC->m_hDC);
Image img(L".bmp");
TextureBrush brush(&img);
//brush.TranslateTransform(30, 30); // (30, 30)
brush.RotateTransform(30); // 30
//brush.ScaleTransform(3, 1); // 3
//brush.ScaleTransform(1, 3); // 3
RECT rect;
GetClientRect(&rect);
graph.FillRectangle(&brush, RectF(0.0f, 0.0f, REAL(rect.right), REAL(rect.bottom)));
(30, 30)
30
4 LinearGradientBrush
linear gradient brush GDI+
LinearGradientBrush 6
LinearGradientBrush(const Point& point1, const Point& point2, const Color& color1, const
Color& color2);
LinearGradientBrush(const Rect& rect, const Color& color1, const Color& color2,
LinearGradientMode mode);
LinearGradientBrush(const Rect& rect, const Color& color1, const Color& color2, REAL
angle, BOOL isAngleScalable = FALSE);
LinearGradientBrush(const PointF& point1, const PointF& point2, const Color& color1,
const Color& color2);
LinearGradientBrush(const RectF& rect, const Color& color1, const Color& color2,
LinearGradientMode mode);
LinearGradientBrush(const RectF& rect, const Color& color1, const Color& color2, REAL
angle, BOOL isAngleScalable = FALSE);
p1 p2 y p1 p2 x
p1 p2 x y
Graphics graph(pDC->m_hDC);
Point p1(10, 10), p2(110, 10), p3(10, 110), p4(230, 10), p5(330, 110);
Size size(100, 100);
Color col1(255, 0, 0), col2(0, 0, 255);
LinearGradientBrush hbrush(p1, p2, col1, col2);
graph.FillRectangle(&hbrush, Rect(p1, size));
LinearGradientBrush vbrush(p1, p3, col1, col2);
graph.FillRectangle(&vbrush, Rect(Point(120, 10), size));
LinearGradientBrush dbrush(p4, p5, col1, col2);
graph.FillRectangle(&dbrush, Rect(Point(230, 10), size));
//
typedef enum {
LinearGradientModeHorizontal = 0, //
LinearGradientModeVertical = 1, //
LinearGradientModeForwardDiagonal = 2, //
LinearGradientModeBackwardDiagonal = 3 //
} LinearGradientMode;
Horizontal
BackwardDiagonal
Vertical
ForwardDiagonal
Graphics graph(pDC->m_hDC);
Color col1(255, 0, 0), col2(0, 0, 255);
Size size(100, 100);
Rect rect1(Point(10, 10), size);
// (LinearGradientMode)0
LinearGradientBrush hbrush(rect1,col1,col2,LinearGradientModeHorizontal);
graph.FillRectangle(&hbrush, rect1);
Rect rect2(Point(120, 10), size);
LinearGradientBrush vbrush(rect2,col1,col2,LinearGradientModeVertical);
graph.FillRectangle(&vbrush, rect2);
Rect rect3(Point(230, 10), size);
LinearGradientBrush fdbrush(rect3,col1,col2,LinearGradientModeForwardDiagonal);
graph.FillRectangle(&fdbrush, rect3);
color2,
LinearGradientBrush(const Rect& rect, const Color& color1, const Color& color2, REAL
angle, BOOL isAngleScalable = FALSE);
isAngleScalable = FALSE
angle
angle
Graphics graph(pDC->m_hDC);
Pen pen(Color::Black);
SolidBrush textBrush(Color::Black);
FontFamily fontFamily(L"");
Font font(&fontFamily, 10.5);
wchar_t str[10]; // wchar_t
http://msdn.microsoft.com/library/chs/default.asp?
url=/library/CHS/cpref/html/frlrfsystemdrawingstringformatclassctortopic.asp
StringFormat sfmt; // StringFormat??
sfmt.SetAlignment(StringAlignmentCenter);//
Color col1(255, 0, 0), col2(0, 0, 255);
int l = 100, d = 10, ld = l + d, sd = 15;
Size size(l, l);
for (int i = 0; i < 24; i++) {
Rect rect(Point(d + (i % 6) * ld, d + (i / 6) * (ld + sd)), size);
REAL angle = i * 15.0f;
LinearGradientBrush brush(rect, col1, col2, angle);
graph.FillRectangle(&brush, rect);
swprintf_s(str, 10, L"%g", angle);
graph.DrawString(str, INT(wcslen(str)), &font, PointF(rect.X + rect.Width / 2.0f,
rect.GetBottom() + 5.0f), &sfmt, &textBrush); // &sfmt???
}
isAngleScalable = TRUE
= angle
= arctan( (width / height) tan() )
width = height = width > height > width <
height <
-90< < 90
Graphics graph(pDC->m_hDC);
REAL angle = 30.0f;
Color col1(255, 0, 0), col2(0, 0, 255);
Rect rect1(Point(10, 10), Size(100, 200));
LinearGradientBrush brush1(rect1, col1, col2, angle, TRUE);
graph.FillRectangle(&brush1, rect1);
Rect rect2(Point(120, 10), Size(150, 200));
LinearGradientBrush brush2(rect2, col1, col2, angle, TRUE);
graph.FillRectangle(&brush2, rect2);
Rect rect3(Point(280, 10), Size(200, 200));
LinearGradientBrush brush3(rect3, col1, col2, angle, TRUE);
graph.FillRectangle(&brush3, rect3);
Rect rect4(Point(10, 220), Size(200, 150));
LinearGradientBrush brush4(rect4, col1, col2, angle, TRUE);
graph.FillRectangle(&brush4, rect4);
Rect rect5(Point(220, 220), Size(200, 100));
LinearGradientBrush brush5(rect5, col1, col2, angle, TRUE);
graph.FillRectangle(&brush5, rect5);
30
Graphics graph(pDC->m_hDC);
REAL factors[4] = {0.0f, 0.4f, 0.6f, 1.0f};
REAL positions[4] = {0.0f, 0.2f, 0.8f, 1.0f};
LinearGradientBrush brush(Point(0, 0),Point(510, 0), Color::Red, Color::Blue);
graph.FillRectangle(&brush, 10, 10, 500, 50); //
brush.SetBlend(factors, positions, 4); //
graph.FillRectangle(&brush, 10, 70, 500, 50);
brush.SetBlendTriangularShape(0.5f, 0.6f); // 0.6
graph.FillRectangle(&brush, 10, 130, 500, 50);
brush.SetBlendTriangularShape(0.5f, 0.8f); // 0.8
graph.FillRectangle(&brush, 10, 190, 500, 50);
4 4
3
GDI+ GDI Windows XP LCD
GDI+ ClearType
GDI+
Windows TrueTypeTTF = TrueType Font 1991
Apple Microsoft B
GDI+ FontFamily Font FontCollection
InstalledFontCollection PrivateFontCollection GDI
CFont
GdiplusBase
Font
FontFamily
FontCollection
InstalledFontCollection
PrivateFontCollection
1
1 FontFamily
font familytypefacestylefont
ArialTimes New Romanregular
bolditalicbold and italicunderlinestrikeout
FontFamily
FontFamily(VOID); //
FontFamily(const WCHAR *name, const FontCollection *fontCollection= NULL);
// name fontCollection
NULL
FontFamily fontFamily(L""); L"_GB2312"
FontFamily fontFamily(L"Times New Roman");
FontCollection InstalledFontCollection
INT GetFamilyCount(VOID) const; // Sought seek
Status GetFamilies(INT numSought,FontFamily *gpfamilies,INT *numFound)const;
// neutral ,
Status GetFamilyName(WCHAR name[LF_FACESIZE],WCHAR language=LANG_NEUTRAL)const;
LANG_NEUTRAL
MFC Fonts GDI+
void CFontsView::OnDraw(CDC* pDC) {
InstalledFontCollection ifc;
int n = ifc.GetFamilyCount(); // (1)
FontFamily *ffs = new FontFamily[n]; // (2)
int found;
//
ifc.GetFamilies(n, ffs, &found); // (3)
wchar_t name[LF_FACESIZE];
Font font(L"", 18);
SolidBrush textBrush(Color::Black);
Graphics graph(pDC->m_hDC);
wchar_t str[40]; // charwchar_t; sprintfswprintf_s;
swprintf_s(str, 40, L"%d ", n);
graph.DrawString(str, INT(wcslen(str)), &font, PointF(10.0f, 10.0f), &textBrush);
for (int i = 0; i < n; i++) {
ffs[i].GetFamilyName(name); // (4)
graph.DrawString(name, INT(wcslen(name)), &font,
PointF(10.0f, 80.0f + 40 * i), &textBrush);
graph.DrawString(L"Font Family ", 15, &Font(name, 18),
PointF(300.0f, 80.0f + 40 * i), &textBrush);
}
Academy Engraved
LET
Albertus
Chasm
Lucida Sans
Clarendon
Smudger LET
Clarendon Condensed
Lynda Cursive
Square721 BT
Albertus Medium
Clarendon Extended
Mangal
Staccato222 BT
Amaze
Comic Sans MS
Marigold
Surfer
Antique Olive
Coronet
Marlett
Sylfaen
Courier New
Mekanik LET
Symbol
CourierPS
SymbolPS
Arial Black
Dolphin
Milano LET
Tahoma
Arial Narrow
Dotum
MingLiU
Times
Bangle
DotumChe
Mirror
Bart
Estrangelo Edessa
MisterEarl BT
Basemic
Eurasia
Monotype Corsiva
Trebuchet MS
Basemic Symbol
Flat Brush
MS Gothic
Tunga
Basemic Times
MS Mincho
Univers
Batang
Galant
MS Outlook
Univers Condensed
BatangChe
Garamond
MS PGothic
Bimini
Gautami
MS PMincho
Blackletter686 BT
Gaze
Verdana
Book Antiqua
Georgia
Gulim
MS Reference Sans
Serif
MS
Reference
Specialty
MS UI Gothic
Bookshelf Symbol 7
GulimChe
MT Extra
Westwood LET
Broadway BT
Gungsuh
MV Boli
Wingdings
cajcd fnta0
GungsuhChe
cajcd fnta1
Helvetica
New
Schoolbook
Nina
cajcd fnta4
Helvetica Narrow
Notes
ZWAdobeF
cajcd fnta6
Highlight LET
Odessa LET
_GB2312
cajcd fnta7
HolidayPi BT
OldDreadfulNo7 BT
cajcd fnta8
Impact
Antique
Compact
Arial
Olive
Century
Victorian LET
Webdings
Wingdings 2
Wingdings 3
cajcd fntaa
Orange LET
cajcd fntac
Palatino
cajcd fntae
Palatino Linotype
cajcd fntbd
Paris
cajcd fntbz
ParkAvenue BT
cajcd fntdg
PMingLiU
cajcd fnthx
cajcd fntlt
Quixley LET
cajcd fntra
Jokerman LET
Raavi
cajcd fntst
Kelt
cajcd fnttab
Ruach LET
_GB2312
Calligraph421 BT
La Bamba LET
Scruff LET
Cataneo BT
Latha
Short Hand
Century Gothic
Letter Gothic
Shruti
CG Omega
Liberate
Signs
CG Times
Lucida Console
Simpson
ofstream
CFile
UTF-16 0xFE 0xFF
2 Font
Font 6
Font(const FontFamily *family, REAL emSize, INT style = FontStyleRegular, Unit unit =
UnitPoint);
Font(const WCHAR *familyName, REAL emSize, INT style = FontStyleRegular, Unit unit =
UnitPoint, const FontCollection *fontCollection = NULL);
Font(HDC hdc, const HFONT hfont);
Font(HDC hdc, const LOGFONTA *logfont);
Font(HDC hdc, const LOGFONTW *logfont);
Font(HDC hdc);
2
API DC
GDI
Font(const WCHAR *familyName, REAL emSize, INT style = FontStyleRegular, Unit unit =
UnitPoint, const FontCollection *fontCollection = NULL);
3
familyName // L
Family Name
Family Name
Family Name
Family Name
Family Name
Family Name
-Font Family Name
Font
Font
Font
Font
Font
Font
MisterEarl BT
4 FontStyle
style FontStyleRegular
typedef enum {
FontStyleRegular = 0, //
FontStyleBold = 1, //
FontStyleItalic = 2, //
FontStyleBoldItalic = 3, //
FontStyleUnderline = 4, //
FontStyleStrikeout = 8 //
} FontStyle; //
5 Unit
emSize unit
typedef enum {
UnitWorld = 0, //
UnitDisplay = 1, //
UnitPixel = 2, // 1/54 1/96
UnitPoint = 3, // 1/72
UnitInch = 4, //
UnitDocument = 5, // 1/300
UnitMillimeter = 6 // mm
} Unit;
em = M
GDI CFont UnitPoint
Unit 1 =1/54
Pixel
133.333
3
80
56
48
34.6667
32
29.3333
24
21.3333
20
18.6667
16
14
12
10
8.6667
7.3333
6.6667
Unit
Point
Inch
Docume
nt
100
1.3889
416.6667
60
42
36
26
24
22
18
16
15
14
12
10.5
9
7.5
6.5
5.5
5
0.8333
0.5833
0.5
0.3611
0.3333
0.3056
0.25
0.2222
0.2083
0.1944
0.1667
0.1458
0.125
0.1042
0.0903
0.0764
0.0694
250
175
150
108.3333
100
91.6667
75
66.6667
62.5
58.3333
50
43.75
37.5
31.25
27.0833
22.9167
20.8333
Millimet
er
35.2778
21.1667
14.8167
12.7
9.1722
8.4667
7.7611
6.35
5.6444
5.2917
4.9389
4.2333
3.7042
3.175
2.6458
2.2931
1.9403
1.7639
REAL fs[] = {100, 60, 42, 36, 26, 24, 22, 18, 16, 15, 14, 12, 10.5, 9, 7.5, 6.5, 5.5, 5};
CString fno[] = {L"", L"", L"", L"", L"", L"", L"", L"", L"", L"",
L"", L"", L"", L"", L"", L"", L"", L""};
wchar_t str[100];
REAL size, y = 10.0f;
SolidBrush textBrush(Color::Black);
Graphics graph(pDC->m_hDC);
for (int i = 0; i < 18; i++) {
size = fs[i];
swprintf_s(str, 100, L"%s (%.4g %g %.4g %.4g %.4g )",
fno[i],size*4/3.0, size, size/72.0, size*300/72.0,size /72.0*25.4);
graph.DrawString(str, INT(wcslen(str)), &Font(L"", size), PointF(10.0f, y), &textBrush);
y += size * 1.5f;
}
2
GDI CDC TextOutDrawText ExtTextOut GDI+
Graphics DrawString
1 DrawString
Status DrawString(const WCHAR *string, INT length, const Font *font, const PointF
&origin, const Brush *brush);
Status DrawString(const WCHAR *string, INT length, const Font *font, const PointF &origin,
const StringFormat *stringFormat, const Brush *brush);
Status DrawString(const WCHAR *string, INT length, const Font *font, const RectF
&layoutRect, const StringFormat *stringFormat, const Brush *brush); // layout
Graphics
null -1
PointF
RectF
StringFormat
2 StringFormat
StringFormat GdiplusBase GDI+
formatFlags StringFormatFlags
typedef enum {
StringFormatFlagsDirectionRightToLeft = 0x00000001, //
StringFormatFlagsDirectionVertical = 0x00000002, //
StringFormatFlagsNoFitBlackBox = 0x00000004, //
StringFormatFlagsDisplayFormatControl = 0x00000020, // Unicode
StringFormatFlagsNoFontFallback = 0x00000400, //
StringFormatFlagsMeasureTrailingSpaces = 0x00000800, //
StringFormatFlagsNoWrap = 0x00001000, //
StringFormatFlagsLineLimit = 0x00002000, //
StringFormatFlagsNoClip = 0x00004000 //
} StringFormatFlags;
3 LANGID
language 16 LANGID LANG_NEUTRAL
MAKELANGID
WORD MAKELANGID(
USHORT usPrimaryLanguage, // primary language identifier
USHORT usSubLanguage
// sublanguage identifier
);
Identifier
0x00
0x01
0x04
0x07
0x09
0x0a
0x0c
0x10
0x11
0x12
0x19
Predefined symbol
LANG_NEUTRAL
LANG_ARABIC
LANG_CHINESE
LANG_GERMAN
LANG_ENGLISH
LANG_SPANISH
LANG_FRENCH
LANG_ITALIAN
LANG_JAPANESE
LANG_KOREAN
LANG_RUSSIAN
Language
Neutral
Arabic
Chinese
German
English
Spanish
French
Italian
Japanese
Korean
Russian
Identifi
Predefined symbol
er
0x00
SUBLANG_NEUTRAL
0x01
SUBLANG_DEFAULT
0x02
SUBLANG_SYS_DEFAULT
0x01
SUBLANG_CHINESE_TRADITIONAL
0x02
SUBLANG_CHINESE_SIMPLIFIED
0x03
SUBLANG_CHINESE_HONGKONG
0x04
0x05
0x01
0x02
0x03
0x04
SUBLANG_CHINESE_SINGAPORE
SUBLANG_CHINESE_MACAU
SUBLANG_ENGLISH_US
SUBLANG_ENGLISH_UK
SUBLANG_ENGLISH_AUS
SUBLANG_ENGLISH_CAN
Language
Language neutral
User Default
System Default
Chinese (Traditional)
Chinese (Simplified)
Chinese (Hong Kong SAR, PRC)
Chinese (Singapore)
Chinese (Macao SAR, PRC)
English (US)
English (UK)
English (Australian)
English (Canadian)
4
StringFormat
StringFormatFlagsDirectionRightToLeft StringFormatFlagsDirectionVertical
Graphics graph(pDC->m_hDC);
Pen pen(Color::Black);
SolidBrush textBrush(Color::Black);
REAL w = 150.0f, h = 120.0f, d = 10.0f;
REAL x1 = d, x2 = x1 + w + d;
REAL y1 = d, y2 = y1 + h + d;
SizeF size(w, h);
RectF rect1(PointF(x1, y1), size), rect2(PointF(x2, y1), size),
rect3(PointF(x1, y2), size), rect4(PointF(x2, y2), size);
Font font(L"", 12);
CString str = L"\r\n \r\n \r\n ";
graph.DrawRectangle(&pen, rect1);
StringFormat stringFormat1; //
graph.DrawString(str, str.GetLength(), &font, rect1, &stringFormat1, &textBrush);
graph.DrawRectangle(&pen, rect2); // StringFormatFlagsDirection
StringFormat stringFormat2(StringFormatFlagsDirectionRightToLeft);
graph.DrawString(str, str.GetLength(), &font, rect2, &stringFormat2, &textBrush);
graph.DrawRectangle(&pen, rect3);
StringFormat stringFormat3(StringFormatFlagsDirectionVertical);
graph.DrawString(str, str.GetLength(), &font, rect3, &stringFormat3, &textBrush);
graph.DrawRectangle(&pen, rect4);
StringFormat stringFormat4(StringFormatFlagsDirectionRightToLeft |
StringFormatFlagsDirectionVertical); //
graph.DrawString(str, str.GetLength(), &font, rect4, &stringFormat4, &textBrush);
5
StringFormatF
StringFormatFlags
Graphics graph(pDC->m_hDC);
Pen pen(Color::Black);
SolidBrush textBrush(Color::Black);
StringFormat stringFormat;
stringFormat.SetAlignment(StringAlignmentCenter); // StringAlignment
Font font0(L"", 12), font(L"", 18);
CString str = L"
";
6
StringFormat
Status SetAlignment(StringAlignment align); //
Status SetLineAlignment(StringAlignment align); //
typedef enum {
StringAlignmentNear = 0, //
StringAlignmentCenter = 1, //
StringAlignmentFar = 2 //
} StringAlignment;
Graphics graph(pDC->m_hDC);
Pen pen(Color::Black);
SolidBrush textBrush(Color::Black);
Font font(L"", 10.5);
CString str = L"";
graph.DrawString(str, str.GetLength(), &font, PointF(10.0f, 10.0f), &textBrush);
StringFormat stringFormat;
StringAlignment hsa, vsa;
CString astrs[3] = {L"", L"", L""};
CString hstrs[3] = {L"", L"", L""};
CString vstrs[3] = {L"", L"", L""};
REAL w = 200.0f, h = 100.0f, d = 10.0f;
SizeF size(w, h);
REAL x, y;
for (int i = 0; i < 9; i++) {
x = d + (w + d) * (i % 3);
y = 30.0f + d + (h + d) * (i / 3);
RectF rect(PointF(x, y), size);
graph.DrawRectangle(&pen, rect);
hsa = StringAlignment(i % 3); //
vsa = StringAlignment(i / 3);
stringFormat.SetAlignment(hsa); //
alignment
stringFormat.SetLineAlignment(vsa); // line_alignment
CString str = astrs[hsa] + astrs[vsa] + L"(" + hstrs[hsa] + vstrs[vsa] + L"" + (i ==
0 ? L"" : L"") + L")";
graph.DrawString(str, str.GetLength(), &font, rect, &stringFormat, &textBrush);
}
//
Graphics graph(pDC->m_hDC);
SolidBrush textBrush(Color::Red), shadowBrush(Color::Gray);
HatchBrush hatchBrush(HatchStyleForwardDiagonal, Color::Black, Color::White);
CString str = L"";
Graphics graph(pDC->m_hDC);
CString str = L"";
Font font(L"", 140);
HatchBrush hatchBrush1(HatchStyleForwardDiagonal, Color::Red, Color::White);
diagonal HatchStyle
graph.DrawString(str, str.GetLength(), &font, PointF(0.0f, 0.0f), &hatchBrush1);
HatchBrush hatchBrush2(HatchStyleBackwardDiagonal, Color::Green, Color::White);
graph.DrawString(str, str.GetLength(), &font, PointF(0.0f, 200.0f), &hatchBrush2);
HatchBrush hatchBrush3(HatchStyleCross, Color::Blue, Color::White);
graph.DrawString(str, str.GetLength(), &font, PointF(0.0f, 400.0f), &hatchBrush3);
//
Graphics graph(pDC->m_hDC);
CString str = L"";
Font font(L"", 140);
TextureBrush textureBrush(&Image(L".bmp"));
graph.DrawString(str, str.GetLength(), &font, PointF(10.0f, 10.0f), &textureBrush);
Graphics graph(pDC->m_hDC);
CString str = L"";
Font font(L"", 100);
Color cols[] = {Color::Red, Color::Orange, Color::Yellow, Color::Green, Color::Cyan,
Color::Blue, Color::Purple, Color::Magenta};
REAL bps[] = {0.0f, 0.15f, 0.3f, 0.45f, 0.6f, 0.75f, 0.875f, 1.0f};
LinearGradientBrush brush(Point(10, 10), Point(810, 10), Color::Black, Color::White); //
gradient
brush.SetInterpolationColors(cols, bps, 8); // interpolation
graph.DrawString(str, str.GetLength(), &font, PointF(10.0f, 10.0f), &brush);
// LinearGradientBrush.SetInterpolationColors(Color*, REAL*, int);
GDI+ GraphicsPath PathGradientBrush
Graphics graph(pDC->m_hDC);
FontFamily ff(L"");
wchar_t str[] = L"";
REAL emSize = 120; // UnitWorld
graph.DrawString(str, -1, &Font(L"", emSize, FontStyleRegular, UnitWorld), PointF(0,
0), &SolidBrush(Color::Green)); // FontStyle
GraphicsPath path, *pOutlinePath;
path.AddString(str, -1, &ff, FontStyleRegular, emSize, Point(0, 100), NULL); // 847
// &FontFamily
Pen pen(Color::Red);
graph.DrawPath(&pen, &path);
// Clone()
pOutlinePath = path.Clone(); // GraphicsPath*
pOutlinePath->Outline(); // _?
PathGradientBrush pgBrush(pOutlinePath);
int n = pOutlinePath->GetPointCount(); // 1023
Color *cols = new Color[n];
for(int i=0;i<n;i++) cols[i]=Color(rand()%255,rand()%255,rand()%255) ;
pgBrush.SetCenterColor(Color(rand()%255, rand()%255, rand() % 255));
pgBrush.SetSurroundColors(cols, &n); // surround
graph.TranslateTransform(0.0f, 100.0f); // 100
graph.FillPath(&pgBrush, &path); //
delete cols; //
8 ClearType
mosaic
ClearType 1999 4 7
LCDLiquid Crystal Display
CRT
LCD
LCD ClearType
LCD
LCD ClearType
ClearType 8
Windws XP ///
8
GDI+ Graphics
Graphics graph(pDC->m_hDC);
SolidBrush textBrush(Color::Black);
Font font(L"Arial", 16);
CString str = L"font smoothing";
wchar_t buf[5];
for (int i = 0; i < 6; i++) {
_itow_s(i, buf, 5, 10/**/); // _itoa()
graph.SetTextRenderingHint(TextRenderingHint(i));
graph.DrawString(buf, -1, &font, PointF(5.0f, 20.0f * i), &textBrush);
GDI GDI
GDI+ GDI+ 6
1
Windows XP /// /
2
InstalledFontCollection PrivateFontCollection
FontCollection
PrivateFontCollection
PrivateFontCollection(VOID);
Status AddFontFile(const WCHAR* filename);
Status AddMemoryFont(const VOID *memory, INT length);
HDZB_25.TTF HDZB_16.TTF
res
//
PrivateFontCollection pfc;
pfc.AddFontFile(L"C:\\myFonts\\HDZB_16.TTF");
if(pfc.GetLastStatus() != Ok){MessageBox(L""); return;}
pfc.AddFontFile(L"C:\\myFonts\\HDZB_25.TTF");
if(pfc.GetLastStatus() != Ok) {MessageBox(L""); return;}
int n = pfc.GetFamilyCount();
if (n < 2) {MessageBox(L""); return; }
//
FontFamily ffs[2];
int found;
pfc.GetFamilies(2, ffs, &found);
//
CString str0 = L"", str;
CString str1 = L"\r\n ";
//
StringFormat stringFormat;
stringFormat.SetAlignment(StringAlignmentCenter); // StringAlignment
RECT rect;
GetClientRect(&rect); // GetClientRect
//
Graphics graph(pDC->m_hDC);
SolidBrush textBrush(Color::Black);
// 1 1
wchar_t name[LF_FACESIZE]; // LF_FACESIZE
ffs[0].GetFamilyName(name);
Font font1(name, 60, FontStyleRegular, UnitPixel, &pfc);
str = str0 + name;
graph.DrawString(str, str.GetLength(), &font1, PointF(0.0f, 0.0f), &textBrush);
graph.DrawString(str1, str1.GetLength(), &font1, PointF(rect.right / 2.0f, 80.0f),
&stringFormat, &textBrush);
// 2 2
ffs[1].GetFamilyName(name);
Font font2(name, 60, FontStyleRegular, UnitPixel, &pfc);
str = str0 + name;
graph.DrawString(str, str.GetLength(), &font2, PointF(0.0f, 220.0f), &textBrush);
graph.DrawString(str1, str1.GetLength(), &font2, PointF(rect.right / 2.0f, 300.0f),
&stringFormat, &textBrush);
4
path
graphics path
GDI DC GDI+
1 GraphicsPath
GDI+ GraphicsPath GraphicsBase
1
GraphicsPath
GraphicsPath(FillMode fillMode = FillModeAlternate); //
GraphicsPath(const Point *points, const BYTE *types, INT count, FillMode fillMode =
FillModeAlternate); //
GraphicsPath(const PointF *points, const BYTE *types, INT count, FillMode fillMode =
FillModeAlternate); //
fillMode FillMode
Alternate :FillModeAlternate Winding
FillModeWinding
points
types
count points types
2
PathPointType
typedef enum {
PathPointTypeStart = 0, //
PathPointTypeLine = 1, //
PathPointTypeBezier = 3, //
PathPointTypePathTypeMask = 0x7, //
PathPointTypePathDashMode = 0x10, //
PathPointTypePathMarker = 0x20, //
PathPointTypeCloseSubpath = 0x80, //
PathPointTypeBezier3 = 3 // PathPointTypeBezier
} PathPointType;
3
GraphicsPath
subpath
CloseFigure CloseAllFigures
Status CloseFigure(VOID); //
Status CloseAllFigures(VOID); //
// ()
Graphics graph(pDC->m_hDC);
Pen pen(Color::Blue);
GraphicsPath path;
int n = path.GetPointCount(); //
Point *points = new Point[n];
path.GetPathPoints(points, n); //
//graph.FillPath(&SolidBrush(Color::Aqua), &path); //
graph.DrawLines(&Pen(Color::Green), points, n); //
//path.CloseAllFigures(); //
graph.DrawPath(&pen, &path); //
// DrawLines DrawPathDrawPath FillPath
DrawPoints(graph, Color::Red, 4, points, n); //
delete points; //
DrawPoints 2.29
4
GraphicsPath
//
Status AddLine(INT x1, INT y1, INT x2, INT y2);
Status AddLine(const Point &pt1, const Point &pt2);
Status AddLine(REAL x1, REAL y1, REAL x2, REAL y2);
Status AddLine(const PointF &pt1, const PointF &pt2);
//
Status AddLines(const Point *points, INT count);
Status AddLines(const PointF *points, INT count);
// polygon
Status AddPolygon(const Point *points, INT count);
Status AddPolygon(const PointF *points, INT count);
//
Status AddRectangle(const Rect &rect);
Status AddRectangle(const RectF &rect);
//
Status AddRectangles(const Rect *rects, INT count);
Status AddRectangles(const RectF *rects, INT count);
//
sweep
X
Status AddArc(INT x, INT y, INT width, INT height, REAL startAngle, REAL sweepAngle); Status
AddArc(const Rect &rect, REAL startAngle, REAL sweepAngle);
Status AddArc(REAL x, REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle);
Status AddArc(const RectF &rect, REAL startAngle, REAL sweepAngle);
// pie arc
Status AddPie(INT x,INT y, INT width, INT height, REAL startAngle, REAL sweepAngle);
Status AddPie(const Rect &rect, REAL startAngle, REAL sweepAngle);
Status AddPie(REAL x, REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle);
Status AddPie(const RectF &rect, REAL startAngle, REAL sweepAngle);
//
4
subpath
figure
GraphicsPath
Status StartFigure(VOID); //
Status CloseFigure(VOID); //
graph.TranslateTransform(250.0f, 0.0f);
graph.FillPath(&SolidBrush(Color::Lime), &path1);
graph.FillPath(&SolidBrush(Color::Aqua), &path2);
/
GDI+ GraphicsPathIterator
GraphicsPathIterator(GraphicsPath *path);
INT GetSubpathCount(VOID);
GraphicsPathIterator
INT NextSubpath(GraphicsPath *path, BOOL *isClosed);// ??
INT NextSubpath(INT *startIndex, INT *endIndex, BOOL *isClosed);
VOID Rewind(VOID);
4.13
Graphics graph(pDC->m_hDC);
Pen pen(Color::Blue);
GraphicsPath path;
path.AddLine(10.0f, 50.0f, 200.0f, 50.0f);
path.AddLine(60.0f, 10.0f, 60.0f, 80.0f);
path.AddEllipse(10, 100, 200, 120);
Point ps[] = {Point(220, 200), Point(250, 150), Point(300, 50), Point(400, 200)};
path.AddBeziers(ps, 4);
path.AddCurve(ps, 4);
int n = path.GetPointCount();
Point *points = new Point[n]; // delete points;
path.GetPathPoints(points, n);
graph.DrawLines(&Pen(Color::Green), points, n);
//path.SetFillMode(FillModeWinding);
graph.FillPath(&SolidBrush(Color::Aqua), &path);
graph.DrawPath(&pen, &path);
DrawPoints(graph, Color::Red, 4, points, n);
DrawPoints(graph, Color::Green, 4, ps, 4);
GraphicsPathIterator pathItr(&path);
int m = pathItr.GetSubpathCount();
CString str;
wchar_t buf[100];
swprintf_s(buf, 100, L" %d \r\n", m);
str += buf;
INT sn, start, end;
BOOL isClosed;
for (int i = 0; i < m; i++) {
sn = pathItr.NextSubpath(&start, &end, &isClosed);
swprintf_s(buf, 100, L"%d %ls %d \
%d~%d\r\n",
i + 1, isClosed ? L"" : L"", sn, start, end);
str += buf;
}
if (first) MessageBox(str);
first bool true OnDraw false
MessageBox OnDraw //
1
3
13
14 - 4 = 10 4
5
Graphics
Status DrawPath(const Pen *pen, const GraphicsPath *path);
GraphicsPath
Status SetFillMode(FillMode fillmode);
FillMode GetFillMode(VOID);
//path.SetFillMode(FillModeWinding); // winding
//
6
GraphicsPath
INT GetPointCount(VOID); //
Status GetPathPoints(Point *points, INT count); //
Status GetPathPoints(PointF *points, INT count); //
Status GetPathTypes(BYTE *types, INT count);//
int n = path.GetPointCount();
Point *points = new Point[n];
path.GetPathPoints(points, n);
graph.DrawLines(&Pen(Color::Green), points, n);
graph.FillPath(&SolidBrush(Color::Aqua), &path);
graph.DrawPath(&pen, &path);
DrawPoints(graph, Color::Red, 4, points, n);
delete points; // _add
2 PathGradientBrush
3.27
PathGradientBrush
Brush 3 // gradient
PathGradientBrush(const GraphicsPath *path);
PathGradientBrush(const Point *points, INT count, WrapMode wrapMode = WrapModeClamp);
PathGradientBrush(const PointF *points, INT count, WrapMode wrapMode = WrapModeClamp);
wrapMode WrapModeClamp
void FillPentacle(HDC hdc) {
INT count = 10;
Point points[] = {Point(100, 0), Point(122, 69), Point(195, 69), Point(137, 111), Point(159, 18
Point(100, 138), Point(41, 181), Point(63, 111), Point(5, 69), Point(78, 69)};
GraphicsPath path;
path.AddPolygon(points, count);
Graphics graph(hdc);
PathGradientBrush pgBrush(&path);
pgBrush.SetCenterColor(Color::Red);
//pgBrush.SetCenterColor(Color::Green);
graph.FillPath(&pgBrush, &path);
Color cols[] = {Color::Black, Color::Green, Color::Blue, Color::White, Color::Black,
Color::Green, Color::Blue, Color::White, Color::Black, Color::Green};
/*Color cols[] = {Color::Cyan, Color::Aqua, Color::Blue, Color::Chartreuse, Color::Coral,
Color::CadetBlue, Color::HotPink, Color::Turquoise, Color::LightSkyBlue, Color::DeepPink};
pgBrush.SetCenterColor(Color::White);*/
pgBrush.SetSurroundColors(cols, &count);
graph.TranslateTransform(200.0f, 0);
graph.FillPath(&pgBrush, &path);
for (int i=0;i<count;i++)cols[i]=Color(rand()%255, rand()%255,rand()%255);
pgBrush.SetSurroundColors(cols, &count);
pgBrush.SetCenterColor(Color(rand() % 255, rand() % 255, rand() % 255));
graph.TranslateTransform(- 200.0f, 200.0f);
graph.FillPath(&pgBrush, &path);
for (int i = 0; i < count; i++) cols[i] = Color(rand() % 255, rand() % 255, rand() % 255);
pgBrush.SetSurroundColors(cols, &count);
pgBrush.SetCenterColor(Color(rand() % 255, rand() % 255, rand() % 255));
graph.TranslateTransform(200.0f, 0.0f);
graph.FillPath(&pgBrush, &path);
}
#include <math.h>
void FillHexagon(HDC hdc, RectF &rect) //
{
float radian = 3.1415926f / 180.0f;
float l = 50.0f, fh = l * sin(60.0f * radian);// x*(PI/180)=x
PointF pts[] = {PointF(50.0f, 0.0f), PointF(50.0f * 1.5f, 0.0f),
0.0f),PointF(50.0f / 2.0f, -fh), PointF(-50.0f / 2.0f, -fh),
PointF(-50.0f, 0.0f), PointF(-50.0f * 1.5f, 0.0f), PointF(-50.0f, 0.0f),
PointF(-50.0f / 2.0f, fh), PointF(50.0f / 2.0f, fh)};
PathGradientBrush pgBrush(pts, 10);
pgBrush.SetWrapMode(WrapModeTile); // _SetWrapMode???
Graphics graph(hdc);
pgBrush.SetCenterColor(Color::Red);
graph.FillRectangle(&pgBrush, rect);
graph.TranslateTransform(75.0f, fh);
pgBrush.SetCenterColor(Color::Green);
graph.FillRectangle(&pgBrush, -75.0f, -fh, rect.Width, rect.Height);
}
PointF(50.0f,
5
region
GDI
GDI+ Region
1
Region 6
Region(VOID); //
Region(const Rect &rect); //
Region(const RectF &rect); //
Region(const GraphicsPath *path); //
Region(const BYTE *regionData, INT size);//
Region(HRGN hRgn); // GDI
//
Region *Clone(VOID);
// region g
BOOL Equals(const Region *region, const Graphics *g) const; //
//
BOOL IsEmpty(const Graphics *g) const; // g
Status MakeEmpty(VOID); //
//
BOOL IsInfinite(const Graphics *g) const; // g
Status MakeInfinite(VOID); //
//
Status GetBounds(Rect *rect, const Graphics *g) const;//g
Status GetBounds(RectF *rect, const Graphics *g) const;
// // _???
UINT GetDataSize(VOID) const; //
Status GetData(BYTE *buffer,UINT bufferSize,UINT *sizeFilled=NULL) const;
//
UINT GetRegionScansCount(const Matrix *matrix) const;
Status GetRegionScans(const Matrix *matrix, Rect *rects, INT *count) const;
Status GetRegionScans(const Matrix *matrix, RectF *rects, INT *count) const;
//
Status Translate(INT dx, INT dy);
Status Translate(REAL dx, REAL dy);
//
Status Transform(const Matrix *matrix);
//
Status GetLastStatus(VOID); // Ok // Ok
// GDI
HRGN GetHRGN(const Graphics *g) const; // g
union
Status Union(const Region *region); //
Status Union(const Rect &rect); //
Status Union(const Rect &rect); //
Status Union(const GraphicsPath *path); //
intersect
Status Intersect(const Region *region); //
Status Intersect(const Rect &rect); //
Status Intersect(const Rect &rect); //
Status Intersect(const GraphicsPath *path); //
exclude // A.Exclude(B) B.Exclude(A)
Status Exclude(const Region *region); //
Status Exclude(const Rect &rect); //
Status Exclude(const Rect &rect); //
Status Exclude(const GraphicsPath *path); //
complement
Status Complement(const Region *region); //
Status Complement(const Rect &rect); //
Status Complement(const Rect &rect); //
Status Complement(const GraphicsPath *path); //
xor // _
Status Xor(const Region *region); //
Status Xor(const Rect &rect); //
Status Xor(const Rect &rect); //
Status Xor(const GraphicsPath *path); //
SolidBrush textBrush(Color::Black);
Font font(L"", 10.5);
StringFormat stringFormat;
stringFormat.SetAlignment(StringAlignmentCenter); // StringAlignment
Point points[] = {Point(100, 0), Point(122, 69), Point(195, 69), Point(137, 111), Point(159,
181), Point(100, 138), Point(41, 181), Point(63, 111), Point(5, 69), Point(78, 69)};
GraphicsPath path;
path.AddPolygon(points, 10);
Region *pRgn, rgnRect(Rect(0, 50, 200, 80));
SolidBrush *pBrush, gbrush(Color::Green), tbrush(Color::Turquoise);
CString strs[] = {L"", L"", L"", L"", L"", L""};
PointF pts[] = {PointF(0.0f, 0.0f), PointF(210.0f, 0.0f), PointF(210.0f, 0.0f),PointF(-420.0f,
220.0f), PointF(210.0f, 0.0f), PointF(210.0f, 0.0f)};
Graphics graph(pDC->m_hDC);
for (int i = 0; i < 6; i++) {
pRgn = new Region(&path);
switch (i) {
case 1: pRgn->Union(&rgnRect); break;
case 2: pRgn->Intersect(&rgnRect); break;
case 3: pRgn->Exclude(&rgnRect); break;
case 4: pRgn->Complement(&rgnRect); break;
case 5: pRgn->Xor(&rgnRect); break;
}
if (i == 0) pBrush = &gbrush; else pBrush = &tbrush;
graph.TranslateTransform(pts[i].X, pts[i].Y); //
graph.FillRegion(pBrush, pRgn);
if (i == 0) graph.FillRegion(&SolidBrush (Color(128, 255, 0, 0)), &rgnRect);
graph.DrawString(strs[i], -1, &font, PointF(100, 190), &stringFormat, &textBrush);
delete pRgn;
} // end_for
Bitmap bmp(L".bmp");
Graphics graph(pDC->m_hDC);
graph.DrawImage(&bmp, 0, 0);
int w = bmp.GetWidth(), h = bmp.GetHeight();
Region rgn(Rect(0, 0, w, h));
Color col, col0;
bmp.GetPixel(0, 0, &col0); // Image.GetPixel(x,y,&Color);
FillRegion 180*180
100KB
}// end_for(i)
graph.TranslateTransform(REAL(w), 0.0f);
graph.FillRegion(&SolidBrush(Color::Green), &rgn); //
4
// g
BOOL IsVisible(INT x, INT y, const Graphics *g) const; //
BOOL IsVisible(const Point &point, const Graphics *g) const; //
BOOL IsVisible(REAL x, REAL y, const Graphics *g) const; //
BOOL IsVisible(const PointF &point, const Graphics *g) const;//
// g
//
BOOL IsVisible(INT x, INT y, INT width, INT height, const Graphics *g) const;
BOOL IsVisible(const Rect &rect, const Graphics *g) const; //
//
BOOL IsVisible(REAL x, REAL y, REAL width, REAL height, const Graphics *g) const;
BOOL IsVisible(const RectF &rect, const Graphics *g) const; //
//
class CGdipDrawView : public CView {
Region *pRgn;
}
//
void CGdipDrawView::OnInitialUpdate() {
CView::OnInitialUpdate();
FontFamily ff(L"");
GraphicsPath path;
path.AddString(L"",-1,&ff,FontStyleRegular,150,Point(0,0), NULL);
pRgn = new Region(&path);
}
// OnDraw
void CGdipDrawView::OnDraw(CDC* pDC) {
Graphics graph(pDC->m_hDC);
graph.FillRegion(&SolidBrush(Color::Green), pRgn);
}
//
void CGdipDrawView::OnLButtonUp(UINT nFlags, CPoint point) {
// TODO: /
if(pRgn->IsVisible(point.x, point.y)) MessageBox(L"");
else MessageBox(L"");
}
//
CGdipDrawView::~CGdipDrawView() {
delete pRgn;
}
// _9_3_2
6
transform GDI+
1 TranslateTransform
(x, y)(dx, dy)
Status TranslateTransform(REAL dx, REAL dy, MatrixOrder order = MatrixOrderPrepend);
x = x + dx
y = y + dy
x' x d x
= +
y' y d y
x' 1 0
y' = 0 1
1 0 0
d x x
d y y
1 1
Graphics graph(pDC->m_hDC);
RedrawWindows(); //
Rect rectSquare(10, 10, 100, 100), rectCircle(120, 10, 100, 100);
graph.DrawRectangle(&Pen(Color::Green), rectSquare);
graph.DrawEllipse(&Pen(Color::Green), rectCircle);
graph.TranslateTransform(30, 20);
graph.DrawRectangle(&Pen(Color::Red), rectSquare);
graph.DrawEllipse(&Pen(Color::Red), rectCircle);
(30, 20)
2 RotateTransform
(x, y) [ ] =
angle
Status RotateTransform(REAL angle, MatrixOrder order = MatrixOrderPrepend);
(x,y)
(x,y)
Set =len,
lencos(a+b) = x; len(cosacosb-sinasinb) = x;
lencosb cosa - lensinbsina = x; xcosa - ysina = x;
y
x = x*cos- y*sin
y = x*sin+ y*cos
y'
=
cos
sin
y
Graphics graph(pDC->m_hDC);
Rect rectSquare(80, 10, 100, 100), rectCircle(190, 10, 100, 100);
graph.DrawRectangle(&Pen(Color::Green), rectSquare);
graph.DrawEllipse(&Pen(Color::Green), rectCircle);
graph.RotateTransform(30.0f);
graph.DrawRectangle(&Pen(Color::Red), rectSquare);
graph.DrawEllipse(&Pen(Color::Red), rectCircle);
30
// TranslateTransform
Graphics graph(pDC->m_hDC);
CRect crect;
GetClientRect(&crect);
PointF cp(REAL(crect.CenterPoint().x), REAL(crect.CenterPoint().y));
Font font(L"", 14);
SolidBrush textBrush(Color::Red);
StringFormat stringFormat;
stringFormat.SetLineAlignment(StringAlignmentCenter);
graph.TranslateTransform(cp.X, cp.Y); //
for (int i = 0; i < 360; i += 30) {
graph.RotateTransform(REAL(i)); //
graph.DrawString(L"", -1, &font, PointF(20.0f, 0.0f),
&stringFormat, &textBrush);
graph.RotateTransform(REAL(-i)); //
}
3 ScaleTransform
x y sx sy
// x,y
Status ScaleTransform(REAL sx, REAL sy, MatrixOrder order = MatrixOrderPrepend);
x = sx*x
y = sy*y
x' s x
=
y' 0
0 x
s y y
x ' sx
y ' = 0
1 0
0
sy
0
0 x
0 y
1
1
Graphics graph(pDC->m_hDC);
Rect rectSquare(10, 10, 100, 100), rectCircle(120, 10, 100, 100);
graph.DrawRectangle(&Pen(Color::Green), rectSquare);
graph.DrawEllipse(&Pen(Color::Green), rectCircle);
graph.ScaleTransform(1.5f, 0.5f);
graph.DrawRectangle(&Pen(Color::Red), rectSquare);
graph.DrawEllipse(&Pen(Color::Red), rectCircle);
(1.5, 0.5)
Graphics graph(pDC->m_hDC);
Font font(L"", 50, FontStyleRegular, UnitPixel),
ifont(L"", 50, FontStyleItalic, UnitPixel);
SolidBrush textBrush(Color::Blue), mirrorBrush(Color::Gray);
CString str(L""); //
graph.DrawString(str, str.GetLength(), &font, PointF(200.0f, 10.0f), &textBrush);
//
graph.ScaleTransform(1, -1);
graph.TranslateTransform(0, -120);
graph.DrawString(str, str.GetLength(), &ifont, PointF(200.0f, 10.0f), &mirrorBrush);
graph.ResetTransform(); // _???//
//
graph.ScaleTransform(-1, 1);
graph.TranslateTransform(-220, 0);
graph.DrawString(str, str.GetLength(), &font, PointF(0.0f, 10.0f), &mirrorBrush);
// +
graph.ResetTransform();
graph.ScaleTransform(-1, -1);
graph.TranslateTransform(-220, -120);
graph.DrawString(str, str.GetLength(), &ifont, PointF(0.0f, 10.0f), &mirrorBrush);
Graphics graph(pDC->m_hDC);
Image img(L".bmp");
REAL w = REAL(img.GetWidth()), h = REAL(img.GetHeight());
graph.DrawImage(&img, PointF(w, 0));
graph.ScaleTransform(1, -1);
graph.TranslateTransform(0, -2 * h);
graph.DrawImage(&img, PointF(w, 0));
graph.ResetTransform();
graph.ScaleTransform(-1, 1);
graph.TranslateTransform(-w, 0);
graph.DrawImage(&img, PointF(0, 0));
graph.ResetTransform();
graph.ScaleTransform(-1, -1);
graph.TranslateTransform(-w, -2 * h);
graph.DrawImage(&img, PointF(0, 0));
4
3
x = x*cos- y*sin
y = x*sin+ y*cos
x = sx*x
y = sy*y
s
cos
y
y
sin x
cos y
x" s x
y" = 0
1 0
0
sy
0
s x cos
= s y sin
0 x ' s x
0 y ' = 0
1
1 0
s x sin
s y cos
0
0
sy
0
0 cos
0 sin
1
0
sin
cos
0
0 x
0 y
1
1
GDI+
sx 0
cos
= ( x y 1) sin
0
0
1
sin 0 s x 0 0
cos 0 0 s y 0
0 1 0 0 1
s x cos s y sin 0
= ( x y 1) s x sin s y cos 0
0
0
1
Graphics graph(pDC->m_hDC);
Rect rectSquare(30, 10, 100, 100), rectCircle(140, 10, 100, 100);
graph.DrawRectangle(&Pen(Color::Green), rectSquare);
graph.DrawEllipse(&Pen(Color::Green), rectCircle);
graph.ScaleTransform(1.5f, 0.5f);
graph.RotateTransform(30.0f); //
// A= RSA // _
graph.DrawRectangle(&Pen(Color::Red), rectSquare);
graph.DrawEllipse(&Pen(Color::Red), rectCircle);
30 (1.5, 0.5)
x = sx*x
y = sy*y
x = x*cos- y*sin
y = x*sin+ y*cos
0 x
0 y
1
1
x" cos
y" = sin
1 0
sin
s x cos
= s x sin
cos
0
0 x' cos
0 y ' = sin
1
1 0
s y sin
s y cos
0
sin
cos
0
0 s x
0 0
1
0
0
sy
0
0 x
0 y
1
1
0 x
0 y
1
1
Graphics graph(pDC->m_hDC);
Rect rectSquare(80, 10, 100, 100), rectCircle(190, 10, 100, 100);
graph.DrawRectangle(&Pen(Color::Green), rectSquare);
graph.DrawEllipse(&Pen(Color::Green), rectCircle);
graph.RotateTransform(30.0f); // MatrixOrderPrepend
graph.ScaleTransform(1.5f, 0.5f); // MatrixOrderPrepend
// A= SRA // _
graph.DrawRectangle(&Pen(Color::Red), rectSquare);
graph.DrawEllipse(&Pen(Color::Red), rectCircle);
(1.5, 0.5) 30
Graphics graph(pDC->m_hDC);
CRect crect;
GetClientRect(&crect); //
PointF cp(REAL(crect.CenterPoint().x), REAL(crect.CenterPoint().y)); //
RectF rect(cp.X - 10.0f, cp.Y - 10.0f, 20.0f, 20.0f); //
REAL scale = 1.0f; //
// REAL scale = 0.0f, ds = 10.0f; //
for (int i = 0; i <= 360; i += 20) { //
graph.TranslateTransform(cp.X, cp.Y); //
//rect.Inflate(scale * ds, scale * ds); //
graph.ScaleTransform(scale, scale); //
graph.RotateTransform(REAL(i)); //
graph.TranslateTransform(-cp.X, -cp.Y); //
graph.DrawRectangle(&Pen(Color::Green), rect); //
SDK Sleep
VOID Sleep(DWORD dwMilliseconds);
dwMilliseconds
//graph.ScaleTransform(scale, scale);
inflate
rRect.Inflate(scale * ds, scale * ds);
Rect RectF Inflate
VOID Inflate(INT dx, INT dy);
VOID Inflate(const Point& point);
VOID Inflate(REAL dx, REAL dy);
VOID Inflate(const PointF& point);
dx dy
// ScaleTransform Inflate
5
3
Status SetTransform(const Matrix *matrix); // matrix
Status ResetTransform(VOID); //
// _ Graphics translate(),rotate()
scale()
Graphics graph(pDC->m_hDC);
REAL radian = 3.1415926f / 180.0f;
Rect rectSquare(80/*30*/, 10, 100, 100), rectCircle(190/*140*/, 10, 100, 100);
REAL sx = 1.5f, sy = 0.5f, a = 30.0f;
REAL m11 = sx * cos(a * radian), m12 = sy /*-sx*/* sin(a * radian),
m21 = -sx/*sy*/ * sin(a * radian), m22 = sy * cos(a * radian),
m31 = 0.0f, m32 = 0.0f;
Matrix m(m11, m12, m21, m22, m31, m32); //
graph.DrawRectangle(&Pen(Color::Green), rectSquare);
graph.DrawEllipse(&Pen(Color::Green), rectCircle);
graph.SetTransform(&m); // matrix
graph.DrawRectangle(&Pen(Color::Red), rectSquare);
graph.DrawEllipse(&Pen(Color::Red), rectCircle);
30 +(1.5, 0.5)
rectSquare X 30rectCircle X 140m12 sy sxm21 -sx sy
(1.5, 0.5)+ 30
2
2
GDI+ Matrix
( x'
y ' 1) = ( x
s x cos
y 1) s y sin
dx
s x sin
s y cos
dy
0
1
A = B gC A = (B gC ) = C gB _
x' s x cos
y ' = s x sin
1 0
s y sin
s y cos
0
d x x
d y y
1 1
y ' s x sin s y cos y d y
(30, 60)
30
1 Matrix
Matrix 4
Matrix(VOID); //
Matrix(const RectF &rect, const PointF *dstplg);
Matrix(const Rect &rect, const Point *dstplg);
Matrix(REAL m11, REAL m12, REAL m21, REAL m22, REAL dx, REAL dy);
1 0 0
M = 0 1 0 = M T
0 0 1
rect.Y
0
rect . X
rect. X
T
M = rect.Width rect.Height 0 M = rect.Y
dstplg.X
0
dstplg.Y
1
rect.Width dstplg.X
rect.Height dstplg.Y
0
1
m11
M = m 21
dx
GDI+
( x'
y ' 1) = ( x
m12
m 22
dy
0
m11
T
0 M = m12
0
1
m 21
m 22
0
dx
dy
1
y 1) M // __GDI +
=( x
rect.Y
0
rect. X
y 1) rect.Width rect.Height 0
dstplg.X
dstplg.Y
1
=( x
m11 m12 0
y 1) m21 m22 0 //
dx
dy 1
( x'
y ' 1)
x'
x
T
= [( x y 1) M ] <==> y ' = M y
1
1
rect. X rect.Width dstplg.X x
= rect.Y rect.Height dstplg.Y y
0
1
0
1
m11 m21 dx x
= m12 m22 dy y
0
0
1
( x'
y ') = ( x
= (x
= (x
= (x
y 1) M 32
rect.Y
rect.X
y 1) rect.Width rect.Height
dstplg.X
dstplg.Y
m11 m12
y 1) m 21 m 22
dx
dy
s x cos
y 1) s y sin
d
x
s x sin
s y cos
d y
m11 = s x cos ,
m12 = s x sin
m 21 = s y sin , m 22 = s y cos
m12
m11
m 21
s y = m 21 2 + m22 2 , = tg 1
m 22
s x = m11 2 + m12 2 , = tg 1
2
Matrix
Matrix *Clone(VOID); // Clone
static BOOL Equals(const Matrix* matrix); //
Status GetElements(REAL *m) const; // m11~m32
Status GetLastStatus(VOID); //
Status Invert(VOID); //
BOOL IsIdentity(VOID); //
BOOL IsInvertible(VOID); //
//
Status Multiply(const Matrix *matrix, MatrixOrder order = MatrixOrderPrepend);
REAL OffsetX(VOID); // x x dx()
REAL OffsetY(VOID); // y y dy
Status Reset(VOID); //
Status Rotate(REAL angle, MatrixOrder order = MatrixOrderPrepend);//
Status RotateAt(REAL angle, const PointF ¢er, //
rect.Width rect.Height 0 = m 21 m 22 0
dstplg.X
dx
dstp
lg
.
Y
1
dy
1
//
Status Shear(REAL shearX, REAL shearY, MatrixOrder order = MatrixOrderPrepend); //
shear
Status TransformPoints(Point *pts, INT count = 1); // ??
Status TransformPoints(PointF *pts, INT count = 1); //
Status TransformVectors(Point *pts, INT count = 1); //
Status TransformVectors(PointF *pts, INT count = 1);//
Status Translate(REAL offsetX, REAL offsetY, MatrixOrder order = MatrixOrderPrepend); //
// shear
//
Status Shear(REAL shearX, REAL shearY, MatrixOrder order= MatrixOrderPrepend);
Shear/
S = shearX
0
shearY
1
0
( x'
shearY
1
y ') = ( x y 1) S = ( x y 1) shearX
1
0
0
= ( x + y shearX y + x shearY ) //
Graphics graph(pDC->m_hDC);
SolidBrush brush(Color::Green);
Rect rect(0, 0, 100, 100);
graph.FillRectangle(&SolidBrush(Color::Green), rect);
Matrix M;
M.Shear(1, 0.5f);
graph.SetTransform(&M);
graph.FillRectangle(&SolidBrush(Color(128, 255, 0, 0)), rect);
M.Reset();
M.Shear(0.5f, 1);
graph.SetTransform(&M);
graph.FillRectangle(&SolidBrush(Color(128, 0, 0, 255)), rect);
M.Reset();
M.Shear(2, 1);
graph.SetTransform(&M);
graph.FillRectangle(&SolidBrush(Color(128, 255, 0, 255)), rect);
M.Reset();
M.Shear(1, 2);
graph.SetTransform(&M);
graph.FillRectangle(&SolidBrush(Color(128, 0, 255, 255)), rect);
-(1, 0.5)-(0.5, 1)-(2, 1)-(1, 2)
Graphics graph(pDC->m_hDC);
SolidBrush grayBrush(Color::Gray), redBrush(Color::Red);
Font font(L"", 150, FontStyleRegular, UnitPixel);
Matrix M;
M.Shear(1.5f, 0.0f);
M.Scale(0.97f, 0.5f);
graph.SetTransform(&M);
graph.DrawString(L"", -1, &font, PointF(-168, 142), &grayBrush);
graph.ResetTransform();
graph.DrawString(L"", -1, &font, PointF(50, 0), &redBrush);
4
TransformPoints TransformVectors
m11 m12
Graphics graph(pDC->m_hDC);
int n = 5;
Point pts[] = {Point(100, 0), Point(159, 181), Point(5, 69), Point(195, 69), Point(41, 181)};
graph.DrawPolygon(&Pen(Color::Green), pts, n); // polygon
Matrix M;
M.Scale(1.5f, 0.5f); //
M.TransformPoints(pts, n);
Graphics graph(pDC->m_hDC);
Pen pen(Color::Green, 4);
pen.SetAlignment(PenAlignmentInset); //
CRect crect;
GetClientRect(&crect); // CRectx,y RectX,Y.
PointF cp(REAL(crect.CenterPoint().x), REAL(crect.CenterPoint().y));
INT w = min(crect.Width(), crect.Height()), h = w / 4;
Rect rect(INT(cp.X) - w / 2, INT(cp.Y) - h / 2, w, h);
Matrix M;
for (int i = 0; i < 180; i += 30/*45*/) {
M.RotateAt(REAL(i), cp);
graph.SetTransform(&M);
graph.DrawEllipse(&pen, rect);
M.Reset();
}
SDK
void GetLocalTime(LPSYSTEMTIME lpSystemTime);
SYSTEMTIME
SYSTEMTIME
typedef struct _SYSTEMTIME {
WORD wYear; // 1601~30827
WORD wMonth; // 1~12
WORD wDayOfWeek; // 0~6 0
WORD wDay; // 1~31
WORD wHour; // 0~23
WORD wMinute; // 0~59
WORD wSecond; // 0~59
WORD wMilliseconds; // 0~999
} SYSTEMTIME; // _system_time
//
CPaintDC dc(this); // CDC
Graphics graph(dc.m_hDC); // CPaintDC.m_hDC;
//graph.SetSmoothingMode(SmoothingModeAntiAlias);
graph.TranslateTransform(cp.X, cp.Y);
graph.FillEllipse(pEraseBrush, *pOutCircleRect);
graph.DrawEllipse(&Pen(Color::Black, 2), *pInCircleRect);
graph.DrawEllipse(&Pen(Color::Black, 2), *pOutCircleRect);
graph.ResetTransform();
Matrix M;
for (int i = 0; i < 360; i += 6) {
M.RotateAt(REAL(i), cp);
graph.SetTransform(&M);
graph.TranslateTransform(cp.X, cp.Y);
if (i % 30) graph.DrawLine(p1mPen, r - dm, 0.0f, r, 0.0f);
else graph.DrawLine(p5mPen, r - d5m, 0.0f, r, 0.0f);
M.Reset();
}
Click.wav SDK
BOOL PlaySound(LPCSTR pszSound, HMODULE hmod, DWORD fdwSound);
IDR_CLICK_WAVE ID
PlaySound(MAKEINTRESOURCE(IDR_CLICK_WAVE), // make_int_resource
AfxGetInstanceHandle(), SND_RESOURCE);
PlaySound
#include <mmsystem.h>
winmm.lib GDI+
3 s
GraphicsPath
Status Transform(const Matrix *matrix);
GraphicsPath path; //
path.AddString(L"", -1, //
&FontFamily(L""), FontStyleRegular, 100, Point(0, 0), NULL);
RectF boundRect;
path.GetBounds(&boundRect); //
Matrix M; //
M.Translate(-(boundRect.X + boundRect.Width / 2),
-(boundRect.Y + boundRect.Height / 2)); //
path.Transform(&M); //
INT n = path.GetPointCount(); //
PointF *points = new PointF[n]; //
path.GetPathPoints(points, n); //
BYTE *types = new BYTE[n]; //
path.GetPathTypes(types, n); //
for (int i= 0; i < n; i++) // , y
points[i].Y *= 2*(boundRect.Width-abs(points[i].X))/boundRect.Width;
GraphicsPath newPath(points, types, n); //
CRect crect;
GetClientRect(&crect); // CRect
Graphics graph(pDC->m_hDC); //
graph.TranslateTransform(REAL(crect.Width()/2),REAL(crect.Height()/2));
graph.FillPath(&SolidBrush(Color::Green), &newPath);//
delete points; // _add
delete types; // _add
4
TextureBrush PathGradientBrush
7
GDI+ 9 Windows
BMPBitMaP.BMP Microsoft IBM 1980 Windows PS/2
1 4816243264 24
GIFGraphics Interchange Format.GIF CompuServe
1987 LZW 256
64K*64K
JPEGJoint Photographic Experts Group.JPG
ISO IEC 1991 DCT
HuffmanLZWRLE
ICONicon.ico Microsoft IBM 1980 Windows PS/2
16*1632*32 54*64
WMFWindows MetaFile.WMF Microsoft IBM 1980
Windows PS/2 GDI
EMFEnhanced Windows MetaFile.EMF 1993
32 Windws NT WMF Win32GDI+ EMF
EMF+
GDI+
GDI+ Effect 11
7
1 Image
Image
1
Image
Image(const WCHAR *filename, BOOL useEmbeddedColorManagement = FALSE);
Image(IStream *stream, BOOL useEmbeddedColorManagement = FALSE);
FALSE
Image img(L".bmp"));
2
Image
UINT GetHeight(VOID); //
UINT GetWidth(VOID); //
ImageType GetType(VOID); //
Status GetRawFormat(GUID *format); //
UINT GetFlags(VOID); // _???
Status GetLastStatus(VOID); //
Image *Clone(VOID); //
static Image *FromFile(const WCHAR *filename, //
BOOL useEmbeddedColorManagement = FALSE);
Status Save(const WCHAR *filename, const CLSID *clsidEncoder???,
const EncoderParameters *encoderParams = NULL); //
3
Image GetType
ImageType GetType(VOID); //
ImageType
typedef enum {
ImageTypeUnknown = 0, //
ImageTypeBitmap = 1, //
ImageTypeMetafile = 2 //
} ImageType;
Image GetRawFormat
Status GetRawFormat(GUID *format); //
GUIDglobally unique identifier
typedef struct _GUID {
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[8];
} GUID;
(11 )
ImageFormatBMP
BMPBitMaP
ImageFormatEMF
EMFEnhanced MetaFile
ImageFormatEXIF
ExifExchangeable Image File
ImageFormatGIF
GIFGraphics Interchange Format
ImageFormatIcon
Icon
JPEGJoint Photographic Experts Group
ImageFormatJPEG
ImageFormatMemo
ryBMP
ImageFormatPNG
PNGPortable Network Graphics
ImageFormatTIFF
TIFFTagged Image File Format
ImageFormatUndefi
ned
ImageFormatWMF
WMFWindows Metafile Format
JPEG GUID {B96B3CAE-0728-11D3-9D7B-0000F81EF32E}????
Image img(ar.GetFile()->GetFilePath());
GUID guid;
img.GetRawFormat(&guid); // GUID
if(guid == ImageFormatJPEG) MessageBox(L"The format is JPEG.");
Image GetFlags
UINT GetFlags(VOID);
ImageFlags
typedef enum {
ImageFlagsNone = 0, //
ImageFlagsScalable = 0x0001, //
ImageFlagsHasAlpha = 0x0002, //
ImageFlagsHasTranslucent = 0x0004, //
ImageFlagsPartiallyScalable = 0x0008, //
ImageFlagsColorSpaceRGB = 0x0010, // RGB
ImageFlagsColorSpaceCMYK = 0x0020, // CMYK
ImageFlagsColorSpaceGRAY = 0x0040, //
ImageFlagsColorSpaceYCBCR = 0x0080, // YCbCr
ImageFlagsColorSpaceYCCK = 0x0100, // YCCK
ImageFlagsHasRealDPI = 0x1000, // DPIdots per inch
ImageFlagsHasRealPixelSize = 0x2000, //
ImageFlagsReadOnly = 0x00010000, //
ImageFlagsCaching = 0x00020000 //
} ImageFlags;
1
GDI+
//
Status GetImageEncodersSize(UINT *numEncoders, UINT *size);
//
Status GetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders);
//
Status GetImageDecodersSize(UINT *numDecoders, UINT *size);
//
Status GetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders);
ImageCodecInfo
Clsid
CLSID
FormatID
GUID
CodecName
WCHAR
*
DllName
WCHAR
DLL
*
FormatDescripti
WCHAR
on
*
FilenameExtensi WCHAR
on
*
MimeType
WCHAR
MIME
*
Flags
DWORD ImageCodecFlags
Version
DWORD
SigCount
DWORD
SigSize
DWORD
SigPattern
BYTE *
SigMask
BYTE *
void CImgProcView::OnCodecInfo()
{
Graphics graph(GetDC()->m_hDC);
RedrawWindow();
SolidBrush brush(Color::Green);
Font font(L"", 12);
UINT n, size;
ImageCodecInfo *codecInfos;
GetImageEncodersSize(&n, &size); // GDI+
codecInfos = (ImageCodecInfo *)malloc(size);
GetImageEncoders(n, size, codecInfos);
CString str = L"\t\t \t ";
graph.DrawString(str, str.GetLength(), &font, PointF(10, 10), &brush);
for (UINT i = 0; i < n; i++) {
str.Format(L"%s\t %s\t\t%s", codecInfos[i].CodecName,
codecInfos[i].FormatDescription, codecInfos[i].FilenameExtension);
graph.DrawString(str, str.GetLength(), &font, PointF(10, 40 + 30 * REAL(i)), &brush);
}
free(codecInfos);
}
Image
//
UINT GetEncoderParameterListSize(const CLSID *clsidEncoder);
Status GetEncoderParameterList(const CLSID *clsidEncoder, UINT size,
EncoderParameters *buffer); //
EncoderParameters
UINT Count; // Number of EncoderParameter objects in the array.
EncoderParameter Parameter[l]; // Array of EncoderParameter objects.
EncoderParameter 4
GUID Guid; // Identifies the parameter category.
ULONG NumberOfValues; // Number of values in the array pointed to by the Value data member.
ULONG Type; // Identifies the data type of the parameter.
VOID *Value; // Pointer to an array of values.
Image Save
Status Save(const WCHAR *filename, const CLSID *clsidEncoder,
const EncoderParameters *encoderParams = NULL);
Status Save(IStream *stream, const CLSID *clsidEncoder,
const EncoderParameters *encoderParams = NULL);
CLSID ID
fileName
CString
void CImgProcDoc::OnFileSaveAs() {
if (ok) {
wchar_t filters[] = L"(*.bmp;*.gif;*.jpg;*.png;*.tif;*.emf)|*.bmp;*.gif;*.jpg;\
*.png;*.tif;*.emf|(*.bmp)|*.bmp|(*.gif)|*.gif|\
[JPEG](*.jpg)|*.jpg|(*.png)|*.png|[TIFF]\
(*.tif)|*.tif|(*.emf)|*.emf|(*.*)|*.*||";
CFileDialog fileDlg(FALSE, NULL, fileName, OFN_HIDEREADONLY, filters);
if (fileDlg.DoModal() == IDOK) {
CString extStr = fileDlg.GetFileExt(); //
extStr.MakeUpper(); // CString.MakeUpper()
//
if (extStr.Compare(L"JPG") == 0) extStr = L"JPEG";
else if (extStr.Compare(L"TIF") == 0) extStr = L"TIFF";
CLSID clsid;
if (GetEncoderClassID(extStr, &clsid)) { //
pImg->Save(fileDlg.GetPathName(), &clsid, NULL);
if (pImg->GetLastStatus() != Ok)
MessageBox(NULL, L"", L"", MB_OK);
}
else MessageBox(NULL, L"", L"", MB_OK);
}
}
ID_FILE_SAVE_AS
ON_COMMAND(ID_FILE_SAVE_AS, &CImgProcDoc::OnFileSaveAs)
ON_COMMAND(ID_FILE_SAVE, &CImgProcDoc::OnFileSaveAs)
3 Bitmap
Bitmap Metafile Image
1
Bitmap 10
Bitmap(const WCHAR *filename, BOOL useIcm = FALSE);
Bitmap(INT width, INT height, PixelFormat format = PixelFormat32bppARGB);
Bitmap(INT width, INT height, Grpaphics *target);
PixelFormat
(14 )
PixelFormat1bppIndexe 1
d
PixelFormat4bppIndexed 4
PixelFormat8bppIndexed 8
PixelFormat16bppARGB1 16 1 RGB 5
555
PixelFormat16bppGraySc 16
ale
PixelFormat16bppRGB55 16 RGB 5 1
5
PixelFormat16bppRGB56 16 RB 5 G 6
5
PixelFormat24bppRGB
24 RGB 8
PixelFormat32bppARGB
32 RGB 8
PixelFormat32bppPARGB 32 RGB 8 RGB
PixelFormat32bppRGB
24 RGB 8 8
PixelFormat48bppRGB
PixelFormat64bppARGB
PixelFormat64bppPARGB
48 RGB 16
64 RGB 16
64 RGB 16 RGB
Bitmap
//
Bitmap *Clone(INT x, INT y, INT width, INT height, PixelFormat format);
Bitmap *Clone(const Rect &rect, PixelFormat format);
Bitmap *Clone(REAL x, REAL y, REAL width, REAL height, PixelFormat format);
Bitmap *Clone(const RectF &rect, PixelFormat format);
//
static Bitmap *FromBITMAPINFO(const BITMAPINFO *gdiBitmapInfo, VOID *gdiBitmapData);
static Bitmap *FromDirectDrawSurface7(IDirectDrawSurface7* surface);
static Bitmap *FromFile(const WCHAR *filename, BOOL useEmbeddedColorManagement = FALSE);
static Bitmap *FromHBITMAP(HBITMAP hbm, HPALETTE hpal);
static Bitmap *FromHICON(HICON hicon);
static Bitmap *FromResource(HINSTANCE hInstance, const WCHAR *bitmapName);
static Bitmap *FromStream(IStream *stream, BOOL useEmbeddedColorManagement);
//
Status GetHBITMAP(const Color &colorBackground, HBITMAP *hbmReturn);
Status GetHICON(HICON *hicon);
// //
Status GetPixel(INT x, INT y, Color *color); //
Status SetPixel(INT x, INT y, const Color &color);
//
Status SetResolution(REAL xdpi, REAL ydpi); // _???
Status LockBits(const Rect *rect, UINT flags, PixelFormat format, BitmapData *lockedBitmapData);
Status UnlockBits(BitmapData *lockedBitmapData);
4
1
Graphics 18 4
// (x,y)
Status DrawImage(Image *image, INT x, INT y); //
Status DrawImage(Image *image, const Point &point); //
Status DrawImage(Image *image, INT x, INT y, INT width, INT height); //
Status DrawImage(Image *image, const Rect &rect); //
Graphics graph(pDC->m_hDC);
Image img(L".bmp"));
graph.DrawImage(&img, 0, 0); // (x,y)
Graphics graph(pDC->m_hDC);
Image img(L".bmp"));
CRect rect;
GetClientRect(&rect); // CRect.Width() CRect.Height()
graph.DrawImage(&img, 0, 0, rect.Width(), rect.Height()); //
2
Graphics
Status DrawImage(Image *image, INT x, INT y, INT width, INT height);
Status DrawImage(Image *image, const Rect &rect);
Graphics graph(pDC->m_hDC);
Image img(L".bmp"));
CRect rect;
GetClientRect(&rect);
graph.DrawImage(&img, 0, 0, rect.Width(), rect.Height());
[] zoomMultiple
Graphics graph(pDC->m_hDC);
Image img(L".bmp"));
graph.DrawImage(&img, 0.0f, 0.0f, zoomMultiple * img.GetWidth(),
zoomMultiple * img.GetHeight());
[]zoomMultiple = 1.5
Graphics //interpolation ,,
Status SetInterpolationMode(InterpolationMode interpolationMode);
InterpolationMode
typedef enum {
InterpolationModeInvalid = QualityModeInvalid, //
InterpolationModeDefault = QualityModeDefault, //
InterpolationModeLowQuality = QualityModeLow, //
InterpolationModeHighQuality = QualityModeHigh, //
InterpolationModeBilinear = QualityModeHigh + 1, //
InterpolationModeBicubic = QualityModeHigh + 2, //
InterpolationModeNearestNeighbor = QualityModeHigh + 3,//
InterpolationModeHighQualityBilinear=QualityModeHigh+4,//
InterpolationModeHighQualityBicubic = QualityModeHigh+5//
} InterpolationMode;
Graphics graph(pDC->m_hDC);
Image img(L".bmp"));
// InterpolationMode::InterpolationNearestNeighbor _test?
//graph.SetInterpolationMode(InterpolationModeNearestNeighbor);
//graph.SetInterpolationMode(InterpolationModeBilinear);
graph.SetInterpolationMode(InterpolationModeHighQualityBilinear);
graph.DrawImage(&img, 0.0f, 0.0f, 3.23f *img.GetWidth(), 3.23f * img.GetHeight());
3
Graphics
// (x,y), (srcx,srcy)
srcwidth srcheight
Status DrawImage(Image *image, INT x, INT y, INT srcx, INT srcy,
INT srcwidth, INT srcheight, Unit srcUnit); //
Status DrawImage(Image *image, REAL x, REAL y, REAL srcx, REAL srcy,
REAL srcwidth, REAL srcheight, Unit srcUnit); //
Status DrawImage(Image* image, const RectF& destRect, REAL srcx, REAL srcy, REAL
srcwidth, REAL srcheight, Unit srcUnit, const ImageAttributes* imageAttributes =
NULL, DrawImageAbort callback = NULL, VOID* callbackData = NULL); //
// //
Status DrawImage(Image *image, RectF &destRect, RectF &sourceRect,
Unit srcUnit, ImageAttributes *imageAttributes = NULL);
cxcycwch zoomMultiple
Graphics graph(pDC->m_hDC);
Image img(L".bmp"));
// unit_pixel
graph.DrawImage(&img, 0, 0, cx, cy, cw, ch, UnitPixel); //
CRect rect;
GetClientRect(&rect);
//
graph.DrawImage(&img, RectF(0, 0, REAL(rect.Width()), REAL(rect.Height())),REAL(cx),
REAL(cy), REAL(cw), REAL(ch), UnitPixel); //
graph.DrawImage(&img, RectF(0, 0, zoomMultiple * cw, zoomMultiple * ch),
REAL(cx), REAL(cy), REAL(cw), REAL(ch), UnitPixel);
10
4 // _9_5
Image //
Status RotateFlip(RotateFlipType rotateFlipType); // flip ,
RotateFlipType
typedef enum {
RotateNoneFlipNone = 0, //
Rotate90FlipNone = 1, // 90
Rotate180FlipNone = 2, // 180
Rotate270FlipNone = 3, // 270
RotateNoneFlipX = 4, // x
Rotate90FlipX = 5, // 90 x
Rotate180FlipX = 6, // 180 x
Rotate270FlipX = 7, // 270 x
RotateNoneFlipY = Rotate180FlipX, // y
RotateNoneFlipY = Rotate270FlipX, // 90 y
Rotate180FlipY = RotateNoneFlipX, // 180 y
Rotate270FlipY = Rotate90FlipX, // 270 y
RotateNoneFlipXY = Rotate180FlipNone, // xy
Rotate90FlipXY = Rotate270FlipNone, // 90 xy
Rotate180FlipXY = RotateNoneFlipNone, // 180 xy
Rotate270FlipXY = Rotate90FlipNone // 270 xy
} RotateFlipType;
RotateNoneFlipNone
Rotate180FlipXY
RotateNoneFlipX
Rotate180FlipY
Rotate90FlipX
Rotate270FlipY
Rotate180FlipX
Rotate270FlipX
RotateNoneFlipY
RotateNoneFlipY
// RotateNoneFilpX Rotate180FilpY
// ___rotate_flip
Graphics graph(pDC->m_hDC);
Image img(L"yyy.emf");
img.RotateFlip(RotateFlipType::Rotate270FlipNone); // ::
graph.DrawImage(&img, 0, 0);
270
90 270
5
Graphics
Status DrawImage(Image *image, const Point *destPoints, INT count);
Status DrawImage(Image *image, const PointF *destPoints, INT count);
//
count 3destPoints 3
Graphics graph(GetDC()->m_hDC);
Image img1(L".bmp"), img2(L".bmp"), img3(L".bmp");
int d = 10, dx = (2 * img1.GetWidth())/3, dy = img3.GetHeight()/2;
6
GIF TIFF Image
UINT GetFrameDimensionsCount(VOID); //
Status GetFrameDimensionsList(GUID *dimensionIDs, UINT count); //
UINT GetFrameCount(const GUID *dimensionID); //
Status SelectActiveFrame(const GUID *dimensionID, UINT frameIndex); //
// (frame dimension count)(frame count)
UINT cf = 0, fn, dn;
//
dn = pImg->GetFrameDimensionsCount(); // Image *pImg;
guids = new GUID[dn]; // delete guids;
pImg->GetFrameDimensionsList(guids, dn);
fn = pImg->GetFrameCount(&guids[0]); //
if (fn < 2) { // res\Images globe.gif GIF
MessageBox(L"");
return;
}
SetTimer(1, 100, NULL); // ()
//
pImg->SelectActiveFrame(guids, cf);
Graphics graph(GetDC()->m_hDC);
graph.DrawImage(pImg, 0, 0);
cf++;
cf %= fn;
Image SaveAdd Save
Status SaveAdd(Image *newImage, const EncoderParameters *encoderParams);
Status SaveAdd(const EncoderParameters* encoderParams);
// GIF TIFF
TIFF [GIF ]
EncoderParameters encoderParameters; //
ULONG parameterValue; //
encoderParameters.Count = 1; //
encoderParameters.Parameter[0].Guid = EncoderSaveFlag; // ???
// Parameter
encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParameters.Parameter[0].NumberOfValues = 1; //
encoderParameters.Parameter[0].Value = ¶meterValue; //
Bitmap mimg(L"Duke\\T1.BMP"); //
CLSID clsid; // ID CLSID = class_id
// GetDocument()???
if (GetDocument()->GetEncoderClassID(L"TIFF", &clsid)) { // ID
parameterValue = EncoderValueMultiFrame; //
mimg.Save(L"Duke.tif", &clsid, &encoderParameters); //
if (mimg.GetLastStatus() != Ok) { //
MessageBox(L"");
return;
}
}else {
MessageBox(L"");
return;
}
wchar_t fnStr[256];
for (int i = 2; i <= 10; i++) {
parameterValue = EncoderValueFrameDimensionPage; //
swprintf_s(fnStr, 256, L"Duke\\T%d.BMP", i); //
mimg.SaveAdd(&Image(fnStr), &encoderParameters); //
if (mimg.GetLastStatus() != Ok) { //
MessageBox(L"");
return;
}
}
5
GDI+ ImageAttributes
ImageAttributes(VOID);
ImageAttributes
Status Reset(ColorAdjustType type = ColorAdjustTypeDefault);
Gamma
>1 <1
=1
GDI+ ImageAttributes
Status SetGamma(REAL gamma, ColorAdjustType type = ColorAdjustTypeDefault);
type
typedef enum {
ColorAdjustTypeDefault = 0, //
ColorAdjustTypeBitmap = 1, //
ColorAdjustTypeBrush = 2, //
ColorAdjustTypePen = 3, //
ColorAdjustTypeText = 4, //
ColorAdjustTypeCount = 5, //
ColorAdjustTypeAny = 6 //
} ColorAdjustType;
Graphics
Status DrawImage(Image *image, RectF &destRect, RectF &sourceRect, Unit
srcUnit,ImageAttributes *imageAttributes);//
Status DrawImage(Image *image, const Rect &destRect, INT srcx, INT srcy, INT srcwidth,
INT srcheight, Unit srcUnit = UnitPixel, ImageAttributes *imageAttributes = NULL,
DrawImageAbort callback = NULL, VOID *callbackData = NULL);
Status DrawImage(Image *image, const Point *destPoints, INT count, INT srcx, INT srcy,
INT srcwidth, INT srcheight, Unit srcUnit = UnitPixel, ImageAttributes
*imageAttributes = NULL, DrawImageAbort callback = NULL, VOID *callbackData =
NULL);
ImageAttributes
Status ClearGamma(ColorAdjustType type = ColorAdjustTypeDefault);
Graphics graph(GetDC()->m_hDC);
Image img(L".bmp");
int w = img.GetWidth(), h = img.GetHeight();
ImageAttributes imgAttr;
imgAttr.SetGamma(2); // 0.5f
graph.DrawImage(&img, Rect(0, 0, w, h), 0, 0, w, h, UnitPixel, &imgAttr);
= 2
= 0.5
2
ImageAttributes // channel
Status SetOutputChannel(ColorChannelFlags channelFlags, ColorAdjustType
ColorAdjustTypeDefault);
ColorChannelFlags colChannel;
type
Graphics graph(GetDC()->m_hDC);
Image img(L".bmp");
int w = img.GetWidth(), h = img.GetHeight();
ImageAttributes imgAttr;
imgAttr.SetOutputChannel(colChannel);
graph.DrawImage(&img, Rect(0, 0, w, h), 0, 0, w, h, UnitPixel, &imgAttr);
//
3
threshold0 ~ 1
255 255
0 2*2*2=8 // VS 255
ImageAttributes
Status SetThreshold(REAL threshold, ColorAdjustType type = ColorAdjustTypeDefault);
ImageAttributes
Status ClearThreshold(ColorAdjustType type = ColorAdjustTypeDefault);
Graphics graph(GetDC()->m_hDC);
Image img(L".bmp");
int w = img.GetWidth(), h = img.GetHeight();
ImageAttributes imgAttr;
imgAttr.SetThreshold(0.5f); // 0.2f 0.8f
//
graph.DrawImage(&img, Rect(0, 0, w, h), 0, 0, w, h, UnitPixel, &imgAttr);
//
0.2
0.5
0.8
ImageAttributes
1
gray
r = g = b = L = (R + G + B) / 3
pImg w h
Color col;
BYTE val;
pGrayImg = new Bitmap(w, h);
for (int i =0; i < w; i++) {
for (int j = 0; j < h; j++) {
pImg->GetPixel(i, j, &col); //
val = BYTE(0.299f * col.GetR() + 0.587f * col.GetG() + 0.114 * col.GetB()); //
Color.GetR() GetG() GetB()
// BYTE [0,255];
//val = BYTE((col.GetR() + col.GetG() + col.GetB()) / 3);
col.SetValue(col.MakeARGB(255, val, val, val));
pGrayImg->SetPixel(i, j, col);
}
}
delete pGrayImg; // add???
2
negative v 255 - v
//
Color col;
BYTE r, g, b;
pNegativeImg = new Bitmap(w, h); //
for (int i =0; i < w; i++) {
for (int j = 0; j < h; j++) {
pImg->GetPixel(i, j, &col); // Color*
r = 255 - col.GetR();
g = 255 - col.GetG();
b = 255 - col.GetB();
col.SetValue(col.MakeARGB(255, r, g, b)); // MakeARGB
pNegativeImg->SetPixel(i, j, col); // Color&
}
}
delete pNegative; // add???
3
woodcut
128r = g = b = 255
r = g = b = 0
avg = (R + G + B) / 3
Color col;
int avg;
BYTE val; // BYTE [0,255]
pWoodcutImg = new Bitmap(w, h);
for (int i =0; i < w; i++) {
for (int j = 0; j < h; j++) {
pImg->GetPixel(i, j, &col);
avg = int(0.299f * col.GetR() + 0.587f * col.GetG() + 0.114 * col.GetB());
//avg = int((col.GetR() + col.GetG() + col.GetB()) / 3);
if (avg >= 128) val = 255; else val = 0;
col.SetValue(col.MakeARGB(255, val, val, val));
pWoodcutImg->SetPixel(i, j, col);
}
}
delete pWoodCutImg; // add
4
carve relievo
128
67
// -
Color col, collt;
BYTE r, g, b;
pCarveImg = new Bitmap(w - 1, h - 1);
for (int i =1; i < w; i++) {
for (int j = 1; j < h; j++) {
pImg->GetPixel(i, j, &col);
pImg->GetPixel(i - 1, j - 1, &collt);
r = BYTE(max(67, min(255, abs(col.GetR() - collt.GetR() + 128))));
g = BYTE(max(67, min(255, abs(col.GetG() - collt.GetG() + 128))));
b = BYTE(max(67, min(255, abs(col.GetB() - collt.GetB() + 128))));
col.SetValue(col.MakeARGB(255, r, g, b));
pCarveImg->SetPixel(i -1, j -1, col);
}
}
delete pCurveImg; // add???
// -
Color col, collt;
BYTE r, g, b;
pRelievoImg = new Bitmap(w - 1, h - 1);
for (int i =1; i < w; i++) {
for (int j = 1; j < h; j++) {
pImg->GetPixel(i, j, &col);
pImg->GetPixel(i - 1, j - 1, &collt);
r = BYTE(max(67, min(255, abs(collt.GetR() - col.GetR() + 128))));
g = BYTE(max(67, min(255, abs(collt.GetG() - col.GetG() + 128))));
b = BYTE(max(67, min(255, abs(collt.GetB() - col.GetB() + 128))));
col.SetValue(col.MakeARGB(255, r, g, b));
pRelievoImg->SetPixel(i -1, j -1, col);
}
}
delete pRelievoImg; // add???
67 128
50 150
30 100
8 MF // _9_7
GDI metafile 1985 WMF Windows
MetaFile Win16 Win3.x 1990 Win32 Win95/
Win16
Win32
Win32/64
GDI
GDI
GDI+
WMF
EMF
EMF+
1
WMFEMF EMF+
META_SETBKCOLOR
META_SETBKMODE
META_SETMAPMODE
META_SETROP2
META_SETRELABS
67
0x020 META_POLYGON
1
0x010 META_POLYLINE
2
0x010 META_ESCAPE
3
0x010 META_RESTOREDC
4
0x010 META_FILLREGION
5
0x032
4
0x032
5
0x062
6
0x012
7
0x022
8
META_SETPOLYFILLMODE
0x010 META_FRAMEREGION
6
META_SETSTRETCHBLTMODE
0x010 META_INVERTREGION
7
META_SETTEXTCHAREXTRA
0x010 META_PAINTREGION
8
META_SETTEXTCOLOR
0x020 META_SELECTCLIPREGION
9
META_SETTEXTJUSTIFICATION 0x020 META_SELECTOBJECT
A
META_SETWINDOWORG
0x020 META_SETTEXTALIGN
B
META_SETWINDOWEXT
0x020 META_CHORD
C
META_SETVIEWPORTORG
0x020 META_SETMAPPERFLAGS
D
META_SETVIEWPORTEXT
0x020 META_EXTTEXTOUT
E
META_OFFSETWINDOWORG
0x020 META_SETDIBTODEV
F
META_SCALEWINDOWEXT
0x041 META_SELECTPALETTE
0
META_OFFSETVIEWPORTORG
0x021 META_REALIZEPALETTE
1
META_SCALEVIEWPORTEXT
0x041 META_ANIMATEPALETTE
2
META_LINETO
0x021 META_SETPALENTRIES
3
META_MOVETO
0x021 META_POLYPOLYGON
4
META_EXCLUDECLIPRECT
0x041 META_RESIZEPALETTE
5
META_INTERSECTCLIPRECT
0x041 META_DIBBITBLT
6
META_ARC
0x081 META_DIBSTRETCHBLT
7
META_ELLIPSE
0x041 META_DIBCREATEPATTERNBRUSH
8
META_FLOODFILL
0x041 META_STRETCHDIB
9
META_PIE
0x081 META_EXTFLOODFILL
A
META_RECTANGLE
0x041 META_SETLAYOUT
B
META_ROUNDRECT
0x061 META_DELETEOBJECT
C
META_PATBLT
0x061 META_CREATEPALETTE
D
META_SAVEDC
0x001 META_CREATEPATTERNBRUSH
E
META_SETPIXEL
0x041 META_CREATEPENINDIRECT
F
META_OFFSETCLIPRGN
0x022 META_CREATEFONTINDIRECT
0
META_TEXTOUT
0x052 META_CREATEBRUSHINDIRECT
1
META_BITBLT
0x092 META_CREATEREGION
2
META_STRETCHBLT
0x0B2
3
META_SETLAYOUT Win98/Win2000
0x042
9
0x012
A
0x012
B
0x012
C
0x012
D
0x012
E
0x083
0
0x023
1
0x0a3
2
0x0d3
3
0x023
4
0x003
5
0x043
6
0x003
7
0x053
8
0x013
9
0x094
0
0x0b4
1
0x014
2
0x0f43
0x054
8
0x014
9
0x01f0
0x00f7
0x01F
9
0x02F
A
0x02F
B
0x02F
C
0x06F
F
2EMF
[]
[]
EMR_ABORTPATH
EMR_ANGLEARC
EMR_ARC
EMR_ARCTO
EMR_BEGINPATH
EMR_BITBLT
EMR_CHORD
EMR_CLOSEFIGURE
EMR_CREATEBRUSHINDIRECT
EMR_CREATEDIBPATTERNBRUSHPT
EMR_CREATEMONOBRUSH
EMR_CREATEPALETTE
EMR_CREATEPEN
EMR_DELETEOBJECT
EMR_ELLIPSE
EMR_ENDPATH
EMR_EOF
EMR_EXCLUDECLIPRECT
EMR_EXTCREATEFONTINDIRECTW
EMR_EXTCREATEPEN
EMR_EXTFLOODFILL
EMR_EXTSELECTCLIPRGN
EMR_EXTTEXTOUTA
EMR_EXTTEXTOUTW
EMR_FILLPATH
EMR_FILLRGN
EMR_FLATTENPATH
EMR_FRAMERGN
EMR_GDICOMMENT
EMR_HEADER
EMR_INTERSECTCLIPRECT
EMR_INVERTRGN
EMR_LINETO
EMR_MASKBLT
EMR_MODIFYWORLDTRANSFORM
EMR_MOVETOEX
EMR_OFFSETCLIPRGN
EMR_PAINTRGN
EMR_PIE
EMR_PLGBLT
EMR_POLYBEZIER
EMR_POLYBEZIER16
EMR_POLYBEZIERTO
EMR_POLYBEZIERTO16
EMR_POLYDRAW
EMR_POLYDRAW16
EMR_POLYGON
EMR_POLYGON16
121
68
EMR_POLYLINE
41
EMR_POLYLINE16
45
EMR_POLYLINETO
55
EMR_POLYLINETO16
59
EMR_POLYPOLYGON
76
EMR_POLYPOLYGON16
46
EMR_POLYPOLYLINE
61
EMR_POLYPOLYLINE16
39
EMR_POLYTEXTOUTA
94
EMR_POLYTEXTOUTW
93
EMR_REALIZEPALETTE
49
EMR_RECTANGLE
38
EMR_RESIZEPALETTE
40
EMR_RESTOREDC
42
EMR_ROUNDRECT
60
EMR_SAVEDC
14
EMR_SCALEVIEWPORTEXTEX
29
EMR_SCALEWINDOWEXTEX
82
EMR_SELECTCLIPPATH
95
EMR_SELECTOBJECT
53
EMR_SELECTPALETTE
75
EMR_SETARCDIRECTION
83
EMR_SETBKCOLOR
84
EMR_SETBKMODE
62
EMR_SETBRUSHORGEX
71
EMR_SETCOLORADJUSTMENT
65
EMR_SETDIBITSTODEVICE
72
EMR_SETMAPMODE
70
EMR_SETMAPPERFLAGS
1
EMR_SETMETARGN
30
EMR_SETMITERLIMIT
73
EMR_SETPALETTEENTRIES
54
EMR_SETPIXELV
78
EMR_SETPOLYFILLMODE
36
EMR_SETROP2
27
EMR_SETSTRETCHBLTMODE
26
EMR_SETTEXTALIGN
74
EMR_SETTEXTCOLOR
47
EMR_SETVIEWPORTEXTEX
79
EMR_SETVIEWPORTORGEX
2
EMR_SETWINDOWEXTEX
85
EMR_SETWINDOWORGEX
5
EMR_SETWORLDTRANSFORM
88
EMR_STRETCHBLT
56
EMR_STRETCHDIBITS
92
EMR_STROKEANDFILLPATH
3
EMR_STROKEPATH
86
EMR_WIDENPATH
121
4
87
6
89
8
91
7
90
96
97
52
43
51
34
44
33
31
32
67
37
48
57
25
18
13
23
80
17
16
28
58
50
15
19
20
21
22
24
11
12
9
10
35
77
81
63
64
66
EMR_HEADER
EMR_POLYBEZIER
EMR_POLYGON
EMR_POLYLINE
EMR_POLYBEZIERTO
EMR_POLYLINETO
EMR_POLYPOLYLINE
EMR_POLYPOLYGON
EMR_SETWINDOWEXTEX
EMR_SETWINDOWORGEX
EMR_SETVIEWPORTEXTEX
EMR_SETVIEWPORTORGEX
EMR_SETBRUSHORGEX
EMR_EOF
EMR_SETPIXELV
EMR_SETMAPPERFLAGS
EMR_SETMAPMODE
EMR_SETBKMODE
EMR_SETPOLYFILLMODE
EMR_SETROP2
EMR_SETSTRETCHBLTMODE
EMR_SETTEXTALIGN
EMR_SETCOLORADJUSTMENT
EMR_SETTEXTCOLOR
EMR_SETBKCOLOR
EMR_OFFSETCLIPRGN
EMR_MOVETOEX
EMR_SETMETARGN
EMR_EXCLUDECLIPRECT
EMR_INTERSECTCLIPRECT
EMR_SCALEVIEWPORTEXTEX
EMR_SCALEWINDOWEXTEX
EMR_SAVEDC
EMR_RESTOREDC
EMR_SETWORLDTRANSFORM
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
EMR_FILLPATH
EMR_STROKEANDFILLPATH
EMR_STROKEPATH
EMR_FLATTENPATH
EMR_WIDENPATH
EMR_SELECTCLIPPATH
EMR_ABORTPATH
62
63
64
65
66
67
68
EMR_GDICOMMENT
EMR_FILLRGN
70
71
EMR_FRAMERGN
72
EMR_INVERTRGN
73
EMR_PAINTRGN
74
EMR_EXTSELECTCLIPRGN
75
EMR_BITBLT
76
EMR_STRETCHBLT
77
EMR_MASKBLT
78
EMR_PLGBLT
79
EMR_SETDIBITSTODEVICE
80
EMR_STRETCHDIBITS
81
EMR_EXTCREATEFONTINDIRECTW
82
EMR_EXTTEXTOUTA
83
EMR_EXTTEXTOUTW
84
EMR_POLYBEZIER16
85
EMR_POLYGON16
86
EMR_POLYLINE16
87
EMR_POLYBEZIERTO16
88
EMR_POLYLINETO16
89
EMR_POLYPOLYLINE16
90
EMR_POLYPOLYGON16
91
EMR_POLYDRAW16
92
EMR_CREATEMONOBRUSH
93
EMR_CREATEDIBPATTERNBRUSHPT
94
EMR_EXTCREATEPEN
95
EMR_POLYTEXTOUTA
96
5
3 EMR_POLYTEXTOUTW
97
6
EMR_SELECTOBJECT
3 EMR_SETICMMODE
98
7
EMR_CREATEPEN
3 EMR_CREATECOLORSPACE
99
8
EMR_CREATEBRUSHINDIRECT
3 EMR_SETCOLORSPACE
10
9
0
EMR_DELETEOBJECT
4 EMR_DELETECOLORSPACE
10
0
1
EMR_ANGLEARC
4 EMR_GLSRECORD
10
1
2
EMR_ELLIPSE
4 EMR_GLSBOUNDEDRECORD
10
2
3
EMR_RECTANGLE
4 EMR_PIXELFORMAT
10
3
4
EMR_ROUNDRECT
4 EMR_RESERVED_105
10
4
5
EMR_ARC
4 EMR_RESERVED_106
10
5
6
EMR_CHORD
4 EMR_RESERVED_107
10
6
7
EMR_PIE
4 EMR_RESERVED_108
10
7
8
EMR_SELECTPALETTE
4 EMR_RESERVED_109
10
8
9
EMR_CREATEPALETTE
4 EMR_RESERVED_110
11
9
0
EMR_SETPALETTEENTRIES
5 EMR_COLORCORRECTPALETTE
11
0
1
EMR_RESIZEPALETTE
5 EMR_SETICMPROFILEA
11
1
2
EMR_REALIZEPALETTE
5 EMR_SETICMPROFILEW
11
2
3
EMR_EXTFLOODFILL
5 EMR_ALPHABLEND
11
3
4
EMR_LINETO
5 EMR_SETLAYOUT
11
4
5
EMR_ARCTO
5 EMR_TRANSPARENTBLT
11
5
6
EMR_POLYDRAW
5 EMR_RESERVED_117
11
6
7
EMR_SETARCDIRECTION
5 EMR_GRADIENTFILL
11
7
8
EMR_SETMITERLIMIT
5 EMR_RESERVED_119
11
8
9
EMR_BEGINPATH
5 EMR_RESERVED_120
12
9
0
EMR_ENDPATH
6 EMR_COLORMATCHTOTARGETW
12
0
1
EMR_CLOSEFIGURE
6 EMR_CREATECOLORSPACEW
12
1
2
69 98~104 Win95/WinNT4.0 105~122 Win98/Win2000
EMR_MODIFYWORLDTRANSFORM
3EMF+
EMF
EMF
typedef struct {
WmfRecordTypeSelectPalette = GDIP_WMF_RECORD_TO_EMFPLUS(META_SELECTPALETTE),
WmfRecordTypeRealizePalette = GDIP_WMF_RECORD_TO_EMFPLUS(META_REALIZEPALETTE),
WmfRecordTypeAnimatePalette = GDIP_WMF_RECORD_TO_EMFPLUS(META_ANIMATEPALETTE),
WmfRecordTypeSetPalEntries = GDIP_WMF_RECORD_TO_EMFPLUS(META_SETPALENTRIES),
WmfRecordTypePolyPolygon = GDIP_WMF_RECORD_TO_EMFPLUS(META_POLYPOLYGON),
WmfRecordTypeResizePalette = GDIP_WMF_RECORD_TO_EMFPLUS(META_RESIZEPALETTE),
WmfRecordTypeDIBBitBlt = GDIP_WMF_RECORD_TO_EMFPLUS(META_DIBBITBLT),
WmfRecordTypeDIBStretchBlt = GDIP_WMF_RECORD_TO_EMFPLUS(META_DIBSTRETCHBLT),
WmfRecordTypeDIBCreatePatternBrush = GDIP_WMF_RECORD_TO_EMFPLUS(META_DIBCREATEPATTERNBRUSH),
WmfRecordTypeStretchDIB = GDIP_WMF_RECORD_TO_EMFPLUS(META_STRETCHDIB),
WmfRecordTypeExtFloodFill = GDIP_WMF_RECORD_TO_EMFPLUS(META_EXTFLOODFILL),
WmfRecordTypeSetLayout = GDIP_WMF_RECORD_TO_EMFPLUS(0x0149),
WmfRecordTypeResetDC = GDIP_WMF_RECORD_TO_EMFPLUS(0x014C),
WmfRecordTypeStartDoc = GDIP_WMF_RECORD_TO_EMFPLUS(0x014D),
WmfRecordTypeStartPage = GDIP_WMF_RECORD_TO_EMFPLUS(0x004F),
WmfRecordTypeEndPage = GDIP_WMF_RECORD_TO_EMFPLUS(0x0050),
WmfRecordTypeAbortDoc = GDIP_WMF_RECORD_TO_EMFPLUS(0x0052),
WmfRecordTypeEndDoc = GDIP_WMF_RECORD_TO_EMFPLUS(0x005E),
WmfRecordTypeDeleteObject = GDIP_WMF_RECORD_TO_EMFPLUS(META_DELETEOBJECT),
WmfRecordTypeCreatePalette = GDIP_WMF_RECORD_TO_EMFPLUS(META_CREATEPALETTE),
WmfRecordTypeCreateBrush = GDIP_WMF_RECORD_TO_EMFPLUS(0x00F8),
WmfRecordTypeCreatePatternBrush = GDIP_WMF_RECORD_TO_EMFPLUS(META_CREATEPATTERNBRUSH),
WmfRecordTypeCreatePenIndirect = GDIP_WMF_RECORD_TO_EMFPLUS(META_CREATEPENINDIRECT),
WmfRecordTypeCreateFontIndirect = GDIP_WMF_RECORD_TO_EMFPLUS(META_CREATEFONTINDIRECT),
WmfRecordTypeCreateBrushIndirect = GDIP_WMF_RECORD_TO_EMFPLUS(META_CREATEBRUSHINDIRECT),
WmfRecordTypeCreateBitmapIndirect = GDIP_WMF_RECORD_TO_EMFPLUS(0x02FD),
WmfRecordTypeCreateBitmap = GDIP_WMF_RECORD_TO_EMFPLUS(0x06FE),
WmfRecordTypeCreateRegion = GDIP_WMF_RECORD_TO_EMFPLUS(META_CREATEREGION),
// EMF 124
EmfRecordTypeHeader = EMR_HEADER,
EmfRecordTypePolyBezier = EMR_POLYBEZIER,
EmfRecordTypePolygon = EMR_POLYGON,
EmfRecordTypePolyline = EMR_POLYLINE,
EmfRecordTypePolyBezierTo = EMR_POLYBEZIERTO,
EmfRecordTypePolyLineTo = EMR_POLYLINETO,
EmfRecordTypePolyPolyline = EMR_POLYPOLYLINE,
EmfRecordTypePolyPolygon = EMR_POLYPOLYGON,
EmfRecordTypeSetWindowExtEx = EMR_SETWINDOWEXTEX,
EmfRecordTypeSetWindowOrgEx = EMR_SETWINDOWORGEX,
EmfRecordTypeSetViewportExtEx = EMR_SETVIEWPORTEXTEX,
EmfRecordTypeSetViewportOrgEx = EMR_SETVIEWPORTORGEX,
EmfRecordTypeSetBrushOrgEx = EMR_SETBRUSHORGEX,
EmfRecordTypeEOF = EMR_EOF,
EmfRecordTypeSetPixelV = EMR_SETPIXELV,
EmfRecordTypeSetMapperFlags = EMR_SETMAPPERFLAGS,
EmfRecordTypeSetMapMode = EMR_SETMAPMODE,
EmfRecordTypeSetBkMode = EMR_SETBKMODE,
EmfRecordTypeSetPolyFillMode = EMR_SETPOLYFILLMODE,
EmfRecordTypeSetROP2 = EMR_SETROP2,
EmfRecordTypeSetStretchBltMode = EMR_SETSTRETCHBLTMODE,
EmfRecordTypeSetTextAlign = EMR_SETTEXTALIGN,
EmfRecordTypeSetColorAdjustment = EMR_SETCOLORADJUSTMENT,
EmfRecordTypeSetTextColor = EMR_SETTEXTCOLOR,
EmfRecordTypeSetBkColor = EMR_SETBKCOLOR,
EmfRecordTypeOffsetClipRgn = EMR_OFFSETCLIPRGN,
EmfRecordTypeMoveToEx = EMR_MOVETOEX,
EmfRecordTypeSetMetaRgn = EMR_SETMETARGN,
EmfRecordTypeExcludeClipRect = EMR_EXCLUDECLIPRECT,
EmfRecordTypeIntersectClipRect = EMR_INTERSECTCLIPRECT,
EmfRecordTypeScaleViewportExtEx = EMR_SCALEVIEWPORTEXTEX,
EmfRecordTypeScaleWindowExtEx = EMR_SCALEWINDOWEXTEX,
EmfRecordTypeSaveDC = EMR_SAVEDC,
EmfRecordTypeRestoreDC = EMR_RESTOREDC,
EmfRecordTypeSetWorldTransform = EMR_SETWORLDTRANSFORM,
EmfRecordTypeModifyWorldTransform = EMR_MODIFYWORLDTRANSFORM,
EmfRecordTypeSelectObject = EMR_SELECTOBJECT,
EmfRecordTypeCreatePen = EMR_CREATEPEN,
EmfRecordTypeCreateBrushIndirect = EMR_CREATEBRUSHINDIRECT,
EmfRecordTypeDeleteObject = EMR_DELETEOBJECT,
EmfRecordTypeAngleArc = EMR_ANGLEARC,
EmfRecordTypeEllipse = EMR_ELLIPSE,
EmfRecordTypeRectangle = EMR_RECTANGLE,
EmfRecordTypeRoundRect = EMR_ROUNDRECT,
EmfRecordTypeArc = EMR_ARC,
EmfRecordTypeChord = EMR_CHORD,
EmfRecordTypePie = EMR_PIE,
EmfRecordTypeSelectPalette = EMR_SELECTPALETTE,
EmfRecordTypeCreatePalette = EMR_CREATEPALETTE,
EmfRecordTypeSetPaletteEntries = EMR_SETPALETTEENTRIES,
EmfRecordTypeResizePalette = EMR_RESIZEPALETTE,
EmfRecordTypeRealizePalette = EMR_REALIZEPALETTE,
EmfRecordTypeExtFloodFill = EMR_EXTFLOODFILL,
EmfRecordTypeLineTo = EMR_LINETO,
EmfRecordTypeArcTo = EMR_ARCTO,
EmfRecordTypePolyDraw = EMR_POLYDRAW,
EmfRecordTypeSetArcDirection = EMR_SETARCDIRECTION,
EmfRecordTypeSetMiterLimit = EMR_SETMITERLIMIT,
EmfRecordTypeBeginPath = EMR_BEGINPATH,
EmfRecordTypeEndPath = EMR_ENDPATH,
EmfRecordTypeCloseFigure = EMR_CLOSEFIGURE,
EmfRecordTypeFillPath = EMR_FILLPATH,
EmfRecordTypeStrokeAndFillPath = EMR_STROKEANDFILLPATH,
EmfRecordTypeStrokePath = EMR_STROKEPATH,
EmfRecordTypeFlattenPath = EMR_FLATTENPATH,
EmfRecordTypeWidenPath = EMR_WIDENPATH,
EmfRecordTypeSelectClipPath = EMR_SELECTCLIPPATH,
EmfRecordTypeAbortPath = EMR_ABORTPATH,
EmfRecordTypeReserved_069 = 69,
EmfRecordTypeGdiComment = EMR_GDICOMMENT,
EmfRecordTypeFillRgn = EMR_FILLRGN,
EmfRecordTypeFrameRgn = EMR_FRAMERGN,
EmfRecordTypeInvertRgn = EMR_INVERTRGN,
EmfRecordTypePaintRgn = EMR_PAINTRGN,
EmfRecordTypeExtSelectClipRgn = EMR_EXTSELECTCLIPRGN,
EmfRecordTypeBitBlt = EMR_BITBLT,
EmfRecordTypeStretchBlt = EMR_STRETCHBLT,
EmfRecordTypeMaskBlt = EMR_MASKBLT,
EmfRecordTypePlgBlt = EMR_PLGBLT,
EmfRecordTypeSetDIBitsToDevice = EMR_SETDIBITSTODEVIC,
EmfRecordTypeStretchDIBits = EMR_STRETCHDIBITS,
EmfRecordTypeExtCreateFontIndirect = EMR_EXTCREATEFONTINDIRECTW,
EmfRecordTypeExtTextOutA = EMR_EXTTEXTOUTA,
EmfRecordTypeExtTextOutW = EMR_EXTTEXTOUTW,
EmfRecordTypePolyBezier16 = EMR_POLYBEZIER16,
EmfRecordTypePolygon16 = EMR_POLYGON16,
EmfRecordTypePolyline16 = EMR_POLYLINE16,
EmfRecordTypePolyBezierTo16 = EMR_POLYBEZIERTO16,
EmfRecordTypePolylineTo16 = EMR_POLYLINETO16,
EmfRecordTypePolyPolyline16 = EMR_POLYPOLYLINE16,
EmfRecordTypePolyPolygon16 = EMR_POLYPOLYGON16,
EmfRecordTypePolyDraw16 = EMR_POLYDRAW16,
EmfRecordTypeCreateMonoBrush = EMR_CREATEMONOBRUSH,
EmfRecordTypeCreateDIBPatternBrushPt = EMR_CREATEDIBPATTERNBRUSHPT,
EmfRecordTypeExtCreatePen = EMR_EXTCREATEPEN,
EmfRecordTypePolyTextOutA = EMR_POLYTEXTOUTA,
EmfRecordTypePolyTextOutW = EMR_POLYTEXTOUTW,
EmfRecordTypeSetICMMode = 98,
EmfRecordTypeCreateColorSpace = 99,
EmfRecordTypeSetColorSpace = 100,
EmfRecordTypeDeleteColorSpace = 101,
EmfRecordTypeGLSRecord = 102,
EmfRecordTypeGLSBoundedRecord = 103,
EmfRecordTypePixelFormat = 104,
EmfRecordTypeDrawEscape = 105,
EmfRecordTypeExtEscape = 106,
EmfRecordTypeStartDoc = 107,
EmfRecordTypeSmallTextOut = 108,
EmfRecordTypeForceUFIMapping = 109,
EmfRecordTypeNamedEscape = 110,
EmfRecordTypeColorCorrectPalette = 111,
EmfRecordTypeSetICMProfileA = 112,
EmfRecordTypeSetICMProfileW = 113,
EmfRecordTypeAlphaBlend = 114,
EmfRecordTypeSetLayout = 115,
EmfRecordTypeTransparentBlt = 116,
EmfRecordTypeReserved_117 = 117,
EmfRecordTypeGradientFill = 118,
EmfRecordTypeSetLinkedUFIs = 119,
EmfRecordTypeSetTextJustification = 120,
EmfRecordTypeColorMatchToTargetW = 121,
EmfRecordTypeCreateColorSpaceW = 122,
EmfRecordTypeMax = 122,
EmfRecordTypeMin = 1,
// EMF+63
EmfPlusRecordTypeInvalid = GDIP_EMFPLUS_RECORD_BASE,
EmfPlusRecordTypeHeader,
EmfPlusRecordTypeEndOfFile,
EmfPlusRecordTypeComment,
EmfPlusRecordTypeGetDC,
EmfPlusRecordTypeMultiFormatStart,
EmfPlusRecordTypeMultiFormatSection,
EmfPlusRecordTypeMultiFormatEnd,
EmfPlusRecordTypeObject,
EmfPlusRecordTypeClear,
EmfPlusRecordTypeFillRects,
EmfPlusRecordTypeDrawRects,
EmfPlusRecordTypeFillPolygon,
EmfPlusRecordTypeDrawLines,
EmfPlusRecordTypeFillEllipse,
EmfPlusRecordTypeDrawEllipse,
EmfPlusRecordTypeFillPie,
EmfPlusRecordTypeDrawPie,
EmfPlusRecordTypeDrawArc,
EmfPlusRecordTypeFillRegion,
EmfPlusRecordTypeFillPath,
EmfPlusRecordTypeDrawPath,
EmfPlusRecordTypeFillClosedCurve,
EmfPlusRecordTypeDrawClosedCurve,
EmfPlusRecordTypeDrawCurve,
EmfPlusRecordTypeDrawBeziers,
EmfPlusRecordTypeDrawImage,
EmfPlusRecordTypeDrawImagePoints,
EmfPlusRecordTypeDrawString,
EmfPlusRecordTypeSetRenderingOrigin,
EmfPlusRecordTypeSetAntiAliasMode,
EmfPlusRecordTypeSetTextRenderingHint,
EmfPlusRecordTypeSetTextContrast,
EmfPlusRecordTypeSetGammaValue,
EmfPlusRecordTypeSetInterpolationMode,
EmfPlusRecordTypeSetPixelOffsetMode,
EmfPlusRecordTypeSetCompositingMode,
EmfPlusRecordTypeSetCompositingQuality,
EmfPlusRecordTypeSave,
EmfPlusRecordTypeRestore,
EmfPlusRecordTypeBeginContainer,
EmfPlusRecordTypeBeginContainerNoParams,
EmfPlusRecordTypeEndContainer,
EmfPlusRecordTypeSetWorldTransform,
EmfPlusRecordTypeResetWorldTransform,
EmfPlusRecordTypeMultiplyWorldTransform,
EmfPlusRecordTypeTranslateWorldTransform,
EmfPlusRecordTypeScaleWorldTransform,
EmfPlusRecordTypeRotateWorldTransform,
EmfPlusRecordTypeSetPageTransform,
EmfPlusRecordTypeResetClip,
EmfPlusRecordTypeSetClipRect,
EmfPlusRecordTypeSetClipPath,
EmfPlusRecordTypeSetClipRegion,
EmfPlusRecordTypeOffsetClip,
EmfPlusRecordTypeDrawDriverString,
EmfPlusRecordTypeStrokeFillPath,
EmfPlusRecordTypeSerializableObject,
EmfPlusRecordTypeSetTSGraphics,
EmfPlusRecordTypeSetTSClip,
EmfPlusRecordTotal,
EmfPlusRecordTypeMax = EmfPlusRecordTotal-1,
EmfPlusRecordTypeMin = EmfPlusRecordTypeHeader
} EmfPlusRecordType;
#define
#define
#define
#define
#define
GDIP_EMFPLUS_RECORD_BASE
0x00004000
GDIP_WMF_RECORD_BASE
0x00010000
GDIP_WMF_RECORD_TO_EMFPLUS(n) ((EmfPlusRecordType)((n) | GDIP_WMF_RECORD_BASE))
GDIP_EMFPLUS_RECORD_TO_WMF(n) ((n) & (~GDIP_WMF_RECORD_BASE))
GDIP_IS_WMF_RECORDTYPE(n)
(((n) & GDIP_WMF_RECORD_BASE) != 0)
2 GDI SDK
GDI Create*MetaFile DC
SDK CDC HDC
DCDC Play*MetaFile
1WMF
SDK
HDC CreateMetaFile(LPCTSTR lpszFile); //
// lpszFile=NULL
HMETAFILE CloseMetaFile(HDC hdc); //
HMETAFILE GetMetaFile(LPCWSTR lpName); //
BOOL PlayMetaFile(HDC hdc, HMETAFILE hmf); //
BOOL DeleteMetaFile(HMETAFILE hmf); // H
// HMETAFILE
//
HDC hdc= CreateMetaFile(L"test.wmf");// WMF , DC
Ellipse(hdc, 10, 10, 150, 100); // Win32 API
Rectangle(hdc, 160, 100, 360, 200);
HMETAFILE hwmf = CloseMetaFile(hdc); // ,
//
// HMETAFILE hwmf = GetMetaFile(L"test.wmf");
if (hwmf != NULL) {
PlayMetaFile(GetDC()->m_hDC, hwmf);
DeleteMetaFile(hwmf);
}
BOOL PlayMetaFileRecord( //
HDC hdc,
// DC
LPHANDLETABLE lpHandletable,
//
CONST ENHMETARECORD *lpMetaRecord, //
UINT nHandles
//
);
BOOL EnumMetaFile( //
HDC hdc,
// DC
HMETAFILE hmf,
//
MFENUMPROC lpMetaFunc,
//
LPARAM lParam
//
);
int CALLBACK EnumMetaFileProc( //
// EnumMetaFile
HDC hDC,
// DC
HANDLETABLE *lpHTable, //
METARECORD *lpMFR,
//
int nObj,
//
LPARAM lpClientData
//
);
2EMF
2EMF
SDK
HDC CreateEnhMetaFile( // enhance
HDC hdcRef,
// DC
LPCTSTR lpFilename, // lpFilename=NULL
CONST RECT* lpRect, // 0.01
LPCTSTR lpDescription//
);
HENHMETAFILE CloseEnhMetaFile(HDC hdc); //
HENHMETAFILE GetEnhMetaFile(LPCTSTR lpszMetaFile); //
BOOL PlayEnhMetaFile( //
HDC hdc,
// DC
HENHMETAFILE hemf, //
CONST RECT *lpRect //
);
BOOL DeleteEnhMetaFile(HENHMETAFILE hemf); //
//
DWORD GetLastError(void); //
// MetaFile EnhMetaFile
//
// HDC
HDC hdcRef = GetDC()->m_hDC;
int iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE); //
int iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE); //
int iWidthPels = GetDeviceCaps(hdcRef, HORZRES); //
int iHeightPels = GetDeviceCaps(hdcRef, VERTRES); //
// 0.01
RECT rect;
::GetClientRect(this->m_hWnd, &rect); //
//rect.left = (rect.left * iWidthMM * 100)/iWidthPels;
//rect.top = (rect.top * iHeightMM * 100)/iHeightPels;
rect.right = (rect.right * iWidthMM * 100)/iWidthPels;
rect.bottom = (rect.bottom * iHeightMM * 100)/iHeightPels;
// EMF
HDC hdcMeta = CreateEnhMetaFile(hdcRef, L"test.emf", &rect, NULL);
//
SelectObject(hdcMeta, CreatePen(PS_SOLID, 0, RGB(255, 0, 0)));
Ellipse(hdcMeta, 10, 10, 150, 100);
Rectangle(hdcMeta, 160, 100, 360, 200);
//
HENHMETAFILE hemf = CloseEnhMetaFile(hdcMeta);
//
// HENHMETAFILE hemf = GetEnhMetaFile(L"test.emf");
RECT rect;
::GetClientRect(this->m_hWnd, &rect);
PlayEnhMetaFile(GetDC()->m_hDC, hemf, &rect);
DeleteEnhMetaFile(hemf);
test.emf // 1K
UINT GetEnhMetaFileHeader( //
// NULL
HENHMETAFILE hemf,
//
UINT cbBuffer,
//
LPENHMETAHEADER lpemh
//
);
BOOL PlayEnhMetaFileRecord( //
HDC hdc,
// DC
LPHANDLETABLE lpHandletable,
//
CONST ENHMETARECORD *lpEnhMetaRecord,
//
UINT nHandles
// ???
);
BOOL EnumEnhMetaFile( //
//
HDC hdc,
// DC
HENHMETAFILE hemf,
//
ENHMFENUMPROC lpEnhMetaFunc,
//
LPVOID lpData,
//
CONST RECT *lpRect
//
);
int CALLBACK EnhMetaFileProc( //
// EnumEnhMetaFile
// FALSE(0) TRUE( 0)
HDC hDC,
// DC
HANDLETABLE *lpHTable,
//
CONST ENHMETARECORD *lpEMFR,
//
int nObj,
//
LPARAM lpData
// parameter
);
//()// EnhMetaFileProc
int CALLBACK EnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable,
CONST ENHMETARECORD *lpEMFR, int nObj, LPARAM lpData) {
/*if (lpEMFR->iType == EMR_CREATEPEN //
|| lpEMFR->iType == EMR_SELECTOBJECT)
PlayEnhMetaFileRecord(hDC, lpHTable, lpEMFR, nObj);*/
if (lpEMFR->iType == EMR_RECTANGLE) { //
PlayEnhMetaFileRecord(hDC, lpHTable, lpEMFR, nObj);
return FALSE; //
}
return TRUE; //
}
//
HENHMETAFILE hemf = GetEnhMetaFile(L"test.emf");
RECT rect;
::GetClientRect(this->m_hWnd, &rect);
EnumEnhMetaFile(GetDC()->m_hDC, hemf, //
ENHMFENUMPROC(&EnhMetaFileProc), NULL, &rect); //
// (ENHMFNUMPROC)&EnhMetaFileProc
DeleteEnhMetaFile(hemf);
test.emf
3
SDK WMF EMF
WMF EMF
3 SDK
UINT GetMetaFileBitsEx( // WMF
// NULL
HMETAFILE hmf, // WMF
UINT nSize,
//
LPVOID lpvData //
);
DeleteMetaFile(hwmf);
}
else MessageBox(L"Create memory EMF file fail!");
DeleteEnhMetaFile(hemf); // hemf NULL
delete []buff; // add by chenbk
}
else MessageBox(L"Load WMF file fail!");
EMF WMF
3 SDK
UINT GetWinMetaFileBits( // EMF
// NULL
HENHMETAFILE hemf, //
UINT cbBuffer,
//
LPBYTE lpbBuffer,
//
INT fnMapMode,
// , MM_TEXT
HDC hdcRef
// DC
);
// HIMETRIC 0.01
rect0.left = 0;
rect0.top = 0;
rect0.right = iWidthMM * 100;
rect0.bottom = iHeightMM * 100;
rect1.left = 0;
rect1.top = 0;
rect1.right = iWidthPels;
rect1.bottom = iHeightPels;
// EMF
hdcMeta = CreateEnhMetaFile(hdcRef, NULL, &rect0, NULL);
OnLButtonUp DC SDK GDI
SelectObject(hdcMeta, pLinePen);
MoveToEx(hdcMeta, point1.x, point1.y, NULL);
LineTo(hdcMeta, point2.x, point2.y);
OnDraw
DC
HENHMETAFILE hemf = CloseEnhMetaFile(hdcMeta); //
PlayEnhMetaFile(GetDC()->m_hDC, hemf, &rect1); //
// EMF
hdcMeta = CreateEnhMetaFile(pDC->m_hDC, NULL, &rect0, NULL);
PlayEnhMetaFile(hdcMeta,hemf,&rect1);//
DeleteEnhMetaFile(hemf); //
// PlayEnhMetaFile //
SDK
HMETAFILE CopyMetaFile(HMETAFILE hmfSrc, LPCTSTR lpszFile);
3MFC CMetaFileDC
SDK MFC CMetaFileDC CDC
CMetaFileDC
// CDC CClientDC CPaintDC CWindowDC CMetaFileDC
CMetaFileDC CMetaFileDCCreate
WMF CreateEnhanced EMFClose WMF CloseEnhanced
EMF CDC
1 CMetaFileDC
CMetaFileDC CMetaFileDC
CMetaFileDC( );
Create
BOOL Create(LPCTSTR lpszFilename = NULL);
WMF CreateEnhanced
BOOL CreateEnhanced(CDC* pDCRef, LPCTSTR lpszFileName,
LPCRECT lpBounds, LPCTSTR lpszDescription);
EMF
lpszDescription NULL
CMetaFileDC metaDC; // DC
// metaDC.Create(NULL); // WMF DC
// metaDC.Create(L"test.wmf"); // WMF DC
// metaDC.CreateEnhanced(NULL, NULL, NULL, NULL); // EMF DC
//
HDC hdcRef = GetDC()->m_hDC;
int iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE); //
int iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE); //
int iWidthPels = GetDeviceCaps(hdcRef, HORZRES); //
int iHeightPels = GetDeviceCaps(hdcRef, VERTRES); //
// 0.01
RECT rect;
GetClientRect(&rect); //
rect.right = (rect.right * iWidthMM * 100)/iWidthPels;
rect.bottom = (rect.bottom * iHeightMM * 100)/iHeightPels;
// EMF DC
metaDC.CreateEnhanced(GetDC(), L"test.emf", &rect, L"MFCDraw MixGraphics");
2
CMetaFileDC CDC CDC CMetaFileDC
metaDC.SelectObject(pLinePen);
// &CPen(PS_SOLID,1,RGB(250,0,0))
metaDC.MoveTo(point1);
metaDC.LineTo(point2);
3
DC CMetaFileDC
HMETAFILE Close( ); // WMF DC NULL
HENHMETAFILE CloseEnhanced( ); // EMF DC NULL
CDC
BOOL PlayMetaFile(HMETAFILE hMF); // WMF
// EMF
BOOL PlayMetaFile(HENHMETAFILE hEnhMetaFile, LPCRECT lpBounds);
SDK
BOOL PlayMetaFile(HDC hdc, HMETAFILE hmf); // WMF
BOOL PlayEnhMetaFile( // EMF
HDC hdc,
// DC
HENHMETAFILE hemf, //
CONST RECT *lpRect //
);
lpBounds
SDK
BOOL DeleteMetaFile(HMETAFILE hmf); // win32
metaDC.LineTo(point2);
OnDraw DC
DC DC
HENHMETAFILE hemf = metaDC.CloseEnhanced(); // DC
PlayEnhMetaFile(GetDC()->m_hDC, hemf, &rectPixel); // SDK
// pDC->PlayMetaFile(hemf, &rectPixel); //
metaDC.CreateEnhanced(GetDC(), NULL, &rectHimm, NULL);// DC
metaDC.PlayMetaFile(hemf,&rectPixel);//
DeleteEnhMetaFile(hemf); // SDK
SDK
HMETAFILE CopyMetaFile(HMETAFILE hmfSrc, LPCTSTR lpszFile);
5
CMetaFileDC CDC CMetaFileDC
Close CloseEnhanced SDK 22
BOOL PlayEnhMetaFileRecord( //
HDC hdc,
// DC
LPHANDLETABLE lpHandletable,
//
CONST ENHMETARECORD *lpEnhMetaRecord, //
UINT nHandles
//
);
BOOL EnumEnhMetaFile( //
//
HDC hdc,
// DC
HENHMETAFILE hemf,
//
ENHMFENUMPROC lpEnhMetaFunc, //
LPVOID lpData,
//
CONST RECT *lpRect
//
);
int CALLBACK EnhMetaFileProc( //
// EnumEnhMetaFile
// FALSE(0) TRUE( 0)
HDC hDC,
// DC
HANDLETABLE *lpHTable,
//
CONST ENHMETARECORD *lpEMFR,
//
int nObj,
//
LPARAM lpData
//
);
// EMF DC
CMetaFileDC metaDC;
metaDC.CreateEnhanced(GetDC(), L"test.emf", &rectHimm, NULL);
//
metaDC.SelectObject(new CPen(PS_SOLID, 0, RGB(255, 0, 0)));
metaDC.Ellipse(10, 10, 150, 100);
metaDC.Rectangle(160, 100, 360, 200);
//
HENHMETAFILE hemf = metaDC.CloseEnhanced();
//
PlayEnhMetaFile(GetDC()->m_hDC, hemf, &rectPixel);
//
DeleteEnhMetaFile(hemf); // SDK
test.emf
//
int CALLBACK EnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable,
CONST ENHMETARECORD *lpEMFR, int nObj, LPARAM lpData) {
/*if (lpEMFR->iType == EMR_CREATEPEN //
|| lpEMFR->iType == EMR_SELECTOBJECT)
PlayEnhMetaFileRecord(hDC, lpHTable, lpEMFR, nObj);*/
if (lpEMFR->iType == EMR_RECTANGLE) { //
PlayEnhMetaFileRecord(hDC, lpHTable, lpEMFR, nObj);
return FALSE; //
}
return TRUE; //
}
//
EnumEnhMetaFile(GetDC()->m_hDC, hemf, //
ENHMFENUMPROC(&EnhMetaFileProc), NULL, &rectPixel); //
DeleteEnhMetaFile(hemf); //
test.emf
4GDI+
GDI+ Metafile Image GDI+ Metafile
EMF EMF+EMF EMF+
typedef enum {
EmfTypeEmfOnly = MetafileTypeEmf, // EMF
EmfTypeEmfPlusOnly = MetafileTypeEmfPlusOnly, // EMF+
EmfTypeEmfPlusDual = MetafileTypeEmfPlusDual // EMF EMF+
} EmfType; // enhance meta file
1Metafile
Metafile 13
//
Metafile(const WCHAR *filename);
Metafile(const
WCHAR
*fileName,
HDC
referenceHdc,
EmfType
type
=
EmfTypeEmfPlusDual, const WCHAR *description = NULL);
Metafile(const WCHAR *fileName, HDC referenceHdc, const Rect &frameRect,
MetaFileFrameUnit frameUnit =
MetafileFrameUnitGdi, EmfType type =
EmfTypeEmfPlusDual, const WCHAR *description = NULL);
Metafile(const WCHAR *fileName, HDC referenceHdc, const RectF &frameRect,
MetafileFrameUnit frameUnit =
MetafileFrameUnitGdi, EmfType type =
EmfTypeEmfPlusDual, const WCHAR *description = NULL);
//
Metafile(IStream *stream);
Metafile(IStream *stream, HDC referenceHdc, EmfType type = EmfTypeEmfPlusDual, const
WCHAR *description = NULL);
Metafile(IStream *stream, HDC referenceHdc, const Rect &frameRect, MetafileFrameUnit
frameUnit = MetafileFrameUnitGdi, EmfType type = EmfTypeEmfPlusDual, const
WCHAR *description = NULL);
Metafile(IStream *stream, HDC referenceHdc, const RectF &frameRect, MetafileFrameUnit
frameUnit = MetafileFrameUnitGdi, EmfType type = EmfTypeEmfPlusDual, const
WCHAR *description = NULL);
// DC
Metafile(HDC referenceHdc, EmfType type = EmfTypeEmfPlusDual, const WCHAR
*description = NULL);
Metafile(HDC referenceHdc, const Rect &frameRect, MetafileFrameUnit frameUnit =
MetafileFrameUnitGdi, EmfType type = EmfTypeEmfPlusDual, const WCHAR
*description = NULL);
Metafile(HDC referenceHdc, const RectF &frameRect, MetaFileFrameUnit frameUnit =
MetafileFrameUnitGdi, EmfType type = EmfTypeEmfPlusDual, const WCHAR
*description = NULL);
// WMF/EMF
Metafile(HENHMETAFILE hEmf, BOOL deleteEmf = FALSE);
Metafile(HMETAFILE hWmf, const WmfPlaceableFileHeader *wmfPlaceableFileHeader, BOOL
deleteWmf = FALSE);
typedef enum {
MetafileFrameUnitPixel = UnitPixel, //
MetafileFrameUnitPoint = UnitPoint, //
MetafileFrameUnitInch = UnitInch, //
MetafileFrameUnitDocument = UnitDocument, //
MetafileFrameUnitMillimeter = UnitDocument + 1, //
MetafileFrameUnitGdi = UnitDocument + 2 // GDI+
} MetafileFrameUnit;
typedef struct {
UINT32 Key; //
INT16 Hmf; //
PWMFRect16 BoundingBox; //
INT16 Inch; //
UINT32 Reserved; //
INT16 Checksum; //
} WmfPlaceableFileHeader;
http://www.caenet.cn/Forums/
// DC
Metafile(const WCHAR *filename);
Metafile mf(L"yyy.emf");
// DC
Metafile(const WCHAR *fileName, HDC referenceHdc, EmfType type =
EmfTypeEmfPlusDual, const WCHAR *description = NULL);
Metafile mf(L"yyy.emf", GetDC()->m_hDC, MetafileTypeEmf, L"");
2Metafile
Metafile
// Graphics EnumerateMetafile
Status PlayRecord(EmfPlusRecordType recordType, UINT flags, UINT dataSize, const BYTE
*data);
// GDI
static UINT EmfToWmfBits(HENHMETAFILE hemf, UINT cbData16, LPBYTE pData16, INT
iMapMode, EmfToWmfBitsFlags eFlags); // EMF WMF
HENHMETAFILE GetHENHMETAFILE(VOID); // EMF SDK
// // ???
UINT GetDownLevelRasterizationLimit(VOID);
Status SetDownLevelRasterizationLimit(UINT metafileRasterizationLimitDpi);
//
Status GetMetafileHeader(MetafileHeader *header) const;
static Status GetMetafileHeader(const WCHAR *filename, MetafileHeader *header);
static Status GetMetafileHeader(IStream *stream, MetafileHeader *header);
static Status GetMetafileHeader(HENHMETAFILE *hEmf, MetafileHeader *header);
static Status GetMetafileHeader(HMETAFILE hWmf, const WmfPlaceableFileHeader
*wmfPlaceableFileHeader, MetafileHeader *header);
3MetafileHeader
MetafileHeader Metafile
GetMetafileHeader
BOOL IsWmf(VOID); // WMF
BOOL IsEmf(VOID) const; // EMF
BOOL IsEmfPlus(VOID) const; // EMF+
BOOL IsEmfOrEmfPlus(VOID) const; // EMF EMF+
BOOL IsEmfPlusOnly(VOID) const; // EMF+
BOOL IsEmfPlusDual(VOID) const; // EMF EMF+
MetafileType GetType(VOID); //
UINT GetVersion(VOID); //
UINT GetMetafileSize(VOID); //
UINT GetEmfPlusFlags(VOID); // EMF+
const METAHEADER *GetWmfHeader(VOID) const; // WMF
const ENHMETAHEADER3 *GetEmfHeader(VOID) const; // EMF
void GetBounds(Rect *rect); //
REAL GetDpiX(VOID); // DPI
REAL GetDpiY(VOID); // DPI
BOOL IsDisplay(VOID) const; // DC
BOOL IsWmfPlaceable(VOID) const; // WMF
REAL DpiX; //
REAL DpiY; //
UINT EmfPlusFlags; // EMF+
INT EmfPlusHeaderSize; // EMF+
INT X; //
INT Y; //
INT Width; //
INT Height; //
INT LogicalDpiX; //
INT LogicalDpiY; //
UINT Size; //
MetafileType Type; // MetafileType
UINT Version; //
union {WmfHeader, EmfHeader}; // METAHEADER ENHMETAHEADER3
enum MetafileType {
MetafileTypeInvalid,
// Invalid metafile
MetafileTypeWmf,
// Standard WMF
MetafileTypeWmfPlaceable, // Placeable WMF
MetafileTypeEmf,
// EMF (not EMF+)
MetafileTypeEmfPlusOnly, // EMF+ without dual, down-level records
MetafileTypeEmfPlusDual
// EMF+ with dual, down-level records
};
Metafile mf (L"test.emf");
MetafileHeader header;
mf.GetMetafileHeader(&header);
Rect rect;
header.GetBounds(&rect);
UINT size = header.GetMetafileSize();
5 GDI+
1
Metafile DC
Metafile(const WCHAR *fileName, HDC referenceHdc, EmfType type =
EmfTypeEmfPlusDual, const WCHAR *description = NULL);
2
Metafile DC
Metafile(const WCHAR *filename);
Graphics DrawImage
Status DrawImage(Image *image, INT x, INT y);
Graphics *myGraphics = new Graphics(GetDC()->m_hDC);
Metafile *myMetafile = new Metafile(L"MyDiskFile.emf");
myGraphics->DrawImage(myMetafile, 0, 0);
// delete myGraphics and myMetafile;
Metafile
Status GetMetafileHeader(MetafileHeader *header) const;
MetafileHeader MetafileHeader
void GetBounds(Rect *rect);
Graphics DrawImage
DrawImage(Image *image, const Rect &rect);
DC Metafile
3
Metafile
Status PlayRecord(EmfPlusRecordType recordType, UINT flags,
UINT dataSize, const BYTE *data);
EMF Graphics 12
// /
BOOL CALLBACK metaCallback(EmfPlusRecordType recordType, unsigned int flags,
unsigned int dataSize, const unsigned char* pStr, void* callbackData) {
if (recordType == EmfPlusRecordTypeDrawPath
/*|| recordType == EmfPlusRecordTypeSetClipRegion*/)
return TRUE;
static_cast <Metafile*> (callbackData)->PlayRecord(recordType, flags, dataSize, pStr);
return TRUE;
} //
// ()
//
Graphics graph(pDC->m_hDC);
Metafile *pmf = new Metafile(L"MyDiskFile.emf");
4
Metafile
DC
DC
GDI+
Metafile
HENHMETAFILE GetHENHMETAFILE(VOID);
DC
Metafile
Metafile GDI+
Image Metafile
SDK
mf = NULL;
mfGraph = NULL;
fns[0] = L"draw.emf";
fns[1] = L"draw0.emf";
fni = 0;
OnInitialUpdate Metafile
HDC hdcRef = GetDC()->m_hDC;
rect0.X = 0;
rect0.Y = 0;
rect0.Width = GetDeviceCaps(hdcRef, HORZRES);
rect0.Height = GetDeviceCaps(hdcRef, VERTRES);
mf = new Metafile(fns[fni], hdcRef, rect0, MetafileFrameUnitPixel);
mfGraph = new Graphics(mf);
OnLButtonUp
mfGraph->DrawLine(&Pen(Color::Green), p0.x, p0.y, point.x , point.y);
OnDraw
delete mfGraph;
delete mf;
Metafile *mf0 = new Metafile(fns[fni]);
Graphics graph(pDC->m_hDC);
graph.DrawImage(mf0, rect0);
fni = !fni; // if(fni) fni = 0; else fni = 1;
mf = new Metafile(fns[fni], pDC->m_hDC, rect0, MetafileFrameUnitPixel);
mfGraph = new Graphics(mf);
mfGraph->DrawImage(mf0, rect0);
delete mf0;
delete mfGraph;
delete mf;
// _Saturday, September 15, 2007
6.3 GDI+