How to take multiple pictures using camera in Xamarin Forms? - c#

I have an application in which I have a requirement to take multiple images in one shot by phone camera. User don't want to open camera again and again.
I have tried https://github.com/jamesmontemagno/MediaPlugin Plugin also but it do not support continuous Images capturing. It clicks one image at a time.
Is there a way to achieve this behaviour?
Thanks

Can you try this in media plugin
for (int i = 0; i < 3; i++)
{
file = await MediaPicker.TakePhotoAsync(new StoreCameraMediaOptions { SaveToAlbum = true, Name = "", Directory = "" });
if (file != null)
{
//code to save
}
The user can press cancel at anytime to stop taking pictures, and it'll hit the return and stop running the code. But its ran the logic to save the images each time a photo has been taken.

Related

How could you check if a window popup exists using Selenium w/ C#?

I'm currently writing a program that has a 'Submit' button that displays a list of providers within a certain area. However, a separate screen may popup if the provider has offices in more than one location (ie. different states, different offices around the same city, etc). If he's located in a single area, a dropdown occurs instead without the need to use window handling for the popup.
So far, my code fails 50% of the time since half of the providers operate in only one location and consequently, no popup appears. While it passes the other 50% since a popup appears and the code continues with no further issues.
My question is, how can I tell Selenium to search for a separate screen once I click the 'Submit' button. And if it doesn't appear, to continue on instead?
My code so far:
string currentHandle = driver.CurrentWindowHandle;
PopupWindowFinder finder = new PopupWindowFinder(driver);
string popupWindowHandle = finder.Click(BtnAccept);
if(popupWindowHandle != currentHandle)
{
driver.SwitchTo().Window(popupWindowHandle);
BtnSelectPopUpProvider.Click();
driver.SwitchTo().Window(currentHandle);
}
I don't know if it will be of any help, but what about using this construction ?
string currentHandle = driver.CurrentWindowHandle;
PopupWindowFinder finder = new PopupWindowFinder(driver);
try
{
string popupWindowHandle = finder.Click(BtnAccept);
if (popupWindowHandle != currentHandle)
{
driver.SwitchTo().Window(popupWindowHandle);
BtnSelectPopUpProvider.Click();
driver.SwitchTo().Window(currentHandle);
}
}
catch { }
On timeout the code below the try will continue to execute.

C# Windows Forms How to Blank Out all other monitors

I am building a log in form for a shared environment.
This form will automatically pop up whenever a user logs in and asks for credentials (via RDP).
I discovered an issue that if the user has multiple monitors, they could disable the form pop up by accessing the Task Scheduler via the task view button on the taskbar.
(Currently it will log a user out if they use any hot key navigation methods)
So I would like to have my form put up a blank screen on all other monitors so the user is forced to address the log in form.
I have found the System.Windows.Forms.Screen.AllScreens array but I am not sure how I can draw a rectangle on every monitor except where the form actually sits.
Any help would be greatly appreciated.
I figured it out so I thought I would share.
I created a new blank form (called monitorBlackOut), set it manual positioning and to be maximized.
In the main form I added the following code:
if (System.Windows.Forms.Screen.AllScreens.Length > 1)
{
for (int i = 1; i < System.Windows.Forms.Screen.AllScreens.Length; i++)
{
int xPos = System.Windows.Forms.Screen.AllScreens[i].Bounds.Location.X;
int yPos = System.Windows.Forms.Screen.AllScreens[i].Bounds.Location.Y;
monitorBlackOut screen = new monitorBlackOut();
screen.Location = new Point(xPos, yPos);
screen.Show();
screens.Add(screen);
}
}
Then when the user successfully logs in I can execute:
foreach(monitorBlackOut screen in screens)
screen.Close();
Works exactly how its supposed to and will work on any number of monitors.

How to use ZXing Barcode Scanner in a Xamarin Forms app?

I'm trying to figure out how use to use ZXing Barcode Scanner nuget package in a simple Xamarin Forms application.
I'm trying to have a large area of my form show what my camera is seeing .. and if it scan's something.. then stop scanning and goto the next Page.
All the examples basically show this:
buttonScan.Click += (sender, e) => {
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
var result = await scanner.Scan();
if (result != null)
Console.WriteLine("Scanned Barcode: " + result.Text);
};
but I don't understand what the actual view/control/widget which gets displayed onto the actual page, is? Like a big square with the camera contents getting displayed etc.
What is the trick to drop a control onto the page .. which I can then wire up to scan whatever the camera is 'seeing' .. and hopefully it will 'read' the barcode or qrcode?

When using FileOpenPicker, how to open the "Choose an app" screen like OneDrive app does?

The new Windows Phone 8.1 file picker let us choose file from any place, but we must tap the ellipse at the picker toolbar and then "choose location" to be able to list files like the new OneDrive app does by default.
The screen I'm talking about is titled "Choose an app", and lists items like "Photos" and "Phone", that are native applications registered for file picker.
Same screen shown here, when the guy tap "Pick files" button
https://www.youtube.com/watch?v=adR-lu8ZM6U#t=19
I want to open this screen by default, not the thumbnail view.
Changing the FileOpenPicker ViewMode property doesn't seem to have any effect.
My code is now just like this, I'm not setting ViewMode neither SuggestedStartLocation now:
private void OpenFilePicker()
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.FileTypeFilter.Add(".mp4");
openPicker.FileTypeFilter.Add(".avi");
App.ContinuationEventArgsChanged += OpenFile_ContinuationEventArgsChanged;
openPicker.PickSingleFileAndContinue();
}
private async void OpenFile_ContinuationEventArgsChanged(object sender, IContinuationActivatedEventArgs e)
{
App.ContinuationEventArgsChanged -= OpenFile_ContinuationEventArgsChanged;
var openFileArgs = e as FileOpenPickerContinuationEventArgs;
if (openFileArgs != null && openFileArgs.Files != null && openFileArgs.Files.Count > 0)
{
//do stuff with the file here
}
}
I'm supposing this should be a problem (from http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.pickers.fileopenpicker.suggestedstartlocation.aspx):
"The SuggestedStartLocation is not always used as the start location for the file picker. To give the user a sense of consistency, the file picker remembers the last location that the user navigated to and will generally start at that location."
Any suggestion?
Thanks
Problem is that you added filetypes which are reserved by system and it causes that photopicker is launched. If you do something like that, it should work as you like:
openPicker.FileTypeFilter.Add("*");
There isn't any other solution.

Launching Webcam in Metro style apps

I am building a win8 app which requires to launch the webcam for taking photos only.
I have seen the sample codes given in MSDN for Camera captures but I only want is onclick of CAPTURE Button the webcam should launched, take a pic and save it.
While in the sample codes they made the user to select option from the list box and on selectionchanged, the required function has been called. My problem is that I don't required any Listbox. Also they have used a class called SuspensionManager which I didn't understand. I am really confused.
Can somebody show me a way out?
Try this:
using Windows.Media.Capture;
var ui = new CameraCaptureUI();
ui.PhotoSettings.CroppedAspectRatio = new Size(4, 3);
var file = await ui.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (file != null)
{
var bitmap = new BitmapImage();
bitmap.SetSource(await file.OpenAsync(FileAccessMode.Read));
Photo.Source = bitmap;
}
Took from here

Categories

Resources