Scale Bar in C# WPF with EMGU - c#

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

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!

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!

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.

How to display images on top of each other using C# (Forms or WPF)?

I need to display images on top of each other. This can either be a composite\layered image or separate images. This will typically be a larger image with smaller images on top. With the composite\layered approach the smaller images would each need to be a separate (and accessible) layer. With the separate images approach the smaller images are on top with a transparent background. With either approach the smaller images must be accessible i.e. can be moved (dragged) or deleted. The app needs to display these images together (as if it was one image) and keep track of the coordinates (position) of the smaller images.
The current (proof-of-concept) solution has a PictureBox control that displays the large image and a treeview. Nodes are dragged from the treeview to the picture box and rendered using the graphics DrawString or DrawImage methods – these draw the smaller images. The problem is that once the smaller image is drawn I cannot get back to it as a separate graphics object. The picture box “sees” it as part of the current image.
I need to do this in C# (WinForms or WPF). And the image type must be a common and open format i.e. not proprietary. Preferably no 3rd party controls.
Any suggestions\guidance?
WPF would be the technology of my choice for this project.
Drag & Drop way nicer, without flickering, better concept
Rendering directly on HW, way smoother for image manipulation
General idea of the implementation:
MVVM pattern
ViewModel holding your layer information
ItemsControl bound to the collection of Small overlay Images holding a DataTemplate which visualizes the images thour custom UserControl based on a Thumb (for drag & drop functionality) displayes the small images on top.
Easy to add functionality to drag, edit, hide each small image seperately.
The problem is that once the smaller image is drawn I cannot get back
to it as a separate graphics object. The picture box “sees” it as part
of the current image.
That behaviour is perfectly normal. GDI drawing does not work with objects. To do what you are asking, you need to track any event that can cause a change in the final image and when such an event occur, you need to draw the whole image from the begining, including the first image (assigning the background image, I guess).
May be create picture box per image. The transparent background will give the effect of single image.

Display Individual Pixels in WPF

I have an application that needs to highlight individual pixels on an image. I don't want to edit the image, I just want to temporarily display red dots on top of certain pixels in the image. So far I have been using a Canvas to draw a whole lot of really small rectangles to highlight those pixels, but that has performance issues, and I was wanting to know if there was a better way to do it.
You can place another image layer over the original one with a transparent background and simply put red pixels on it.

Categories