zoukankan      html  css  js  c++  java
  • 贝塞尔曲线控件 for .NET (EN)

    Conmajia 2012
    Updated on Feb. 18, 2018

    In Photoshop, there is a very powerful feature Curve Adjust, as shown in figure 1.

    figure 1 Curve Adjust in Photoshop

    You can adjust image parameters by adding, deleting or dragging nodes of the image curve.

    Basically, such a curve is simple to implement:

    • A curve is presented by a series of points which are called nodes
    • Each node is an adjustable handle
    • Mouse events handlers for each node

    Detailed design procedure is omitted. The result is show in figure 2:


    figure 2 Animated Example

    Sample Codes

    The Node list.

    List<Point> points;
    

    Deal with node handlers.

    Rectangle getHandle(Point p)
    {
        Rectangle rect = new Rectangle(
            p.X - 3,
            p.Y - 3,
            6,
            6);
        return rect;
    }
    

    Check for mouse position.

    bool isHandle(Point p)
    {
        foreach (Point pt in points)
        {
            if (isInside(p, getHandle(pt)))
            {
                downIndex = points.IndexOf(pt);
                downPoint = pt;
                current = pt;
                return true;
            }
        }
    
        return false;
    }
    

    Draw handlers.

    void drawHandle(Graphics g, Point p)
    {
        if (points.IndexOf(p) == downIndex)
            g.FillRectangle(
                Brushes.Black,
                getHandle(p));
        else
            g.DrawRectangle(
                Pens.Black,
                getHandle(p));
    }
    

    Draw the curve.

    void drawCurve(Graphics g)
    {
        g.DrawCurve(Pens.Black, points.ToArray());
    }
    

    Total sample source code: download

    The End. (Box)

  • 相关阅读:
    前端PC人脸识别登录
    html2canvas 轮播保存每个图片内容
    基于Element的下拉框,多选框的封装
    聊聊 HTTPS
    从 rails 窥探 web 全栈开发(零)
    理解 Angular 服务
    Vue3 与依赖注入
    一次 HTTP 请求就需要一次 TCP 连接吗?
    GO 语言入门(一)
    读 Angular 代码风格指南
  • 原文地址:https://www.cnblogs.com/conmajia/p/8452407.html
Copyright © 2011-2022 走看看