IGPTextureBrush 对应的 TGPTextureBrush 类的 Create 方法有很多重载.

参数中可有 TGPWrapMode 和 IGPImageAttributes, 但测试中发现 IGPImageAttributes 在这里并不好用.

比较有意义是: 可以从建立参数中指定原始图片的范围.

测试效果图:



uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Image: IGPImage;
  Brush1, Brush2: IGPTextureBrush;
  Rect, DstRect: TGPRectF;
  Graphics: IGPGraphics;
begin
  Image := TGPImage.Create('C:\GdiPlusImg\Apple.gif');
  Rect.Initialize(0, 0, 270, 300);
  DstRect.Initialize(0, 0, Image.Width * 0.6, Image.Height * 0.6);

  Brush1 := TGPTextureBrush.Create(Image);
  Brush2 := TGPTextureBrush.Create(Image, DstRect); //只使用原始图片的一部分

  Graphics := TGPGraphics.Create(Canvas.Handle);
  Graphics.Clear($FF008000);

  Graphics.FillRectangle(Brush1, Rect);
  Rect.X := Rect.X + Rect.Width + 20;
  Graphics.FillRectangle(Brush2, Rect);
end;

posted on 2009-12-14 01:49  万一  阅读(1801)  评论(1编辑  收藏  举报