Show coordinates (or ruler) on my Canvas - c#

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!

Related

Tranlate Imagebox Pixel position to Window position

So I am using WinForms to create an application that needs to render overlays at certain image positions. For that, I need to translate pixel positions on a PictureBox to a position in the Window so I can draw a textbox at that location. The stuff is inside a "TabPane" element from Devexpress, which is treated as a panel. I first tried to use relative positioning from the center of the image, but that never worked. I could not find any information on the internet.
Any helpful ideas would be helpful and appreciated!

Snap to pixel integrating Win2D

Is there a way to implement pixel snapping in UWP from code behind ?
I know XAML controls in UWP automatically do this, but I'm using a thir party library, Win2D, to draw some lines, and pixel snapping is not default.
Aligning these lines with the rest of the interface is a pain. I need to align some vertical borders drawn with Win2D with the pixel snapped vertical borders of some cells drawn inside a XAML horizontal ListView.
What I would need would be a way to get the exact X and Y coordinates of the closest pixel. I need to draw a vertical / horizontal line with Win2D.DrawLine from A to B and I need to snap to pixels to prevent antialising and to align with a XAML Border.
This is picture of the actual issue. The lower raw is drawn with Win2d, The upper raw is the table header and is drawn with XAML controls.
I need a way to snap to pixel the lines drawn with Win2D just as XAML does this.
I got the exact coordinates of the items I needed to align to using this sample:
Absolute coordinates of UIElement in WinRT
Then I have simply drawn the lines to the exact coordinates.
The alternative to your own answer might be to draw just these lines using XAML.

Resize rectangle corner

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

Draw a overlaying rectangle (example)

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.

How to make a resizeable rectangle selection tool?

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.

Categories