Bitmap.MakeTransparent 方法

使默认的透明颜色对此 Bitmap 透明。

重载列表

使默认的透明颜色对此 Bitmap 对象透明。

[Visual Basic] Overloads Public Sub MakeTransparent()
[C#] public void MakeTransparent();
[C++] public: void MakeTransparent();
[JScript] public function MakeTransparent();

使指定的颜色对此 Bitmap 对象透明。

[Visual Basic] Overloads Public Sub MakeTransparent(Color)
[C#] public void MakeTransparent(Color);
[C++] public: void MakeTransparent(Color);
[JScript] public function MakeTransparent(Color);
示例

[Visual Basic, C#] 下面的示例旨在用于 Windows 窗体,它需要 PaintEventArgs e(这是 Paint 事件处理程序的参数)。代码执行下列操作:

  • 获取 Bitmap 对象中像素的颜色。
  • 使该颜色对位图透明。
  • Bitmap 对象绘制到屏幕。
[Visual Basic, C#] 注意   此示例显示如何使用 MakeTransparent 的一个重载版本。有关其他可用示例,请参阅单独的重载主题。
[Visual Basic] 
Public Sub MakeTransparent_Example(e As PaintEventArgs)
' Create a Bitmap object from an image file.
Dim myBitmap As New Bitmap("Grapes.gif")
' Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _
myBitmap.Height)
' Get the color of a background pixel.
Dim backColor As Color = myBitmap.GetPixel(1, 1)
' Make backColor transparent for myBitmap.
myBitmap.MakeTransparent(backColor)
' Draw the transparent bitmap to the screen.
e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _
myBitmap.Height)
End Sub
        
[C#] 
public void MakeTransparent_Example(PaintEventArgs e)
{
// Create a Bitmap object from an image file.
Bitmap myBitmap = new Bitmap("Grapes.gif");
// Draw myBitmap to the screen.
e.Graphics.DrawImage(
myBitmap,
0,
0,
myBitmap.Width,
myBitmap.Height);
// Get the color of a background pixel.
Color backColor = myBitmap.GetPixel(1, 1);
// Make backColor transparent for myBitmap.
myBitmap.MakeTransparent(backColor);
// Draw the transparent bitmap to the screen.
e.Graphics.DrawImage(
myBitmap,
myBitmap.Width,
0,
myBitmap.Width,
myBitmap.Height);
}
        

[C++, JScript] 没有可用于 C++ 或 JScript 的示例。若要查看 Visual Basic 或 C# 示例,请单击页左上角的“语言筛选器”按钮 语言筛选器

请参见

Bitmap 类 | Bitmap 成员 | System.Drawing 命名空间

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值