I am developing a Selfie Cam App for Windows Phone 8, I don't want to use the PhotoCamera library and Video Brush etc... to manually get the front facing cam.
I want to use the CameraCaptureTask to show the camera. As all know better, that when we launch the CameraCaptureTask, it shows the Primery(Back) camera, but I need that when the Task launch it shows the Front Facing Cam first.
Plz help in this regards.
CameraCapture task don't have option to select front-facing camera.
you've to write your own code to Launch front-facing camera by default.
Possibilities:
CameraCaptureTask is WP8 API, and i don't think that Microsoft is going to provide any option in future with CameraCaptureTask.
But in WP8.1 (wp Store apps), there are no alternative for CameraCaptureTask yet, so in future Microsoft might come out with something similar to CameraCaptureTask which might contain option to launch front-facing camera by default.
Edit:
Capture Image/Video with exact orientation:-
If you're facing issue of image capture orientation while capturing image or recording video, you should have to rotate the VideoBrush to 90 degree. So that the recorded video/Image will be captured as you wish.
Check the code for this function.
You need to edit the XAML code where you've created the VideoBrush control.
<Canvas x:Name="CanvasLayoutRoot" Background="Transparent">
<!--Camera viewfinder >-->
<Rectangle x:Name="viewfinderRectangle"
Width="{Binding ActualHeight, ElementName=CanvasLayoutRoot}"
Height="{Binding ActualWidth, ElementName=CanvasLayoutRoot}"
RenderTransformOrigin="0.5 0.5" Margin="-144 145" >
<Rectangle.RenderTransform>
<CompositeTransform Rotation="90"/>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
Here main thing to notice is <Rectangle.RenderTransform> part and two tags RenderTransformOrigin="0.5 0.5" and Margin="-144 145" of control.
after setting the UI, assign VideoCaptureDevice to rectangle and you're done..!!
Hope that helps..
Related
I am trying to display a GIF file stored in a Windows Phone 8.1 (RT) application's local folder. Until now, I have tried several approaches:
Load the GIF in a WebView control. This is not a solution since I want to display the images in a FlipView control (I cannot flip to another image). Also, it is quite slow.
Get the GIF frames using the BitmapDecoder class and animate them using a storyboard.
The code is as follows:
using (var stream = await storageFile.OpenReadAsync())
{
//I don't specify the type since I would like to load other type of images also
//It doesn't make any difference if I would use "BitmapDecoder.GifDecoderId"
var decoder = await BitmapDecoder.CreateAsync(stream);
uint frameCount = decoder.FrameCount;
for (uint frameIndex = 0; frameIndex < frameCount; frameIndex++)
{
var frame = await decoder.GetFrameAsync(frameIndex);
var writableBitmap = new WriteableBitmap((int)decoder.OrientedPixelWidth,
(int)decoder.OrientedPixelHeight);
var pixelDataProvider = await frame.GetPixelDataAsync
(BitmapPixelFormat.Bgra8,
decoder.BitmapAlphaMode, new BitmapTransform(),
ExifOrientationMode.IgnoreExifOrientation,
ColorManagementMode.DoNotColorManage);
var pixelData = pixelDataProvider.DetachPixelData();
using (var pixelStream = writableBitmap.PixelBuffer.AsStream())
{
pixelStream.Write(pixelData, 0, pixelData.Length);
}
_bitmapFrames.Add(writableBitmap);
}
}
The problem is that the frames I get from the GIF image are messed up
Am I doing something wrong in this approach? What should I modify in order to get good results?
I wouldn't like to use SharpDX since it seems to be very complicated and I am a beginner.
ImageTools is available only for Silverlight
I made a very basic GifImage control that you can start from. This is a starting point, you'll have to improve it to make it more usable as a reusable control. Check it out here.
EDIT
Do you have any idea how to improve the loading speed (parallelization, etc.)?
I assume you're referring to the process of preparing the frames. From what I tested, it seems to load instantly anyway, so there shouldn't be a need for drastic performance improvements. However, if perhaps the animation has hundreds of frames, then it could be a bottleneck maybe? More testing needs to be done to assess whether or not optimisations are necessary.
I also don't think it can be paralleled easily since each frame needs to be rendered in sequence from the previous frame. My only suggestion would be to run the loading code on a background thread so the UI thread doesn't block for large images.
If I have this control as a FlipViewItem, how can I release the memory after the item is flipped away?
I'm not sure whether or not you're using MVVM or not, but anyway, here's some suggestions:
Set the Source of the GifImage to null if it's not currently visible (inspect the SelectedIndex of the flip view). Note that currently the code in my repo doesn't handle setting Source to null. Like I said before, it needs lots of improvements. You'll have to make sure that the control doesn't hold any references to the frames so that the garbage collector can free them from memory (that is, call animation.KeyFrames.Clear() to clear all references to the frames).
Use a VirtualizingStackPanel inside the flip view. This will ensure that only the previous, current, and next flip view items are created in memory. You set it like this:
<FlipView>
<FlipView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</FlipView.ItemsPanel>
</FlipView>
I had a similar problem. I was trying to display an animated GIF loaded from an external source inside a ScrollViewer for Windows Phone 8.1 app. Since the web control takes over the events the scrolling did not work.
I used this trick: I placed the web control inside a grid and put another grid over the webcontrol. The grid over the web control was set to be the exact same size and I set the background to transparent. This way the grid receives the events and the scrolling works again.
<ScrollViewer Visibility="Visible" HorizontalAlignment="Left" VerticalAlignment="Top" Width="380">
<Grid>
<StackPanel>
<!--
Some items ...
-->
<Grid >
<WebView x:Name="animationWebView" HorizontalAlignment="Left" Height="315" Width="390" Visibility="Visible" />
<Grid Width="390" Height="315" Background="Transparent" />
</Grid>
<!--
Some other items ...
-->
</StackPanel>
</Grid>
</ScrollViewer>
I started developing a Windows 8 (Metro style)-Windows Phone 8 application that will have (between the other things) a multilayer image editor. The problem is that this thing would be pretty easy with owner draw controls...but i can't find anything like that :O
I searched everywhere, but there is not something like the OnPaint/OnDraw/OnRender/OnXXXX or things like that! Am i missing something?
Thanks to everybody!
Side Note:
For my use case I founded a workaround, a Canvas with a WritableBitmap, this way I can have a "raster" surface instead of the list of items. Other than this I use the WritableBitmapEx that wraps the WritableBitmap with all the various APIs like DrawLine, Ellipse, etc..
You are right there is no OnPaint/OnDraw/OnRender in Windows Phone App.
If you want to keep it strictly XAML the best thing you can do is make your custom control
from the Canvas object like this.
<Canvas x:Name="my_canvas">
<Rectangle Fill="Red" Width="100" Height="100" Canvas.Top="100" Canvas.Left="100" />
<Rectangle Fill="Orange" Width="100" Height="100" Canvas.Top="100" Canvas.Left="200" />
<!-- more ui elements -->
</Canvas>
You can programmatically add in items using C# by doing this (it can get really tedious if you're drawing a lot of objects... like say drawing a fine stock chart)
this.my_canvas.Children.Add(my_ui_element);
There is also Windows Phone XNA which I used for a game I have uploaded to the store. In there you will have to deal with a gaming loop and content pipeline which is not easy.
Whenever I use a chart with a Line series of column series (any series other than Pie Series), I have this error:
Could not find any resources appropriate for the specified culture or
the neutral culture. Make sure
WinRTXamlToolkit.Controls.DataVisualization.Properties.Resources.resources
was correctly embedded or linked into assembly
"WinRTXamlToolkit.Controls.DataVisualization" at compile time, or that
all the satellite assemblies required are loadable and fully signed
what can be wrong here ?
here's the XAML:
<charting:Chart Name="columnChart" Grid.Row="1" Width="400" Height="400" >
<charting:Chart.Series>
<charting:ColumnSeries ItemsSource="{Binding items}"
IndependentValueBinding="{Binding Name}"
DependentValueBinding="{Binding Value}"
IsSelectionEnabled="True">
</charting:ColumnSeries>
</charting:Chart.Series>
</charting:Chart>
I had the same problem. Adding the source to my own solution did not help by itself. I did manage to fix it by changing the Build Action of the resources file to Embedded Resource.
OK
removing the references and adding again using NuGet solved the initial problem, the solution to the Column Chart in this link WinRT Xaml Toolkit Column Series Error?
I have a problem with web cams in Win8 metro.
I want to make an application that will draw on photo.source video from webcam.
Unfortunately, I found only this How to get camera feeds in Windows 8 Metro style app? and app opens only capture and I need show only the webcam. Thanks for answers.
You could use the CaptureElement to integrate the camera feed in your application. In XAML:
<CaptureElement x:Name="capElement" Width="400"></CaptureElement>
In code-behind, you need to activate the source:
MediaCapture captureMgr = new MediaCapture();
await captureMgr.InitializeAsync();
capElement.Source = captureMgr;
await captureMgr.StartPreviewAsync();
You mean something like this? windowsapps/CameraCaptureUI
Has anyone build a AS3 Camera-Select-algorithm, ready to use?
With MacBooks you have the problem that the build-in webcam is not rightly choosen from the webplayer.
You have to select the USP-Cam by youself from the list
DV Video
IIDC FireWire Video
USB Video Class Video
by
camera = Camera.getCamera("2");
THNX!
I found kind of a workaround here
You cant actually set the camera programatically. The best you can do is prompt the user to set it next to a video panel to show them if the camera they've chosen actually works. example here: http://www.neave.com/webcam/
to prompt them to change cameras you use:
Security.showSettings(SecurityPanel.CAMERA)
there is no event to wait for, though you can poll your video panel's bitmap data for changes and prompt the user behind the security panel when you think they've chosen the right camera.
Having done battle with this problem, I would suggest that everyone use this library.
https://github.com/cataclysmicrewind/CameraDetection/
Flash + webcam should = easy + awesome.
Unfortunately, it is pain + suffering.