收集了这么一个例子来
看上去AVG的文本框应该是用GDI+来写
directDraw不支持alpha blending
把代码贴一下~
这样半透明和文字都用GDI+解决了
听说效率不是很高,所以后面的图还是用ddraw来画
这些ddraw不支持的东西只能用效率低的选择
到时候把它实践一下,不知道效果好不好
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, 0, 0, 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[] {1, 0, 0, 0, 0},
19 new float[] {0, 1, 0, 0, 0},
20 new float[] {0, 0, 1, 0, 0},
21 new float[] {0, 0, 0, 0.5f, 0}, //注意:此处为0.5f,图像为半透明
22 new float[] {0, 0, 0, 0, 1}};
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(0, 0, bitmap.Width, bitmap.Height),
30 0, 0, 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[] {1, 0, 0, 0, 0},
43 new float[] {0, 1, 0, 0, 0},
44 new float[] {0, 0, 1, 0, 0},
45 new float[] {0, 0, 0, 0.1f, 0}, //注意:此处为0.1f,图像为强透明
46 new float[] {0, 0, 0, 0, 1}};
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(0, 0, bitmap.Width, bitmap.Height),
54 0, 0, 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, 0, 0, curImage.Width, curImage.Height);
67 g.Dispose();
68
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, 0, 0, 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[] {1, 0, 0, 0, 0},
19 new float[] {0, 1, 0, 0, 0},
20 new float[] {0, 0, 1, 0, 0},
21 new float[] {0, 0, 0, 0.5f, 0}, //注意:此处为0.5f,图像为半透明
22 new float[] {0, 0, 0, 0, 1}};
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(0, 0, bitmap.Width, bitmap.Height),
30 0, 0, 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[] {1, 0, 0, 0, 0},
43 new float[] {0, 1, 0, 0, 0},
44 new float[] {0, 0, 1, 0, 0},
45 new float[] {0, 0, 0, 0.1f, 0}, //注意:此处为0.1f,图像为强透明
46 new float[] {0, 0, 0, 0, 1}};
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(0, 0, bitmap.Width, bitmap.Height),
54 0, 0, 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, 0, 0, curImage.Width, curImage.Height);
67 g.Dispose();
68