WPF integrating with a web cam and rotating the video - wpf

is this possible?

Once you have got the video displayed (see your previous question), set the display element's LayoutTransform or RenderTransform to a suitable RotateTransform. If you wish to flip the video instead, use a ScaleTransform with a negative scale. If you wish to do both, use a TransformGroup containing both a ScaleTransform and a RotateTransform.

Check out the WPF MediaKit, which has code for webcams. You can use standard WPF transforms to do your rotating.

Related

How to easily change the layout of the screen from Portrait to Landscape and vice versa in WPF

Let's suppose we have the designed the layout of some WPF application to be used on standard Full HD screen 1920x1080. Then we need to rotate the screen and install it in a box that is mounted on kiosk PC but in Portrait orientation.
I need to find a way on how to rotate the screen easily or at least in some more elegant way.
I tried to use use RenderTransform and RotateTransform applied to the contents of the window but this rotates the image and of course not the layout.
The controls remain of the same width and height.
Is there a way to do it automatically or should I take each control and change it properties one by one ?
The problem is present for TextBlocks and TextBoxes. They are intended to be used horizontally. You can rotate it but the layout is calculated based to it's horizontal width.
BTW. Rotation of the entire window is not allowed. It throws an exception.
It looks like that I have found the solution myself. If we choose the Layout transform instead of RenderTransform then the visual system does the arrangement and measurement of the layout automatically before the rendering.
The WPF framework does the job in this order
LayoutTransform
Measure
Arrange
RenderTransform
Render
This is best described here LAYOUTTRANSFORM VS. RENDERTRANSFORM - WHAT'S THE DIFFERENCE?

Drawing shapes, text and images with moving and scaling in WPF

I'm trying to draw simple map in WPF. I need to draw shapes, text and images. It also should be possible to use mouse to move around and zoom in and out.
Right now, I have combination of Canvas + Geometry + Transforms to draw shapes, but I don't know how to add text and images.
I already tried various combination of Canvas/Grid and Layout/Render transform. Biggest problem is adding text and images, because transformations are in geometries.
If i understand you right, you're currently putting Path objects (with transformed Geometries) into a Canvas. For adding text and images you could easily add TextBlock and Image objects to the same Canvas and apply your transformations to their RenderTransform property.
A completely different approach would be to use WPF low-level rendering, provided by the DrawingVisual class. You may start at WPF Graphics Rendering Overview.

silverlight image control brightness and contrast

Does anyone know how to apply brightness and contrast control to an Image in silverlight 5? Maybe using UIElement.Effect? I don't need to modify/save the image, just change how it is displayed.
Use a WriteableBitmap as source for your image and then apply a brightness/contrast formula on every pixel of the WriteableBitmap.
You need to call Invalidate() on your bitmap instance after you have changed the pixels.
I ended up using a Custom Pixel Shader. Shazzam has a contrast adjust custom pixel shader in it's pre-installed samples. The beauty of this is that it works in both WPF and silverlight.

Change Alpha Blend Mode in WPF?

The System.Drawing.Graphics class has a property CompositionMode with two options: SourceOver (which, based on the alpha component, blends whatever is drawn with the background already existing) or SourceCopy which simply overwrites the background with whatever is being drawn.
Does something similar exist in WPF?
In WPF when i draw a PolyLine for example on top of another the new PolyLine always alphablends with the background. I think that is independent of the container being used. I am using a Canvas but could not find a blend mode property anywhere. What I want to do is what the SourceCopy compositionmode mentioned above does. I.e. the new PolyLine should simply overwrite whatever is already on the Canvas.
Is there a simple way to do that, short of using pixel shaders (which - as far as I understand - wouldn't work anyways because I don't have access to the Canvas backbuffer).
I am not stuck with a Canvas and would be happy to use any container that supports overwrite mode.
I currently have a solution based on a WriteableBitmap for which I obtain a System.Drawing.Graphics context and then manipulate the CompositionMode. It works but since my window is fullscreen that solution has serious performance impacts.
Clarification and example:
The WPF window is fully transparent and so is the Canvas (back ground color(0,0,0,0)). Now I draw a PolyLine with a Color.FromArgb(128,128,0,0). I now have a semi-transparent red polyline. Next I draw the same PolyLine with Color.FromArgb(0,0,0,0). The result is the same as before because of the alpha blending taking place. What I want, however, is that the red polyline is erased with the second polyline (which is exactly what the SourceCopy mode in the Graphics class does.
I think all you need to do is make sure that the brushes used to fill/stroke the PolyLine have fully opaque alpha values (i.e. 255). Then the background shouldn't be blended into it.
You could apply a Clipping Mask, this way you can provide the path to clip over the elements that are below it, but it might be tough to maintain after a lot elements are required to be clipped...

silverlight: reflection effect

I've seen examples in silverlight where the achieve a effect using 1 of 2 ways:
Two image objects, both
displaying the same image, but the
bottom one rotating it 180 degrees
and applying a gradient image
opacity
A MediaElement object and a VideoBrush element.
I have a series of path objects, rectanges, etc which I would like to apply a reflection affect to. Is there a more elegant solution other than copying my objects manually and rotating them? Unfortunately the VideoBrush object only works on MediaElement objects, but is there something else I can use?
Not in Silverlight, in WPF you have a VisualBrush which can help with this but Silverlight doesn't have one in version 2. Just to be clear though, it's not a rotation it's a negative ScaleY on a ScaleTransform. The easiest thing is to put everything into a UserControl and then use two UserControls with one having a ScaleTransform and an OpacityMask on it.
For a good example, please see the following blog post from Mike Snow.
http://silverlight.net/blogs/msnow/archive/2008/09/04/silverlight-tip-of-the-day-36-how-to-create-reflections-and-shadows-for-images-and-text.aspx

Resources