我本来以为是Graphics.RenderingOrigin的问题,由此写了一篇blog,见http://www.cnblogs.com/xingd/archive/2005/02/02/100954.html。
但经过mikespook和我的试验后,发现RenderingOrigin只针对HatchBrush起作用,不会影响TextureBrush的Origin位置,对于TextureBrush,如果希望其使用的图片的(0,0)的点位于输出位置的起点,可以使用如下的代码:
TextureBrush是支持Matrix变换的,所以使用TranslateTransform就可以影响其Origin位置。
将TextureBrush.WrapMode置为WrapMode.Tile时,可以实现平铺的效果,可以通过一次FillRectangle的调用为一个大的区域绘制出指定图像的平铺效果,这要比使用Bitmap配合DrawImage要快得多。以下是从一个论坛中看到的使用FillRectanlge+TextureBrush代替Bitmap+DrawImage的效果“Got another 10 fps out of my game."
TextureBrush.WrapMode除了Tile之外,还有其他的枚举值,可以实现图像翻传等效果。在TextureBrush的构造函数中,还可以支持传入ImageAttributes,可以对图像进行多种功能强大的处理。ImageAttributes的一些方法如下:
| SetBrushRemapTable | Sets the color-remap table for the brush category. |
| SetColorKey
Supported by the .NET Compact Framework. |
Overloaded. Sets the color key (transparency range). |
| SetColorMatrices | Overloaded. Sets the color-adjustment matrix and the grayscale-adjustment matrix. |
| SetColorMatrix | Overloaded. Sets the color-adjustment matrix. |
| SetGamma | Overloaded. Sets the gamma value. |
| SetNoOp | Overloaded. Turns off color adjustment. |
| SetOutputChannel | Overloaded. Sets the CMYK output channel. |
| SetOutputChannelColorProfile | Overloaded. Sets the output channel color-profile file. |
| SetRemapTable | Overloaded. Sets the color-remap table. |
| SetThreshold | Overloaded. Sets the threshold (transparency range). |
| SetWrapMode | Overloaded. Sets the wrap mode. |