How to use Front-facing camera to take pictures on windows phone? - windows-phone-8

I've got two questions about how to access the camera on Windows Phone 8:
How can I access the front-facing camera to take pictures?
How can I access the flash/torch of main camera?

This article from MSDN has an example of both accessing the front and back cameras, as well as accessing the flash, assuming your using C# (since you didn't specify). Here's a snippet under the Creating the Capture Device heading:
System.Collections.Generic.IReadOnlyList<Windows.Foundation.Size> SupportedResolutions =
PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Front);
Windows.Foundation.Size res = SupportedResolutions[0];
this.captureDevice = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Front, res);
For accessing the flash of the camera, here is a snippet under the Specifying Camera Properties heading:
cam.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.On);
cam.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, true);
cam.SetProperty(KnownCameraGeneralProperties.AutoFocusRange, AutoFocusRange.Infinity);
Hope this helps!

Related

Create WriteableBitmap using HTML content in Windows phone 8.1

Create WriteableBitmap using HTML content in Windows phone 8.1 Without involving the XAML
I have created WebView object in c# and render HTML content in WebView.NaviagateToString and trying to get the object using WebView.CapturePreviewToStreamAsync method but i am getting the Global exception ( value does not fall within the expected range).
WebView wv = new WebView();
wv.NavigateToString(HTML Content);
InMemoryRandomAccessStream imras = new InMemoryRandomAccessStream();
await wv.CapturePreviewToStreamAsync(imras);
And also i tried using the below code, but i didn't find the dlls.
Bitmap m_Bitmap = new Bitmap(400, 600);
PointF point = new PointF(0, 0);
SizeF maxSize = new System.Drawing.SizeF(500, 500);
HtmlRenderer.HtmlRender.Render(Graphics.FromImage(m_Bitmap),"<html><body><p>This is a shitty html code</p><p>This is another html line</p></body>", point,maxSize);
m_Bitmap.Save(#"C:\Test.bmp")
Please help me out from this.
Thanks.
t's impossible currently, Windows Phone Store apps do have a phone-only ScreenCapture API, but it still need to show your content in you app.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

Windows Phone 8.1 Has No Sample Images?

I am testing PhotoChooserTask in my 8.1 app and I do not see any available sample images that come with the emulator? Is there a way to get sample images?
void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
//MessageBox.Show(e.ChosenPhoto.Length.ToString());
//Code to display the photo on the page in an image control named myImage.
System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
bmp.SetSource(e.ChosenPhoto);
myImage.Source = bmp;
}
}
You don't need to download from the Internet. I found a great workaround for this.. In the new WP8.1 emulator you have the option to emulate a SD card. Its great. I have created a blog post and a YouTube video. Have a look. Hope it helps.
http://wpdevkvk.wordpress.com/2014/07/19/adding-your-own-photos-to-windows-phone-8-1-emulator/
In the Windows Phone 8.1 emulator there aren't any images available. Actually there are some images for selecting as the background for the start screen, but it is only available for start+theme app in settings page. You can't access them. But you have a workaround for that. Before you test your app you can open the camera app and take some photos. (Obviously it will take save some images of random squares but it will have to do) Then next time you run the app your PhotoChooserTask has some photos to select from.

Windows Phone 8 Live tiles Text & image update

I created an app for windows Phone 8 and want to implement Live tiles in my app. I don't even know anything about live tiles. I tried many examples from the forums and all.
But all are in the form of buttons(Like Flip, Cycle) If i click Cycle Button it will direct to the start screen to show the Cycle Tile.
But, How could i implement in my app. i want to shows the lives tiles only when user pins into the start screen.
anyone, help me to solve this????
Thanks in Advance.
The first thing you need to know is that LiveTiles on Windows Phone 8 can be implemented only from C#/.NET code, not C++. The native libraries don't have access to LiveTiles, so you need to use the .NET API.
Next... if your app is written in C++ with DirectX, you need to use XAML with Direct3D interop. This means you will have at least 2 VS projects, one using XAML/C#, the other using C++. LiveTiles will be updated through callbacks and delegates, sending events from the C++ component to the C# XAML component.
(If your app is using only C#/.NET, you don;t need any callbacks)
One more thing: the only type of LiveTile which always works on Windows Phone is FlipTile type. If you use iconic tiles, WP8 usually ignores colors, and shows only white&transparency.
Here is a snippet from my C++ component:
std:string dummyStd = "test string to display";
std::wstring dummyWs.assign(dummyStd.begin(), dummyStd.end());
Platform::String^ dummy = ref new Platform::String(separatorWs.c_str());
m_d3DInterop->OnLiveTilesUpdates(dummy);
and a snippet from the C# component:
public void OnLiveTilesUpdates(String s)
{
String szTitle = "title";
String szText = s;
ShellTile oTile = ShellTile.ActiveTiles.First();
{
FlipTileData oFliptile = new FlipTileData();
oFliptile.Title = "";
oFliptile.Count = 0;
oFliptile.BackTitle = szText;
oFliptile.BackContent = szTitle;
oFliptile.WideBackContent = szTitle;
oFliptile.SmallBackgroundImage = new Uri("/Assets/Tiles/FlipTileFrontSmall.png", UriKind.Relative);
oFliptile.BackgroundImage = new Uri("/Assets/Tiles/FlipTileFrontMedium.png", UriKind.Relative);
oFliptile.WideBackgroundImage = new Uri("/Assets/Tiles/FlipTileFrontHigh.png", UriKind.Relative);
oFliptile.BackBackgroundImage = new Uri("/Assets/Tiles/FlipTileFrontMedium.png", UriKind.Relative);
oFliptile.WideBackBackgroundImage = new Uri("/Assets/Tiles/FlipTileFrontHigh.png", UriKind.Relative);
oTile.Update(oFliptile);
}
Remember you need to bind the two snippets of code using events and delegates/callbacks (only if you use XAML with Direct3D interop).
Also, if you arrive here, you should know that the best component to use for rendering is DrawingSurface, because DrawingSurfaceBackgroundGrid has some z-order issues in WP8, and SwapChainBackgroundPanel is not supported in WP8.
PS: you should also do some research regarding secondary tiles.

Capture video without sound in Windows Store App

I want to write a Windows Store App that can capture video (without any sound) and take pictures. Imagine a digital camera: you can preview the picture on the screen of your device before pushing the button which takes the pic.
The problem I'm facing now is the fact that the Windows.Media.Capture namespace has only classes for objects that capture video with sound (CameraCaptureUI, MediaCapture). I'm not troubled by the objects' capabilities, but by the fact that I will have to include in the manifest of the app the Microphone capability and it does not make sense for the app to use it. I need a class that uses only the Webcam capability.
Any ideas?
I found the answer and I thought I should share it. I'm sorry for answering my own question, but here goes:
One can specify in the settings of the MediaCapture object, when initializing it, that it will use only the Video part:
var mediaCaptureMgr = new MediaCapture();
var captureSettings = new MediaCaptureInitializationSettings();
captureSettings.StreamingCaptureMode = StreamingCaptureMode.Video;
await mediaCaptureMgr.InitializeAsync(captureSettings);
RTFM!

Windows 8 Metro C# Camera

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