All mighty TextureBrush.

wyrd

Well-known member
Joined
Aug 23, 2002
Messages
1,408
Location
California
I read that the TextureBrush is faster to draw images then a Bitmap, so I gave it a shot. It seems to crank out an extra 5 fps, but unfortunately I cant get it to work correctly. I have it set up like this;

TextureBrush brush = new TextureBrush(image, imageRect);

To draw the brush..

graphics.FillRectangle(brush, location.x, location.y, brush.width, brush.height);

I hope thats pretty self explanatory. The actual code is on another machine so I apologize.

Anyway.. when drawing the brush (graphics.FillRectangle()) in different locations (moving the x and y location coordinates) it seems to "wrap" the image.

I tried changing the WrapMode to WrapMode.Clamp, unfortunately it treated the image as if it was always located at coordinates 0, 0 and if I filled a rectangle away from those coordinates (ie; 100, 100) it wouldnt display anything.

Anyone have any idea what Im doing wrong?
 
I would suggest trying two things:

1st - try setting the Graphics Property "RenderingOrigin" to the "location"-Point...

2nd - set the "imageRect" to "new Rectangle(location, image.Size);" before you create the TextureBrush...

Hope this helps!

Andreas
 
okay.... this time I tested it ;-) :

Code:
TextureBrush brush = new TextureBrush(image, imageRect);

//if you already used the brush:
//brush.ResetTransform();
brush.TranslateTransform(location.X,location.Y);

graphics.FillRectangle(brush, new Rectangle(location, image.Size));

hope this helps!

andreas
 
Back
Top