GDI+学习记录之纹理画刷TextureBrush

TextureBrush(IN Image* image,IN WrapMode wrapMode,IN const RectF &dstRect)为纹理画刷的构造函数

image:纹理对象指针

WrapMode:平铺模式

dstRect:图片纹理的加载区域

Graphics graphics(this->GetDC()->m_hDC);
Image image(L"texture.bmp");//加载图片资源
Gdiplus::TextureBrush tBrush(&image);//通过图片资源对象构造纹理画刷对象
RectF fillRect(10.0,10.0,100.0,100.0);//绘画区域
graphics.FillEllipse(&tBrush,fillRect);//用画刷画一个实心圆
Pen pen(&tBrush,10);//通过画刷构造画笔对象
RectF DrawRect(10.0,120.0,100.0,100.0);
graphics.DrawEllipse(&pen,DrawRect);//用画笔画一个空心圆

效果图:

GDI+学习记录之纹理画刷TextureBrush_第1张图片

结论1:画实心区域要用画刷和Graphics对象的Fill函数

结论2:画空心区域要用画笔和Graphics对象的Draw函数

图片纹理资源texture01.bmp原效果图:

Image sourceImage(L"texture01.bmp");
//创建一个截取图片纹理资源部分区域的画刷对象
Gdiplus::TextureBrush tLeftToTopBrush(&sourceImage,WrapModeTile,RectF(5.0,5.0,30.0,30.0));//截取左上角
graphics.FillEllipse(&tLeftToTopBrush,RectF(10.0,240.0,100,100));
Gdiplus::TextureBrush tRightToTop(&sourceImage,WrapModeTile,RectF(60.0,5.0,30.0,30.0));//截取右上角
graphics.FillEllipse(&tRightToTop,RectF(120.0,240,100,100));
Gdiplus::TextureBrush tLeftToBottomBrush(&sourceImage,WrapModeTile,RectF(5.0,60.0,30.0,30.0));//截取左下角
graphics.FillEllipse(&tLeftToBottomBrush,RectF(10.0,350.0,100.0,100.0));
Gdiplus::TextureBrush tRightToBottomBrush(&sourceImage,WrapModeTile,RectF(60.0,60.0,30.0,30.0));//截取右下角
graphics.FillEllipse(&tRightToBottomBrush,RectF(120.0,350.0,100.0,100.0));

显示效果图:

GDI+学习记录之纹理画刷TextureBrush_第2张图片

你可能感兴趣的:(gdi+)