I am using ZXing.Net.Mobile in my windows phone 8.1 app. It is using below reference:
ZXing.Net.Mobile.Core
zxing.portable
ZXingNetMobile
My Code :
var scanner = new MobileBarcodeScanner();
MobileBarcodeScanningOptions options = new MobileBarcodeScanningOptions();
options.TryHarder = true;
options.PossibleFormats.Add(ZXing.BarcodeFormat.CODE_128);
options.PossibleFormats.Add(ZXing.BarcodeFormat.CODE_39);
var result = await scanner.Scan(options);
if (result != null)
{
MessageDialog a = new MessageDialog(result.Text);
a.Content = result.Text;
a.ShowAsync();
}
Issue:
Am getting below issue whenever scan method executes.
Use the platform specific implementations instead at ZXing.Mobile.MobileBarcodeScanner.Scan(....
Is there any real time QR code scanner available for windows phone 8.1 ?
Related
I created project based on:
https://github.com/Microsoft/real-time-filter-demo/tree/master/RealtimeFilterDemoWP
My question is how to enable flash light (torch) on WP8.1
Should I use MediaCapture() ?
var mediaDev = new MediaCapture();
await mediaDev.InitializeAsync();
var videoDev = mediaDev.VideoDeviceController;
var tc = videoDev.TorchControl;
if (tc.Supported)
{
if (tc.PowerSupported)
tc.PowerPercent = 100;
tc.Enabled = true;
}
when I used it it crash on
var videoDev = mediaDev.VideoDeviceController;
by unhandled exception
How to add flashlight to this sample project ?
You haven't initialized the MediaCaptureSettings, thus when you attempt to initialize the videoController the exception occurs. You need to initialize the settings, let MediaCapture know what device you'd like to use, and setup the VideoDeviceController. In addition, for Windows Phone 8.1 camera drivers, some require you to start the preview, or others require you to start video recording to turn on flash. This is due to the flash being tightly coupled with the camera device.
Here's some general code to give you the idea. *Disclaimer, this is untested. Best sure to call this in an async Task method so you can assure the awaited calls complete before you attempt to toggle the Torch Control property.
private async Task InitializeAndToggleTorch()
{
// Initialize Media Capture and Settings Objects, mediaCapture declared global outside this method
mediaCapture = new MediaCapture();
MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
// Grab all available VideoCapture Devices and find rear device (usually has flash)
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
DeviceInformation device = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
// Set Video Device to device with flash obtained from DeviceInformation
settings.VideoDeviceId = device.Id;
settings.AudioDeviceId = "";
settings.PhotoCaptureSource = PhotoCaptureSource.VideoPreview;
settings.StreamingCaptureMode = StreamingCaptureMode.Video;
mediaCapture.VideoDeviceController.PrimaryUse = Windows.Media.Devices.CaptureUse.Video;
// Initialize mediacapture now that settings are configured
await mediaCapture.InitializeAsync(settings);
if (mediaCapture.VideoDeviceController.TorchControl.Supported)
{
// Get resolutions and set to lowest available for temporary video file.
var resolutions = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoRecord).Select(x => x as VideoEncodingProperties);
var lowestResolution = resolutions.OrderBy(x => x.Height * x.Width).ThenBy(x => (x.FrameRate.Numerator / (double)x.FrameRate.Denominator)).FirstOrDefault();
await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoRecord, lowestResolution);
// Get resolutions and set to lowest available for preview.
var previewResolutions = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties (MediaStreamType.VideoPreview).Select(x => x as VideoEncodingProperties);
var lowestPreviewResolution = previewResolutions.OrderByDescending(x => x.Height * x.Width).ThenBy(x => (x.FrameRate.Numerator / (double)x.FrameRate.Denominator)).LastOrDefault();
await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, lowestPreviewResolution);
// Best practice, you should handle Media Capture Error events
mediaCapture.Failed += MediaCapture_Failed;
mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded;
}
else
{
// Torch not supported, exit method
return;
}
// Start Preview
var captureElement = new CaptureElement();
captureElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
// Prep for video recording
// Get Application temporary folder to store temporary video file folder
StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;
// Create a temp Flash folder
var folder = await tempFolder.CreateFolderAsync("TempFlashlightFolder", CreationCollisionOption.OpenIfExists);
// Create video encoding profile as MP4
var videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
// Create new unique file in the Flash folder and record video
var videoStorageFile = await folder.CreateFileAsync("TempFlashlightFile", CreationCollisionOption.GenerateUniqueName);
// Start recording
await mediaCapture.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile);
// Now Toggle TorchControl property
mediaCapture.VideoDeviceController.TorchControl.Enabled = true;
}
Phew! That's a lot of code just to toggle flash huh? Good news is this is fixed in Windows 10 with new Windows.Devices.Lights.Lamp API. You can do same work in just a few lines of code:
Windows 10 Sample for Windows.Devices.Lights.Lamp
For reference, check this thread:
MSDN using Win8.1 VideoDeviceController.TorchControl
I want to create a custom image for the AppbarButton.
I'm using code from
Windows Phone 8.1 AppBarButton icon with 2 rows of text
RenderTargetBitmap rtb = new RenderTargetBitmap();
await rtb.RenderAsync(TodayTextBorder);
IBuffer pixels = await rtb.GetPixelsAsync();
string filename = "TodayIcon.png";
var outputFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.ReplaceExisting);
using (var outputStream = await outputFile.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder enc = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, outputStream);
var dpi = DisplayInformation.GetForCurrentView().LogicalDpi;
enc.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)rtb.PixelWidth, (uint)rtb.PixelHeight, dpi, dpi, pixels.ToArray());
await enc.FlushAsync();
}
BitmapIcon icon = new BitmapIcon();
icon.UriSource = new Uri("ms-appdata:///local/" + filename);
TodayAppbarButton.Icon = icon;
But it doesn't work. Well, it works on the Emulator and on the phone in case the app was deployed directly from Visual Studio. But when I'm publishing app and installing it from the Store I'm getting erroneous appbar button image (like this http://i.imgur.com/de73cTo.png)
I am coding a PCL Web Lib calling for Windows Phone 8.1 RT and Windows 8.1 app
While HttpWebRequest Class can NOT modify HOST, referer and so on headers running is Windows RT 8.1 app (WP8.1 RT runs OK, it is a bug in Microsoft)
So I want to use HttpClient Class. One UnResolve issue is how to modify request HOST? I can set different HOST without any exception. But actually, the request HOST is not applied. below is my code:
var client = new HttpClient();
var request = new HttpRequestMessage()
{
RequestUri = new Uri("http://www.bing.com"),
Method = HttpMethod.Get,
};
client.DefaultRequestHeaders.Host = new HostName("12.34.56.78");
//client.DefaultRequestHeaders.Add("Host", "12.34.56.78");
var respose = await client.SendRequestAsync(request);
var content = await respose.Content.ReadAsStringAsync();
According to Wikipedia the host HTTP header is used to identify the virtual host on the server. I think you should set the IP address on the RequestUri and set the host to the desired domain name, for example:
var client = new HttpClient();
var request = new HttpRequestMessage()
{
RequestUri = new Uri("http://12.34.56.78/path"),
Method = HttpMethod.Get,
};
client.DefaultRequestHeaders.Host = new HostName("www.bing.com");
var respose = await client.SendRequestAsync(request);
var content = await respose.Content.ReadAsStringAsync();
In Windows Phone 8 I was able to create a Shell Tile with the following:
StandardTileData newTileData = new StandardTileData
{
BackgroundImage = new Uri("/Images/my_tile_medium.png", UriKind.Relative),
Title = "My Tile Title",
BackTitle = "My Tile Back",
BackBackgroundImage = new Uri("/Images/my_tile_medium_back.png", UriKind.Relative),
};
ShellTile.Create(MyAppPages.MainPage("Name=MyAppTile"), newTileData);
This no longer works in Windows Phone 8.1. How can I programatically create a tile with Windows Phone 8.1
In WP8.1 Runtime you can use SecondaryTile, for example:
SecondaryTile tileData = new SecondaryTile()
{
TileId = "MyTileID",
DisplayName = "MyTilesTitle",
Arguments = "Some arguments"
};
tileData.VisualElements.Square150x150Logo = new Uri("uri to image");
tileData.VisualElements.ShowNameOnSquare150x150Logo = true;
await tileData.RequestCreateAsync();
Some guide you can also find here at MSDN.
I am building a geofencing app on Windows Phone. The current version includes about 100 geofences, some of the overlap with others. I wrote a background task and set the trigger the entered state of a geofence. When I am out, testing my app, it occurs, that the background task does not react on geofences which overlap with others.
This is the code from the backround task:
public void Run(IBackgroundTaskInstance taskInstance)
{
var reports = GeofenceMonitor.Current.ReadReports();
var report = reports.FirstOrDefault(r => (r.Geofence.Id == "testID") && (r.NewState == GeofenceState.Entered));
if (report == null) return;
var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var txtNodes = toastXmlContent.GetElementsByTagName("text");
txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("Geofence entered!"));
txtNodes[1].AppendChild(toastXmlContent.CreateTextNode(report.Geofence.Id));
var toast = new ToastNotification(toastXmlContent);
var toastNotifier = ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toast);
}
Does anybody know, how to handle overlapping geofences on Windows Phone?
Thank you