zoukankan      html  css  js  c++  java
  • C#图像的拉伸与反转变换

     

    (2013-01-12 15:25:18)
    标签:

    c

    图像

    变换

    拉伸

    反转

    it

    分类: C#.NET
    例子:
    using System;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Drawing.Drawing2D;
    using System.Text;
    using System.Windows.Forms;
     
    namespace StretchAndReversalWindows
    {
        public partial class Form1 : Form
        {
            Bitmap myBitmap;
            int width, height;
            Graphics g;
     
            public Form1()
            {
                InitializeComponent();
                width = this.pictureBox1.Width;
                height = this.pictureBox1.Height;
                g = this.pictureBox1.CreateGraphics();
            }
     
            //选择图像
            private void buttonSelectFile_Click(object sender, EventArgs e)
            {
                OpenFileDialog openFile = new OpenFileDialog();
                openFile.Filter = "*.jpg;*.bmp|*.jpg;*.bmp;";
                if (openFile.ShowDialog() == DialogResult.OK)
                {
                    Bitmap srcBitmap = new Bitmap(openFile.FileName);
                    myBitmap = new Bitmap(srcBitmap, this.pictureBox1.Width, this.pictureBox1.Height);
                    this.pictureBox1.Image = myBitmap;
                }
            }
     
            //左到右拉伸
            private void buttonLeftToRight_Click(object sender, EventArgs e)
            {
                g = this.pictureBox1.CreateGraphics();
                g.Clear(this.BackColor);
                for (int x = 0; x <= width; x++)
                {
                    g.DrawImage(myBitmap, 0, 0, x, height);
                }
                g.Dispose();
            }
     
            //上到下拉伸
            private void buttonUpToDown_Click(object sender, EventArgs e)
            {
                g = this.pictureBox1.CreateGraphics();
                g.Clear(Color.Gray);
                for (int y = 0; y <= height; y++)
                {
                    g.DrawImage(myBitmap, 0, 0, width, y);
                }
                g.Dispose();
            }
     
            //中间向两边拉伸
            private void buttonMiddleToSide_Click(object sender, EventArgs e)
            {
                g = this.pictureBox1.CreateGraphics();
                g.Clear(Color.Gray);
                for (int y = 0; y < width / 2; y++)
                {
                    Rectangle DestRect = new Rectangle(width / 2 - y, 0, 2 * y, height);
                    Rectangle SrcRect = new Rectangle(0, 0, myBitmap.Width, myBitmap.Height);
                    g.DrawImage(myBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
                }
                g.Dispose();
            }
     
            //反转
            private void buttonReversal_Click(object sender, EventArgs e)
            {
                g = this.pictureBox1.CreateGraphics();
                g.Clear(this.BackColor);
                for (int x = -width / 2; x <= width; x++)
                {
                    Rectangle DestRect = new Rectangle(0 ,height / 2 - x, width, 2 * x);
                    Rectangle SrcRect = new Rectangle(0, 0, myBitmap.Width, myBitmap.Height);
                    g.DrawImage(myBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
                }
                g.Dispose();
            }
     
     
            //中间向四周扩散
            private void buttonExpand_Click(object sender, EventArgs e)
            {
                g = this.pictureBox1.CreateGraphics();
                g.Clear(this.BackColor);
                for(int x = 0; x <= width; x++)
                {
                    Rectangle DestRect = new Rectangle(width / 2 - x, height / 2 - x, 2 * x, 2 * x);
                    Rectangle SrcRect = new Rectangle(0, 0, myBitmap.Width, myBitmap.Height);
                    g.DrawImage(myBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
                }
                g.Dispose();
            }
        }
    }
     
    界面:

    C#图像的拉伸与反转变换

  • 相关阅读:
    vs2013运行qt.exe文件提示错误“找不到Qt5Cored.dll”
    基于stm32f1的lora开发基础通信实验
    vs出现找不到dll,重新安装程序可能会解决此问题
    C&C++&opencv文件操作
    出现无法解析的符号xxx(vs2013)
    opencv目标跟踪检测(C)
    vs运行出错:error MSB8020或error LNK1104: 无法打开文件“opencv_calib3d248d.lib/opencv_contribxxxd.lib”
    vs串口读写dll封装C++#(免费源码分享)
    stm32定时器操作配置()
    pwm控制ili9341背光屏幕亮度(stm32f4)
  • 原文地址:https://www.cnblogs.com/wahaccp/p/3225238.html
Copyright © 2011-2022 走看看