Display Individual Pixels in WPF - c#

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.

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!

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

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.

How to colour a transparent part of an image programmatically in .NET

I have an image created and saved manually as a file, which has a shape (e.g. a heart) that is transparent in the image, and the rest of the image has other colour. How to make the transparent shape with a specified colour programmatically in .NET, leaving the rest of the image untouched?
For example, provided is an image, which I want to fill transparent part with a colour.
http://www.sendspace.com/file/an53a1
It's transparent. So draw the background first in the color you want with Graphics.Clear(), then Graphics.DrawImage() to draw the image.
What you need is a flood fill algorithm.
Please take a look at this:
http://www.codeproject.com/KB/GDI-plus/floodfillincsharp.aspx

Drawing ListViewItem exceed VisibleClipBounds

I'm trying to manually draw ListViewItems on a Custom UserControl. The control itself is a wrapper around a ListView stored as a private member on the class.
There is a DrawListViewItemEventHandler attached to allow manual drawing for these items, and for the most part this seems to work. The problem I have is where the text for the ListViewItem (in large image mode) is long.
I'm drawing a bounding rectangle around the ListViewItem with various themes, and I then measure the size of the text using Graphics.MeasureString() and manually draw the text. However what I'm finding is that the vertical drawing is cropping at 2.5 lines of text, because the caption is falling outside of the VisibleClipBounds of the graphics context I have been passed.
It seems a bit of a strange but I'm not sure why such a thing should happen and can't figure out how to get around the problem.
You could use Tile view and TileSize to give yourself enough space to draw your text.
The ListView can't guarantee to draw all its text: the text could be huge.

Categories