DotNet编程-星光伴我行

滴滴真谛 水滴石穿

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

                                              图像的绘制,剪切,旋转,添加文字.生成图像的缩略图        

 1 //按指定大小绘制图像 
 2        private void button1_Click(object sender, System.EventArgs e)
 3        {
 4            Bitmap myImage = new Bitmap(@"c:\11.jpg");
 5            Graphics g=this.pictureBox1.CreateGraphics();
 6            Pen            pen = new Pen(Color.FromArgb(000));
 7            int            width =this.pictureBox1.Width-100 ;
 8            int            height =this.pictureBox1.Height-100 ;
 9            int            x =2;
10            int            y =2;
11            //设定图像的绘制区域
12            g.DrawRectangle(pen, x - 1, y - 1, width + 1, height + 1);
13            //设定图像的绘制质量
14            g.InterpolationMode = InterpolationMode.HighQualityBilinear;
15            //绘制图像
16            g.DrawImage(myImage, x, y, width, height);
17            pen.Dispose();
18            
19        }
 
1
private void button2_Click(object sender, System.EventArgs e)
 2        {
 3            //以正常方式显示图片
 4            Bitmap myImage = new Bitmap(@"c:\11.jpg");
 5            Graphics g=this.pictureBox1.CreateGraphics();
 6            g.DrawImage(myImage, 2920); 
 7            //以旋转方式显示图片
 8           // g.Clear(Color.Yellow ) ;  //如果不清除将在上次的基础上绘制
 9            g.RotateTransform(-30);
10            g.DrawImage(myImage, 100380);
11            g.ResetTransform();
12
13            
14        
15        }

16
17        private void button3_Click(object sender, System.EventArgs e)
18        {
19            Bitmap myImage = new Bitmap(@"c:\11.jpg");
20            //设定一块显示区域
21            this.pictureBox1.Image =myImage;
22            //创建画布 
23            Graphics g=Graphics.FromImage (this.pictureBox1.Image  );
24            //设定要显示的字符
25            String drawString = "老婆你好!";
26            //设置字体与画刷
27            Font drawFont = new Font("隶书"20);
28            SolidBrush drawBrush = new SolidBrush(Color.Black);
29            //设定显示的区域
30            PointF drawPoint = new PointF(150.0F50.0F);
31            //设定字符串的格式
32            StringFormat drawFormat = new StringFormat();
33            drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
34            //绘制字符至屏幕
35            g.DrawString(drawString, drawFont, drawBrush, drawPoint, drawFormat);
36            drawPoint = new PointF(150.0F+120.0F , 50.0F+250.0F);
37            drawFont = new Font("隶书"10);
38            g.DrawString("furenjun", drawFont, drawBrush, drawPoint, drawFormat);
39            drawPoint = new PointF(150.0F+60.0F+120.0F , 50.0F+250.0F+50.0F);
40            drawFont = new Font("隶书"6);
41            g.DrawString(System.DateTime.Now.ToString ()   , drawFont, drawBrush, drawPoint, drawFormat);
42            //保存图像
43            this.pictureBox1.Refresh ();
44            this.pictureBox1.Image.Save(@"c:\mfu.jpg",System.Drawing.Imaging.ImageFormat.Jpeg );
45            
46
47
48        }

49
50        private void button4_Click(object sender, System.EventArgs e)
51        {
52            if (this.openFileDialog1.ShowDialog()==DialogResult.OK)
53            {
54                //获取图像
55                Bitmap myBitmap = new Bitmap(this.openFileDialog1.FileName  );
56                //设定图像剪切区域
57                RectangleF cloneRect = new RectangleF(00100100);
58                PixelFormat format = myBitmap.PixelFormat;
59                Bitmap cloneBitmap = myBitmap.Clone(cloneRect, format);
60                //绘制剪切的图像
61                Graphics g=this.pictureBox1.CreateGraphics();  
62                //                g.DrawImage(cloneBitmap, 0, 0);
63                
64                //生成图像的缩略图   
65                Image.GetThumbnailImageAbort myCallback =
66                    new Image.GetThumbnailImageAbort(ThumbnailCallback);
67                
68                Image myThumbnail = myBitmap.GetThumbnailImage(
69                    4060, myCallback, IntPtr.Zero);
70                this.pictureBox1.Image = myThumbnail;
71                //g.DrawImage(myThumbnail, 150, 75);
72                
73                MessageBox.Show( myBitmap.FrameDimensionsList.ToString() +"\n" +myBitmap.HorizontalResolution.ToString()    ) ;
74
75            }

76
77        }

78        public bool ThumbnailCallback()
79        {
80            return false;
81        }

1using System;
2using System.Drawing;
3using System.Collections;
4using System.ComponentModel;
5using System.Windows.Forms;
6using System.Data;
7using System.Drawing.Drawing2D;
8using System.Drawing.Imaging ; 

 

posted on 2005-12-05 12:46  DotNet编程  阅读(978)  评论(1编辑  收藏  举报