C#用GDI+的alpha blending技术实现半透明效果的例子

收集了这么一个例子来
看上去AVG的文本框应该是用GDI+来写
directDraw不支持alpha blending
把代码贴一下~
这样半透明和文字都用GDI+解决了
听说效率不是很高,所以后面的图还是用ddraw来画
这些ddraw不支持的东西只能用效率低的选择
到时候把它实践一下,不知道效果好不好

ContractedBlock.gif ExpandedBlockStart.gif Code
 1 private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
 2 
 3 {
 4     Graphics g = this.CreateGraphics();
 5     g.Clear(this.BackColor);
 6     Image curImage = Image.FromFile(@"e:\photo.jpg");
 7     g.DrawImage(curImage, 00, curImage.Width, curImage.Height);
 8     g.Dispose();
 9 }
10 
11 private void button1_Click(object sender, System.EventArgs e)
12 {
13     Graphics g = this.CreateGraphics();
14     g.Clear(this.BackColor);
15     DrawPerson();
16     Bitmap bitmap = new Bitmap(@"e:\photo.jpg");
17     float[][] ptsArray =
18     new float[] {10000},
19     new float[] {01000},
20     new float[] {00100},
21     new float[] {0000.5f0}, //注意:此处为0.5f,图像为半透明
22     new float[] {00001}};
23     ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
24     ImageAttributes imgAttributes = new ImageAttributes();
25     //设置图像的颜色属性
26     imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default,
27     ColorAdjustType.Bitmap);
28     //画图像
29     g.DrawImage(bitmap, new Rectangle(00, bitmap.Width, bitmap.Height),
30         00, bitmap.Width, bitmap.Height,
31         GraphicsUnit.Pixel, imgAttributes);
32     g.Dispose();
33 }
34 
35 private void button2_Click(object sender, System.EventArgs e)
36 {
37     Graphics g = this.CreateGraphics();
38     g.Clear(this.BackColor);
39     DrawPerson();
40     Bitmap bitmap = new Bitmap(@"e:\photo.jpg");
41     float[][] ptsArray =
42         new float[] {10000},
43         new float[] {01000},
44         new float[] {00100},
45     new float[] {0000.1f0}, //注意:此处为0.1f,图像为强透明
46         new float[] {00001}};
47     ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
48     ImageAttributes imgAttributes = new ImageAttributes();
49     //设置图像的颜色属性
50     imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default,
51 ColorAdjustType.Bitmap);
52     //画图像
53     g.DrawImage(bitmap, new Rectangle(00, bitmap.Width, bitmap.Height),
54         00, bitmap.Width, bitmap.Height,
55         GraphicsUnit.Pixel, imgAttributes);
56     g.Dispose();
57 }
58 
59 private void button3_Click(object sender, System.EventArgs e)
60 {
61     Graphics g = this.CreateGraphics();
62     g.Clear(this.BackColor);
63     DrawPerson();
64     //画一幅图像 
65     Image curImage = Image.FromFile(@"e:\photo.jpg");
66     g.DrawImage(curImage, 00, curImage.Width, curImage.Height);
67     g.Dispose();
68 

转载于:https://www.cnblogs.com/dark_arthur/archive/2008/10/27/1320340.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值