/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { var initOptions = e.Parameter as CameraViewInitObject; if (initOptions == null) { Frame.GoBack(); return; } _cameraOptions = initOptions.CameraOptions; _qrDetectionModeEnabled = initOptions.QRDetectionMode; _qrAutoHandleQrCode = initOptions.AutoHandleQRCode; ((Storyboard)Resources["CameraGridFadeInStoryBoard"]).Begin(); HardwareButtons.BackPressed += HardwareButtons_BackPressed; Window.Current.VisibilityChanged += Current_VisibilityChanged; }
public CameraOptions overlaySettings = new CameraOptions(); // default values public CameraOverlayView (UIImagePickerController controller, CameraOptions _settings, CGRect frame) : base (frame) { log ("Intializing Camera Overlay from frame..."); if(_settings != null) overlaySettings = _settings; // Clear the background of the overlay: this.Opaque = false; this.BackgroundColor = UIColor.Clear; // transparent UIImage overlayGraphic; string OverlayImage = _settings.Overlay; log ("Overlay Image: "+OverlayImage); if (OverlayImage != null && File.Exists("./"+OverlayImage+".png")){ log ("Overlay Image: "+OverlayImage + " found!"); overlayGraphic = UIImage.FromBundle (OverlayImage+".png"); } else { log ("Overlay Image not found"); // Load the image to show in the overlay: overlayGraphic = UIImage.FromBundle (@"overlaygraphic.png"); } overlayGraphic = overlayGraphic.ImageWithRenderingMode (UIImageRenderingMode.AlwaysTemplate); // convert image to template UIImageView overlayGraphicView = new UIImageView (overlayGraphic); overlayGraphicView.Frame = new CGRect( overlaySettings.GuidelinesMargins, overlaySettings.GuidelinesMargins, frame.Width - overlaySettings.GuidelinesMargins * 2 , frame.Height - overlaySettings.GuidelinesMargins * 2); log ("guidelines tint color: " + overlaySettings.GuidelinesColorHexadecimal); UIColor color = GetUIColorfromHex (overlaySettings.GuidelinesColorHexadecimal); if (color != null) overlayGraphicView.TintColor = color; this.AddSubview (overlayGraphicView); ScanButton scanButton = new ScanButton ( new CGRect ((frame.Width / 2) - (overlaySettings.ScanButtonWidth /2), frame.Height - overlaySettings.ScanButtonHeight - overlaySettings.ScanButtonMarginBottom , overlaySettings.ScanButtonWidth, overlaySettings.ScanButtonHeight), overlaySettings); scanButton.TouchUpInside += delegate(object sender, EventArgs e) { log("Scan Button TouchUpInside... " ); controller.TakePicture(); }; this.AddSubview (scanButton); if (overlaySettings.DescriptionLabelText != null) { UILabel label = new UILabel (new CGRect (overlaySettings.DescriptionLabelMarginLeftRight, frame.Height - overlaySettings.DescriptionLabelHeight - overlaySettings.DescriptionLabelMarginBottom, frame.Width - overlaySettings.DescriptionLabelMarginLeftRight * 2, overlaySettings.DescriptionLabelHeight)); // applying "DescriptionLabelMarginLeftRight" margins to width and x position label.Text = overlaySettings.DescriptionLabelText; color = GetUIColorfromHex (overlaySettings.DescriptionLabelColorHexadecimal); if(color != null) label.TextColor = color; label.BaselineAdjustment = UIBaselineAdjustment.AlignCenters; label.TextAlignment = UITextAlignment.Center; // centered aligned label.LineBreakMode = UILineBreakMode.WordWrap; // wrap text by words label.Lines = 2; if (overlaySettings.DescriptionLabelFontFamilyName != null) { UIFont labelFont = UIFont.FromName (overlaySettings.DescriptionLabelFontFamilyName, overlaySettings.DescriptionLabelFontSize); if (labelFont != null) { label.Font = labelFont; } else { log ("Font family [" + overlaySettings.DescriptionLabelFontFamilyName + "] for 'DescriptionLabelFontFamilyName' not found"); } } this.AddSubview (label); } UILabel cancelLabel = new UILabel (new CGRect ((frame.Width / 4) - (overlaySettings.CancelButtonWidth /2), frame.Height - overlaySettings.CancelButtonHeight - overlaySettings.ScanButtonMarginBottom, overlaySettings.CancelButtonWidth, overlaySettings.CancelButtonHeight)); cancelLabel.Text = overlaySettings.CancelButtonText; color = GetUIColorfromHex (overlaySettings.CancelButtonColorHexadecimal); if(color != null) cancelLabel.TextColor = color; cancelLabel.BaselineAdjustment = UIBaselineAdjustment.AlignCenters; cancelLabel.TextAlignment = UITextAlignment.Center; // centered aligned // list of available ios fonts: https://developer.xamarin.com/recipes/ios/standard_controls/fonts/enumerate_fonts/ if (overlaySettings.CancelButtonFontFamilyName != null) { UIFont cancelLabelFont = UIFont.FromName (overlaySettings.CancelButtonFontFamilyName, overlaySettings.CancelButtonFontSize); if (cancelLabelFont != null) { cancelLabel.Font = cancelLabelFont; } else { log ("Font family [" + overlaySettings.CancelButtonFontFamilyName + "] for 'CancelButtonFontFamilyName' not found"); } } UITapGestureRecognizer cancelLabelTap = new UITapGestureRecognizer(() => { log("Cancel Button TouchesEnded... " ); UIApplication.SharedApplication.InvokeOnMainThread (delegate { SystemLogger.Log(SystemLogger.Module.PLATFORM, "Canceled picking image "); IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.Media.onFinishedPickingImage", null); IPhoneServiceLocator.CurrentDelegate.MainUIViewController ().DismissModalViewController(true); }); }); cancelLabel.UserInteractionEnabled = true; cancelLabel.AddGestureRecognizer(cancelLabelTap); this.AddSubview (cancelLabel); }
public ScanButton (CGRect frame, CameraOptions options) : base (frame) { UIImage buttonImage = UIImage.FromBundle(@"scanbutton"); buttonImage = buttonImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); // convert image to template this.SetImage (buttonImage, UIControlState.Normal); this.SetImage (buttonImage, UIControlState.Highlighted); UIImage buttonIconImage = UIImage.FromBundle(@"scaniconbutton"); buttonIconImage = buttonIconImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); // convert image to template UIImageView buttonIconImageView = new UIImageView (buttonIconImage); if(options != null) { buttonIconImageView.Frame = new CGRect( (frame.Width / 2) - (options.ScanButtonIconWidth /2), (frame.Height / 2) - (options.ScanButtonIconHeight /2), options.ScanButtonIconWidth , options.ScanButtonIconHeight); // we will place the icon in the middle of the button image SystemLogger.Log (SystemLogger.Module.PLATFORM, "ScanButton : tint color to be used " + options.ScanButtonColorHexadecimal); UIColor color = CameraOverlayView.GetUIColorfromHex (options.ScanButtonColorHexadecimal); if (color != null) this.TintColor = color; SystemLogger.Log (SystemLogger.Module.PLATFORM, "ScanButton : tint color to be used for icon " + options.ScanButtonIconColorHexadecimal); color = CameraOverlayView.GetUIColorfromHex (options.ScanButtonIconColorHexadecimal); if (color != null) buttonIconImageView.TintColor = color; } this.TouchUpInside += delegate { if(options != null) { SystemLogger.Log (SystemLogger.Module.PLATFORM, "ScanButton : TouchUpInside... changing color to: " + options.ScanButtonPressedColorHexadecimal); UIColor color = CameraOverlayView.GetUIColorfromHex (options.ScanButtonPressedColorHexadecimal); if(color != null) this.TintColor = color; } }; this.AddSubview (buttonIconImageView); // adding inside image as a new subview }
public abstract void TakeSnapshotWithOptions (CameraOptions options);
public abstract Task TakeSnapshotWithOptions(CameraOptions options);
/// <summary> /// Launches the CameraView in photo mode /// </summary> /// <param name="options"></param> /// <returns></returns> public async Task ShowCameraView(CameraOptions options) { NavigateToCameraViewPage(new CameraViewInitObject { CameraOptions = null, AutoHandleQRCode = false, QRDetectionMode = false }); }
private async Task EnableCameraCustomOverlay(CameraOptions options) { await StatusBar.GetForCurrentView().HideAsync(); if (options == null || !options.UseCustomCameraOverlay) return; _cameraOptions = options; var GuideMarksBrush = FromHexColorToBrush(options.GuidelinesColorHexadecimal); var screenWidth = Window.Current.Bounds.Width; var screenHeight = Window.Current.Bounds.Height; var WPBlackMargin = 25; /*ULGuideMark.Stroke = URGuideMark.Stroke = BLGuideMark.Stroke = BRGuideMark.Stroke = GuideMarksBrush; //UpperLeft Mark ULGuideMark.Points = new PointCollection() { new Point(WPBlackMargin, (screenHeight / 10) + WPBlackMargin), new Point(WPBlackMargin, WPBlackMargin), new Point((screenWidth / 10) + WPBlackMargin, WPBlackMargin) }; //UpperRight Mark URGuideMark.Points = new PointCollection() { new Point((screenWidth - screenWidth / 10) - WPBlackMargin, WPBlackMargin), new Point(screenWidth - WPBlackMargin, WPBlackMargin), new Point(screenWidth - WPBlackMargin, (screenHeight / 10) + WPBlackMargin) }; //BottomLeft Mark BLGuideMark.Points = new PointCollection() { new Point(WPBlackMargin, (screenHeight - WPBlackMargin - (screenHeight / 10))), new Point(WPBlackMargin, screenHeight - WPBlackMargin), new Point((screenWidth / 10) + WPBlackMargin, screenHeight - WPBlackMargin) }; //BottomRight Mark BRGuideMark.Points = new PointCollection() { new Point((screenWidth - WPBlackMargin - (screenWidth / 10)), screenHeight - WPBlackMargin), new Point(screenWidth - WPBlackMargin, screenHeight - WPBlackMargin), new Point(screenWidth - WPBlackMargin, (screenHeight - WPBlackMargin - (screenHeight / 10))) }; */ if (options.Overlay != null) { BitmapImage imageBitmap; try { imageBitmap = new BitmapImage(new Uri("ms-appx:///Assets/" + options.Overlay + ".png")); } catch (Exception ex) { imageBitmap = new BitmapImage(new Uri("ms-appx:///Assets/background.png")); } CameraPreviewOverlay.Source = imageBitmap; } CameraButtonsGrid.Margin = new Thickness(0, 0, 0, options.ScanButtonMarginBottom); // CameraDescription Label CameraDescriptionTextBlock.Text = options.DescriptionLabelText; CameraDescriptionTextBlock.Foreground = FromHexColorToBrush(options.DescriptionLabelColorHexadecimal); CameraDescriptionTextBlock.Height = options.DescriptionLabelHeight; CameraDescriptionTextBlock.FontFamily = new FontFamily(options.DescriptionLabelFontFamilyName); CameraDescriptionTextBlock.FontSize = options.DescriptionLabelFontSize; CameraDescriptionTextBlock.Margin = new Thickness(options.DescriptionLabelMarginLeftRight, 0, options.DescriptionLabelMarginLeftRight, options.DescriptionLabelMarginBottom); // CameraDescription Label Shadows... CameraDescriptionTextBlockShadow1.Text = CameraDescriptionTextBlockShadow1.Text = CameraDescriptionTextBlockShadow1.Text = CameraDescriptionTextBlockShadow1.Text = CameraDescriptionTextBlock.Text; CameraDescriptionTextBlockShadow1.Height = CameraDescriptionTextBlockShadow1.Height = CameraDescriptionTextBlockShadow1.Height = CameraDescriptionTextBlockShadow1.Height = CameraDescriptionTextBlock.Height; CameraDescriptionTextBlockShadow1.FontFamily = CameraDescriptionTextBlockShadow1.FontFamily = CameraDescriptionTextBlockShadow1.FontFamily = CameraDescriptionTextBlockShadow1.FontFamily = CameraDescriptionTextBlock.FontFamily; CameraDescriptionTextBlockShadow1.FontSize = CameraDescriptionTextBlockShadow1.FontSize = CameraDescriptionTextBlockShadow1.FontSize = CameraDescriptionTextBlockShadow1.FontSize = CameraDescriptionTextBlock.FontSize; CameraDescriptionTextBlockShadow1.Margin = new Thickness(options.DescriptionLabelMarginLeftRight + 3, 0 + 3, options.DescriptionLabelMarginLeftRight - 3, options.DescriptionLabelMarginBottom - 3); CameraDescriptionTextBlockShadow2.Margin = new Thickness(options.DescriptionLabelMarginLeftRight + 4, 0 + 4, options.DescriptionLabelMarginLeftRight - 4, options.DescriptionLabelMarginBottom - 4); CameraDescriptionTextBlockShadow3.Margin = new Thickness(options.DescriptionLabelMarginLeftRight + 5, 0 + 5, options.DescriptionLabelMarginLeftRight - 5, options.DescriptionLabelMarginBottom - 5); CameraDescriptionTextBlockShadow4.Margin = new Thickness(options.DescriptionLabelMarginLeftRight + 6, 0 + 6, options.DescriptionLabelMarginLeftRight - 6, options.DescriptionLabelMarginBottom - 6); CameraDescriptionTextBlockShadow1.Visibility = CameraDescriptionTextBlockShadow2.Visibility = CameraDescriptionTextBlockShadow3.Visibility = CameraDescriptionTextBlockShadow4.Visibility = Visibility.Visible; //Shutter Button ShutterButton.Height = options.ScanButtonHeight; ShutterButton.Width = options.ScanButtonWidth; ShutterButton.IsEnabled = true; //CancelButton CancelCameraButton.Content = options.CancelButtonText; CancelCameraButton.Width = options.CancelButtonWidth; CancelCameraButton.Height = options.CancelButtonHeight; CancelCameraButton.FontSize = options.CancelButtonFontSize; CancelCameraButton.Foreground = FromHexColorToBrush(options.CancelButtonColorHexadecimal); CancelCameraButton.FontFamily = new FontFamily(options.CancelButtonFontFamilyName); CancelCameraButton.IsEnabled = true; CameraButtonsGrid.Visibility = Visibility.Visible; }
/// <summary> /// Shows the CameraView in QR Detection mode /// </summary> /// <param name="autoHandleQrCode"></param> /// <param name="options"></param> /// <returns></returns> public async Task ShowDetectQrView(bool autoHandleQrCode, CameraOptions options) { NavigateToCameraViewPage(new CameraViewInitObject { CameraOptions = options, AutoHandleQRCode = autoHandleQrCode, QRDetectionMode = true }); }
public override MediaMetadata TakeSnapshot () { cameraOptions = null; // rest values for camera options SystemLogger.Log(SystemLogger.Module.PLATFORM, "Getting picture from camera"); using (var pool = new NSAutoreleasePool ()) { var thread = new Thread (ShowCameraView); thread.Start (); }; //TODO change method signature to "void" return. return null; }
public override void TakeSnapshotWithOptions (CameraOptions options) { cameraOptions = options; // reset image scale factor SystemLogger.Log(SystemLogger.Module.PLATFORM, "Getting picture from camera with specific camera options..."); using (var pool = new NSAutoreleasePool ()) { var thread = new Thread (ShowCameraView); thread.Start (); }; }
public override async Task TakeSnapshotWithOptions(CameraOptions options) { AppverseBridge.Instance.RuntimeHandler.ShowCameraView(options); }
public override void TakeSnapshotWithOptions(CameraOptions options) { throw new NotImplementedException(); }