Tranlate Imagebox Pixel position to Window position - c#

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!

Related

How can I XOR an image onto another image in WPF (C#)?

I'm writing an application where I need a crosshair cursor to pick points on an arbitrary image. Being as the image may contain both light and dark regions, I'm looking to XOR the cursor on top of the image, thus inverting the colours of the pixels where the cursor lies. In order to illustrate what I mean, please see the following image...
My application will be written using WPF and C#.NET. The image will be displayed in a Canvas within a ScrollViewer, where the cursor will be contained within a .png file. The cursor image file contains a white cursor on a black background so that it will produce the correct results once it's "blitted" onto the image with an XOR operation. I've also gone with the approach of having the cursor as an image file because I will need to show instances of the cursor at selected points within the image.
Of course, another important requirement is that the drawing operation should run as fast as possible, as it's basically a cursor that will move constantly as the user moves the mouse.
Thanks in advance!

Show coordinates (or ruler) on my Canvas

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!

Scale Bar in C# WPF with EMGU

Is it possible to overlay a scale bar into an image been displayed in WPF using EMGU like in the following picture?
Or like in Bing Maps.
I have images that are 1024x600 size, and I want to display on the image the scale of scale bar (I know the pixel size).
For example in the above image I would like to overlay to my image a green line and say that this line is 5cm.
I know how to do the calculations that relate the length of the line to the actual dimensions, however I don't know how to create that scale bar and overlay it on top of the image.
Any information about what approach I shall follow would be welcome!
Thank you.
In WPF I have found the easiest way to do this is to use your image as the background of a Canvas control. Canvas controls allow the placement of any control anywhere on the canvas. I am using a similar technique in a product we are developing.
Doug

Image resizing relative to image center

I am currently working on a project based on Kinect and I can't find a way how to resize the image relative to the image center. I managed to update image width and height as I move my hands and I get the picture resized, but relative to the TopLeft corner. So, basically if you imagine a rectangle, the top left corner is always fixed, while other corners move. The picture resizes only in the directions from right to left and from bottom to top.
I first tried to use ScaleTransform to resize the image and there i could specify the transform origin ( which I was setting in the middle of the picture), but it does not allow to update the image size in the result... so it makes no use to me..
So, if anyone could give my some sort of an idea of how to approach the task of resizing in all directions dynamically I would be very grateful. Maybe there is some way how to set the point to a different value than top left?
Thanks in advance!
You can use RenderTransformOrigin to move the center point of a scale action. For example:
<Setter Property="RenderTransformOrigin" Value="0.5, 0.5" />
I had a similar question related to resizing on a DP from the center of a UserControl. The discovery of how to resize from the center of the object is mentioned in one of the comments of the accepted answer.
Growing UserControl Size with Style Trigger?

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