随笔 - 2146  文章 - 97 评论 - 11758 trackbacks - 253

//正常显示图片, 没有变换
uses GDIPAPI, GDIPOBJ;

procedure TForm1.FormPaint(Sender: TObject);
var
  g: TGPGraphics;
  img: TGPImage;
begin
  g := TGPGraphics.Create(Canvas.Handle);
  img := TGPImage.Create('c:\temp\test.png'); {测试文件要存在}
  g.DrawImage(img, 0, 0, img.GetWidth, img.GetHeight);
  img.Free;
  g.Free;
end;

//效果图:

//添加颜色变换
uses GDIPAPI, GDIPOBJ;

procedure TForm1.FormPaint(Sender: TObject);
var
  g: TGPGraphics;
  img: TGPImage;
  imgAtt: TGPImageAttributes;
const
  ColorMatrix: TColorMatrix = (
    (1.0, 0.0, 0.0, 0.0, 0.0),
    (0.0, 1.0, 0.0, 0.0, 0.0),
    (0.0, 0.0, 1.0, 0.0, 0.0),
    (0.0, 0.0, 0.0, 1.0, 0.0),
    (1.0, 0.0, 0.0, 0.0, 1.0));
begin
  g := TGPGraphics.Create(Canvas.Handle);
  img := TGPImage.Create('c:\temp\test.png'); {测试文件要存在}

  imgAtt := TGPImageAttributes.Create;
  imgAtt.SetColorMatrix(colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeDefault);

  g.DrawImage(
    img,
    MakeRect(0,0,img.GetWidth,img.GetHeight),
    0,
    0,
    img.GetWidth,
    img.GetHeight,
    UnitPixel,
    imgAtt);

  imgAtt.Free;
  img.Free;
  g.Free;
end;

//效果图:

这个话题还有很多内容, 先弄这个例子算是给 M. Rokkaei 的回答.
posted on 2008-02-06 10:41 万一 阅读(...) 评论(...) 编辑 收藏