How to make a resizeable rectangle selection tool?

前端 未结 4 506
夕颜
夕颜 2021-01-02 20:12

I\'m trying to write a very simple photo editor using C# 2008 or QT4.

How to make a resizeable rectangle selection tool like the photoshop did?

相关标签:
4条回答
  • 2021-01-02 20:54

    I don't know the specific calls, but the idea is this:

    You want to draw a transparent rectangle with an opaque or dotted border. The rectangle appears when the mouse button is clicked. While the button is held, the dimension of the rectangle will change as the mouse moves, with the top-left point at the position where the button was clicked and the bottom-right following the mouse as it moves. Releasing the button causes the rectangle to fix its position over the selection area.

    You should be able to figure out the particulars from a resource on the C# Drawing namespace.

    0 讨论(0)
  • 2021-01-02 20:56

    If you are talking about the "classic" "rubber band" type of selection rectangle, check out How to draw a rubber band rectangle or a focus rectangle in Visual C#.

    0 讨论(0)
  • 2021-01-02 21:08

    WPF Code Example: http://www.codeproject.com/KB/WPF/wpfmarchingants.aspx?display=Print

    This one is a bit more complicated because it involves image cropping, but if you scroll down to the selection rectangle, you can see the basic formulas for calculating the rectangle: http://69.10.233.10/KB/WPF/ImageCropper.aspx

    Lastly, another one using GDI: http://codelog.blogial.com/2008/10/31/rubber-band-selection-rectangle-in-c/

    If you provide more specifics, I'm sure we can help you out more.

    0 讨论(0)
  • 2021-01-02 21:09

    Qt has a class for that:

    http://doc.trolltech.com/4.5-snapshot/qrubberband.html

    0 讨论(0)
提交回复
热议问题