How to rotate the camera viewer in Windows phone? - c#

I use PhotoCamera option to take the snapshot. Once the Image capture is completed i set the VideoBrush to the Canvas in xaml. But the video viewer is actually rotated than the original... .I am not sure what might be the problem..
My code..
myCamera = new PhotoCamera(CameraType.Primary);
myCamera.CaptureImageAvailable += new EventHandler<ContentReadyEventArgs>(CameraCaptureImageAvailable);
VideoBrush videobrush = new VideoBrush();
videobrush.SetSource(myCamera);
canvasCameraView.Background = videobrush;
Can anyone help me ?

I found the solution that we can achieve through CompositeTransform...
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202956(v=vs.105).aspx

Related

Xamarin: How do I place an image on top of another image at a specific pixel location

I have an app I need to build with Xamarin for iOS. I'm using Xamarin.Forms at the moment.
The app is a custom view of a garden that I will need to place plant markers on in the admin at a touch. I cannot find a way to composite these images in a way I can drive the display from a database and make the markers clickable.
Any help or guidance is appreciated.
In this case you need to use AbsoluteLayout
var layout = new AbsoluteLayout();
var image = new Image { Source = "foo.png" };
AbsoluteLayout.SetLayoutBounds (image , new Rectangle (.5, 1, .5, .1));
//("X, Y, Width, Height")
layout.Children.Add (bottomLabel);
Content = layout;
here just a sample of placing image from c#, you can customize this to your requirement

How to play a video from the Internet in WPF?

I want to play a video from the Internet in WPF. I used the code below. It can play the video but it always breaks down and the speed is very slow. I don't know how to solve this problem.
mediaElement.MediaFailed += mediaElement_MediaFailed;
mediaElement.LoadedBehavior = MediaState.Play;
mediaElement.Source = new Uri(#"http://media2.neu6.edu.cn/hls/cctv6hd.m3u8", UriKind.Absolute);
As I understand this is a long term issue with Media Element itself. Try using WPFMediaKit
instead.

Display video with VlcDotNet library

I have made a C# Windows Forms Application in Visual Studio 2012 and added dlls from this webpage: http://vlcdotnet.codeplex.com/
I have already gotten video to work with this code:
VlcControl player = new VlcControl();
Vlc.DotNet.Core.Medias.MediaBase media = new
Vlc.DotNet.Core.Medias.PathMedia(#"path\movie.avi");
player.Media = media;
player.Play();
But that displays it in another window and I have no control over that. How would I embed the video in my form?
I have not found any documentation on how to do this programmatically. Most people in tutorials have some sort of vlc control listed in their toolbox, but I haven't, so I would need to do that with code.
I have tried using panel as VlcControl's parent:
player.Parent=panel1;
Movie still plays, but there is no video, only sound.
What kind of container should I use and how to make it show the video?
More information:
Here: VLC.DotNet Control Hosted in WPF it is said that it is possible to embed video inside WindowsFormsHost element in WPF. However, in Windows Forms Application, there is only ElementHost available to me. Could I use that to embed videos and if yes, how?
I have found the solution. I needed to add player to panel's controls and set the player size. Here it is, if anyone will ever need it:
player = new VlcControl();
panel1.Controls.Add(player);
player.BackColor = System.Drawing.Color.Black;
player.ImeMode = System.Windows.Forms.ImeMode.NoControl;
player.Location = new System.Drawing.Point(0, 0);
player.Name = "test";
player.Rate = 0.0F;
player.Size = new System.Drawing.Size(1024, 768);
Vlc.DotNet.Core.Medias.MediaBase media = new
Vlc.DotNet.Core.Medias.PathMedia(#"path\movie.avi");
player.Media = media;
player.Play();

How can i save UI Element as a image in Windows Phone 8?

Currently i'am developing app that will be possible to share image, with information take it of longlistselector as is showed in app, i'am trying save an ui element as a image, i don't know how can i achieve this task.
In android i realized that is possible to do this with getDrawingCache , but in windows phone 8 if is it possible?. I won´t to create new image with each element of LLS,
How can i save UI longlistselector as a image in windows phone?
I tried to do screen shoot of the current view, but not of all elements of LLS are visible.
Thanks in advance!.
Put this code to the Image where you want to render and apply as source
var writeableBitmap = new WriteableBitmap((int)YourLongListSelector.RenderSize.Width, (int)LongListSelector.RenderSize.Height);
writeableBitmap.Render(YourLongListSelector, new ScaleTransform() { ScaleX = 1, ScaleY = 1 });
writeableBitmap.Invalidate();
image.Source = writeableBitmap;

Drawing on Video within C#

I am making an application that will allow users to apply certain tools to analyse videos & images. I need help with how i actaully draw/write on the video loaded into windows media player within my form and being able to save it on. It needs to be able to lert the user draw freehand and shapes on it.
Thanks in Advance,
Chris :)
This is a non-trivial, if not impossible task to accomplish with the wmp control in winforms.
I don't know of any way to actually draw on the wmp but you could draw on a transparent panel overlaid over the wmp. This will not work will the video is playing but you can show the drawing while it is paused. I have used this technique to draw over a 3rd party video control that works similarly to wmp.(Edit - this does not seem to work with the wmp control)
However, as real transparent panels are also rather tricky in winforms, another way would be to grab an image from the video and draw on the overlaid image. Again, only when it is paused.
This commercial control does enable drawing over the video. It has an event that fires every frame that you can use to do the drawing. The big downside, though is that you can't really do anything too fancy as your drawing routine needs to finish before the next frame is drawn.
I would strongly encourage you to use WPF(even if its a wpf control hosted within a winforms app) to show your video. It is a whole lot easier to draw on video(including playing video) in wpf.
EDIT
I just tested drawing over the wmp using a transparent panel and its doesn't behave as my 3rd party control did,so I suggest you do the video playing bit in WPF and host that in your winforms app. (I just tested that too using #Callums inkcanvas suggestion and it works like a charm)
If you are using WPF, try placing an InkCanvas on top of your video and setting the Background to transparent. You can then save and load up the shapes the users draw on top of the video.
A little proof-of-concept with a picture instead of a video:
I suspect you may be using WinForms though, where this may be more difficult. If so, a good excuse to learn WPF!
EDIT: With WinForms, you would have to make your own custom control that acts as a transparent overlay and add brush strokes to it. It would be extremely hard to implement well (with transparent background, which doesn't play well with
WinForms). I would recommend using WPF if you are still at a stage you can change your application's UI. WPF works on XP and up.
EDIT2: After googling, there are some InkCanvas equivalents that people have made for WinForms, but I have no idea how good they are and may not support transparent backgrounds.
You could always have the video that you want annotated in a new WPF window and the rest of your application in WinForms.
I have found how to do this.
Here is one way in WPF using Canvas
private void buttonPlayVideo_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.Filter = "All Files|*.*";
Nullable<bool> result = dlg.ShowDialog();
if (result == true) {
MediaPlayer mp = new MediaPlayer();
mp.Open(new Uri(filename));
VideoDrawing vd = new VideoDrawing();
vd.Player = mp;
vd.Rect = new Rect(0, 0, 960, 540);
DrawingBrush db = new DrawingBrush(vd);
canvas.Background = db;
mp.Play();
}
}
then create mouse events for Canvas and draw with it
Point startPoint, endPoint;
private void canvas_MouseDown(object sender, MouseButtonEventArgs e)
{
startPoint = e.GetPosition(canvas);
}
private void canvas_MouseUp(object sender, MouseButtonEventArgs e)
{
endPoint = e.GetPosition(canvas);
Line myLine = new Line();
myLine.Stroke = System.Windows.Media.Brushes.LightSteelBlue;
myLine.X1 = startPoint.X;
myLine.Y1 = startPoint.Y;
myLine.X2 = endPoint.X;
myLine.Y2 = endPoint.Y;
myLine.HorizontalAlignment = HorizontalAlignment.Left;
myLine.VerticalAlignment = VerticalAlignment.Center;
myLine.StrokeThickness = 2;
canvas.Children.Add(myLine);
}
This can be done in WinForms but it is not easy. There is transparent form support with alpha blending in WinForms. Use the following CreateParams for the transparent overlay form: WS_EX_LAYERED, WS_EX_TRANSPARENT. Check the MSDN references for this type of window: http://msdn.microsoft.com/en-us/library/ms997507.aspx, http://msdn.microsoft.com/en-us/library/ms632599%28VS.85%29.aspx#layered.
Put a transparent form above your video control and you can draw anything you want on it. Move and resize events need to be coordinated between your video window and the transparent form above it. Redrawing the overlay needs to use UpdateLayeredWindow() in user32.dll.
I learned quite a bit from this example: http://www.codeproject.com/Articles/13558/AlphaGradientPanel-an-extended-panel.
You might look at XNA (www.xna.com) from Microsoft. It is made for managed languages like c# and should support video.
I've only used it for drawing in c#, but it gets the job done.
I should also note that XNA will function as part of a regular Windows Forms app. For what it's worth, I have also prototyped something like this with Flash; Flash allows you to import each frame of the movie file into the editor and create a SWF that can respond to user interaction.
However, this approach is useless if you need to update the movie in real-time. Flash (last I checked) could only import the movie at design time.
Ok, by far and away the best way of doing this is to use Silverlight. Silverlight supports all of the major streaming formats and also provides complete access to the framebuffer.
Easy :-)

Categories