Categories
Delphi

GDI+ TextureBrush paints image offset

The GDI plus TextureBrush renders The brush from the origin of the Graphics canvas that it is drawing to, so if you fill a rectange with a textured brush starting at 10,10 then the brush appears offset.
To ensure the top left corner of the image you have used in your texture brush starts at the same place onthe rectangle you are filling we need to set the brushes translation Transformation to the top left corner of the rectange to fill.
e.g
  ABrush  := TGPTextureBrush.Create(AImage,WrapModeTile);
  ABrush.TranslateTransform(x,y);
  AGraphics.FillRectangle(ABrush,x,y,width,height);
  ABrush.free;