mikespook在他的blog中提到了Graphics.FillRectanle使用TextureBrush里的图象位置问题,原文见http://www.cnblogs.com/mikespook/archive/2005/01/31/99912.html
  
  我本来以为是Graphics.RenderingOrigin的问题,由此写了一篇blog,见http://www.cnblogs.com/xingd/archive/2005/02/02/100954.html
  
  但经过mikespook和我的试验后,发现RenderingOrigin只针对HatchBrush起作用,不会影响TextureBrush的Origin位置,对于TextureBrush,如果希望其使用的图片的(0,0)的点位于输出位置的起点,可以使用如下的代码:
TextureBrush与Imageusing (Image image = Image.FromFile(@"e:\pic.jpg"))
{
TextureBrush与Image    
using (TextureBrush brush = new TextureBrush(image))
{
TextureBrush与Image        brush.TranslateTransform(x, y);
TextureBrush与Image        g.FillRectangle(brush, x, y, image.Width, image.Height); 
TextureBrush与Image        g.Restore(state); 
TextureBrush与Image    }

TextureBrush与Image}

  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.

相关文章:

  • 2021-12-22
  • 2022-12-23
  • 2021-09-09
  • 2021-07-11
  • 2021-08-12
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-24
  • 2021-09-20
  • 2021-12-16
  • 2022-01-25
  • 2022-12-23
  • 2021-08-11
相关资源
相似解决方案