现在的位置: 首页 > 综合 > 正文

GDI+ 将图片背景设为透明

2012年09月22日 ⁄ 综合 ⁄ 共 672字 ⁄ 字号 评论关闭

ImageAttributes.SetColorKey Method( Color, Color, ColorAdjustType )

Sets the Color key ( transparency range )  for a specified category.

 

Namespace: System.Drawing.Imageing

Assembly: System.Drawing ( in System.Drawing.dll )

 

Syntax:

Public:

void SetColorKey(

Color colorLow,

Color colorHigh,

ColorAdjustType type

)

 

示例代码:

CString str;

 

str.Format(_T("%s"), moveinfo->picfilepath );  

Image image( str );

ImageAttributes imAtt;

imAtt.SetColorKey(

Color( 0, 0, 0),

Color( 0, 0, 0),

ColorAdjustTypeBitmap );

 

int iwidth,iheight;

iwidth = image.GetWidth();

iheight = image.GetHeight();

m_graphics.get()->DrawImage( &image, Rect(moveinfo->ptPosition.X - iwidth/2

, moveinfo->ptPosition.Y - iheight/2, iwidth, iheight), 0,0,iwidth,iheight,UnitPixel, &imAtt );

 

抱歉!评论已关闭.