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


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

     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 ; 
  • 相关阅读:
    Python2和3版本对str和bytes类型的处理
    使用Fiddle对夜神模拟器进行抓包的设置
    WebSocket 实现链接 群聊(low low low 版本)
    WebSocket 实现链接 发送消息
    Linux文件操作命令
    Linux命令格式
    FastJson
    JSON语法规则
    Mybatis resultMap支持继承
    Mybatis在xml文件中处理大于号小于号的方法
  • 原文地址:https://www.cnblogs.com/furenjun/p/290858.html
Copyright © 2020-2023  润新知