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

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

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

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

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

76InBlock.gif
77ExpandedBlockEnd.gif        }

78 None.gif         public   bool  ThumbnailCallback()
79 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
80InBlock.gif            return false;
81ExpandedBlockEnd.gif        }

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

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值