GDI+ 学习记录(31): 图像颜色变换(TGPImageAttributes)


//正常显示图片, 没有变换

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;


 
   
//效果图:
GDI+ 学习记录(31): 图像颜色变换(TGPImageAttributes)

//添加颜色变换

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;


 
   
//效果图:
GDI+ 学习记录(31): 图像颜色变换(TGPImageAttributes)
这个话题还有很多内容, 先弄这个例子算是给 M. Rokkaei 的回答.

你可能感兴趣的:(attribute)