18、文本的旋转显示
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g =e.Graphics;
g.SmoothingMode=SmoothingMode.AntiAlias;
//声明并初始化Graphics对象g
string tempstr = "Hello C#";
//取得要显示的文字
for(int i=0;i<361;i=i+10)
{
g.TranslateTransform(150, 150);
g.RotateTransform(i);
//将指定的旋转用于g的变换矩阵
//将指定的平移添加到g的变换矩阵前
Brush myBrush=Brushes.Blue;
g.DrawString(tempstr, this.Font, myBrush, 60, 0);
//显示旋转文字
g.ResetTransform();
//将g的全局变换矩阵重置为单位矩阵
}
}
19、阴影效果的文字
Graphics g=e.Graphics;
Font myFont;
myFont=new Font("SansSerif",40);
SolidBrush textShadowBrush = new SolidBrush(Color.FromArgb(70, Color.Blue));
g.DrawString("Hello C#",myFont,Brushes.Blue, 25, 25 );
g.DrawString("Hello C#",myFont,textShadowBrush, 30, 30);
20、图案填充的文字
Image textImage = new Bitmap("..\\..\\Texture.ICO");
TextureBrush textTextureBrush = new TextureBrush(textImage);
Font myFont=new Font("SansSerif",50);
e.Graphics.DrawString("Hello C#", myFont, textTextureBrush, 10, 20 );
21、将彩色图片转换为灰度图片
Bitmap bmp;
private void button1_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
bmp=new Bitmap(this.openFileDialog1.FileName);
for (int i=0;i<bmp.Width-1;i++)
{
for(int j=0;j<bmp.Height-1;j++)
{
Color Color1=bmp.GetPixel(i,j);
int rgb=(Color1.R+Color1.G+Color1.B)/3;
//颜色处理
bmp.SetPixel(i,j,Color.FromArgb(rgb,rgb,rgb));
}
}
this.pictureBox1.Image=bmp;
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.pictureBox1.SizeMode=PictureBoxSizeMode.StretchImage;
}
本系列文章是作者学习《Visual C#.NET 应用编程150例》(源码)心得笔记,欢迎转载,请注明原文地址,如有疑问,可以通过 278250658@qq.com 联系作者本人。