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?
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#.
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.
Qt has a class for that:
http://doc.trolltech.com/4.5-snapshot/qrubberband.html
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.
Related
In my WPF application I have a control that acts like a zoom box. You can zoom and drag its content. In my case this content is a grid that contains an image and some UserControls. These UserControls have to be positioned ontop of the image to highlight some segments of that image.
Here is an example (this is not an actual use case):
My question is, how should I position those red rectangles (what is the better practise here)?
By replacing the grid with a canvas and use Canvas.SetLeft resp. Canvas.SetTop?
or
By manipulating the RenderTransform of those rectangles?
Note: The rectangles are interactive (they have to interact with the mouse and maybe some other input devices).
I've built a drawing application for figures (ellipse, rectangle...), and I need a ruler on my canvas view that shows the position of the coordinates, something like this, just to show the user where is he drawing:
http://pe-images.s3.amazonaws.com/photo-effects/color-grid/first-guide.gif
How can I do that on XAML (WPF)? Maybe drawing a rectangle at the top and the left but dont know how to show the position numbers. Thank you!
I'm working on an image editor, there are some shape controls like rectangle, eclipse etc with drag drop feature on canvas and they are re-sizable(one corner is fixed, other three are re-sizable), attached a screen shot below:
I'd like to only resize the seleted corner, other three will be fixed, any ideas?
DaveRook Edit
In Photoshop, this is achieved by wrapping (under transforms)! This means re-drawing that corner un-proportionally to the rest of the image.
You will need to do a few things to achieve resizing of your rectangle.
a drag handle (something for the user to click and move).
to calculate the new height and width of your rectangle based upon the mouse position when the drag handle is being moved.
to update the height and width of the rectangle.
There is no shortcut here, but this SO question should be enough to get you started
How would I go about drawing a rectangle like this image?
(Notice rectangle slight grey in the middle)
Screenshot
I've got drawing Rectangles on Forms/PictureBox's ect but for the of me can't figure out how to do it over all your open applications.
Any feedback will be much appreciated
If you want just a border you can use ControlPaint.DrawReversibleFrame.
You need to create a window that is set to the size of the display. No border, no background. Basically, an invisible window. Then you can draw rectangles or whatever else you want and they will appear to be overlaid on top of other things.
Keep in mind you cannot keep this window open all the time as it will cover up everything else and prevent events from getting through. Open it as needed and then close it.
I have a silverlight application in which I have to click on some pictures, if I hover over them for 3 seconds approx.
The problem is that if the pictures are a bit small in size, and the mouse moves a little, it moves out of the respective picture clicking area and selects another picture.
I have tried using a custom image in place of the default mouse cursor, but can this mouse be enlarged in some way so that it has a larger clicking area under it and not only the tip of the mouse pointer?
I think you're thinking about this the wrong way around. The mouse pointer simply defines a coordinate on the screen, rather than an area. If you want mouseover/click etc to be more generous, and give a wider area of interaction, you should make the target area larger.
So in the case of some small image, you can surround it with a larger area to handle the mouseover or click events, for example by surrounding it by a transparent border (note that elements with a transparent background will receive mouse events, unlike elements with no background).