• 大小: 141KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-06-12
  • 语言: C#
  • 标签: C#  图形学  线段裁剪  

资源简介

线段裁剪,使用Cohen-Sutherland算法。能基本实现单步动画效果。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
namespace 线段裁剪
{
    
    public partial class Main : Form
    {
        bool flag = false;
        bool stepFlag = false;
        Bitmap image;
        Graphics g;
        Point cut_box_start_p;
        Point cut_box_end_p;
        Point line_start_p;
        Point line_end_p;
        const int RECTANGLE = 0;
        const int LINE = 1;
        const int DRAWLINE = 0;
        const int DRAWCUTBOX = 1;
        int currentDrawMode = -1;
        const int LEFT = 1;
        const int RIGHT = 2;
        const int BOTTOM = 4;
        const int TOP = 8;
        ArrayList lines;
        Thread line_clip_thread;
        public Main()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
            int image_width = pictureBox1.Width;
            int image_height = pictureBox1.Height;
            image = new Bitmap(image_width image_height);
            g = Graphics.FromImage(image);
            pictureBox1.Image = image;
            cut_box_start_p = new Point();
            cut_box_end_p = new Point();
            lines = new ArrayList();

        }

        private void groupBox1_Enter(object sender EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender EventArgs e)
        {

        }

        private void pictureBox1_MouseMove(object sender MouseEventArgs e)
        {
            int x = e.X;
            int y = e.Y;
            txtCurrPos.Text = x + ““ + y;
            
        }

        private void pictureBox1_MouseDown(object sender MouseEventArgs e)
        {
            if (flag == false)
            {
                currentDrawMode = DRAWCUTBOX;
                flag = true;
            }
            else currentDrawMode = DRAWLINE;
            if (currentDrawMode == DRAWCUTBOX)
            {
                cut_box_start_p = e.Location;
            }
            else if (currentDrawMode == DRAWLINE)
            {
                line_start_p = e.Location;
            }
        }

        private void pictureBox1_MouseUp(object sender MouseEventArgs e)
        {
            
            if (currentDrawMode == DRAWCUTBOX)
            {
                cut_box_end_p = e.Location;
                my_draw(DRAWLINE);
            }
            else if (currentDrawMode == DRAWLINE)
            {
                line_end_p = e.Location;
                my_draw(LINE);
            }
            
        }

        private void pictureboxRefresh()
        {
            pictureBox1.Refresh();
        }


        private void my_draw(int x)
        {
            if (x == RECTANGLE)
            {
                int width = M

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-02-03 20:49  线段裁剪\.svn\
     文件         418  2011-02-03 20:49  线段裁剪\.svn\all-wcprops
     文件         571  2011-02-03 20:49  线段裁剪\.svn\entries
     目录           0  2011-01-25 13:19  线段裁剪\.svn\prop-base\
     文件          53  2011-01-25 13:19  线段裁剪\.svn\prop-base\线段裁剪.suo.svn-base
     目录           0  2011-01-25 13:19  线段裁剪\.svn\props\
     目录           0  2011-02-03 20:49  线段裁剪\.svn\text-base\
     文件         878  2011-01-25 13:19  线段裁剪\.svn\text-base\线段裁剪.sln.svn-base
     文件       24064  2011-02-03 20:49  线段裁剪\.svn\text-base\线段裁剪.suo.svn-base
     目录           0  2011-02-03 20:49  线段裁剪\.svn\tmp\
     目录           0  2011-01-25 13:19  线段裁剪\.svn\tmp\prop-base\
     目录           0  2011-01-25 13:19  线段裁剪\.svn\tmp\props\
     目录           0  2011-02-03 20:49  线段裁剪\.svn\tmp\text-base\
     文件          30  2011-03-01 16:43  线段裁剪\README.txt
     文件         878  2011-01-25 13:19  线段裁剪\线段裁剪.sln
     文件       28672  2011-02-23 15:32  线段裁剪\线段裁剪.suo
     目录           0  2011-01-25 13:19  线段裁剪\线段裁剪\
     目录           0  2011-01-25 13:22  线段裁剪\线段裁剪\.svn\
     文件         983  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\all-wcprops
     文件        1064  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\entries
     目录           0  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\prop-base\
     目录           0  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\props\
     目录           0  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\text-base\
     文件       11637  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\text-base\Main.cs.svn-base
     文件        7963  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\text-base\Main.Designer.cs.svn-base
     文件        6011  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\text-base\Main.resx.svn-base
     文件         492  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\text-base\Program.cs.svn-base
     文件        3678  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\text-base\线段裁剪.csproj.svn-base
     目录           0  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\tmp\
     目录           0  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\tmp\prop-base\
     目录           0  2011-01-25 13:19  线段裁剪\线段裁剪\.svn\tmp\props\
............此处省略144个文件信息

评论

共有 条评论