예제 #1
0
        void UpdateMainPage()
        {
            if (_application.MainPage == null)
            {
                return;
            }

            IList <Action <SKCanvas, int, int> > renderChildren = new List <Action <SKCanvas, int, int> >();

            UIView view = new NativeSkiaView(new SkiaView((canvas, w, h) =>
            {
                canvas.Clear(SKColors.White);
                _canvas = canvas;
                _size   = new Xamarin.Forms.Size(w, h);
                foreach (var renderer in renderChildren)
                {
                    renderer(canvas, w, h);
                }
            }));

            UIViewController vc = new UIViewController
            {
                View = view
            };

            AddRenderers(_application.MainPage, renderChildren);

            Window.RootViewController = vc;
        }
예제 #2
0
        public void DrawImage(IImage image, float x, float y, float width, float height, Xamarin.Forms.Aspect aspect)
        {
            if (image != null)
            {
                CanvasBitmap bitmap = ((Image)image).NativeBitmap;
                if (bitmap != null)
                {
                    if (aspect == Xamarin.Forms.Aspect.Fill)
                    {
                        ds.DrawImage(bitmap, new Rect(x, y, width, height));
                    }
                    else
                    {
                        Xamarin.Forms.Size bounding = new Xamarin.Forms.Size(width, height);

                        if (aspect == Xamarin.Forms.Aspect.AspectFill)
                        {
                            Xamarin.Forms.Rectangle imageBox = MathHelper.Fill(new Xamarin.Forms.Rectangle(Xamarin.Forms.Point.Zero, image.Size), bounding);

                            ds.DrawImage(bitmap, new Rect(x, y, width, height), new Rect(imageBox.X, imageBox.Y, imageBox.Width, imageBox.Height));
                        }
                        else
                        {
                            Xamarin.Forms.Rectangle boundingBox = MathHelper.Fit(image.Size, new Xamarin.Forms.Rectangle(x, y, width, height));

                            ds.DrawImage(bitmap, new Rect(boundingBox.X, boundingBox.Y, boundingBox.Width, boundingBox.Height));
                        }
                    }
                }
            }
        }
예제 #3
0
        public static Stream GetImageStream(IList <Line>?lines,
                                            Size imageSize,
                                            Color backgroundColor)
        {
            if (lines == null)
            {
                return(Stream.Null);
            }

            var image = GetImageInternal(lines, backgroundColor);

            if (image is null)
            {
                return(Stream.Null);
            }

            var resizedImage = MaxResizeImage(image, (float)imageSize.Width, (float)imageSize.Height);

            using (resizedImage)
            {
                var stream = new MemoryStream();
                resizedImage.Save(stream, ImageFormat.Jpeg);
                stream.Position = 0;
                return(stream);
            }
        }
예제 #4
0
        public void DrawImage(IImage image, float x, float y, float width, float height, Xamarin.Forms.Aspect aspect)
        {
            if (image != null)
            {
                CGImage cgImage = ((Image)image).NativeImage;
                if (cgImage != null)
                {
                    if (aspect == Xamarin.Forms.Aspect.Fill)
                    {
                        context.DrawImage(new CGRect(x, y, width, height), cgImage);
                    }
                    else
                    {
                        Xamarin.Forms.Size bounding = new Xamarin.Forms.Size(width, height);

                        if (aspect == Xamarin.Forms.Aspect.AspectFill)
                        {
                            Xamarin.Forms.Rectangle imageBox = MathHelper.Fill(new Xamarin.Forms.Rectangle(Xamarin.Forms.Point.Zero, image.Size), bounding);

                            using (CGImage newImage = cgImage.WithImageInRect(new CGRect(imageBox.X, imageBox.Y, imageBox.Width, imageBox.Height)))
                                context.DrawImage(new CGRect(x, y, width, height), newImage);
                        }
                        else
                        {
                            Xamarin.Forms.Rectangle boundingBox = MathHelper.Fit(image.Size, new Xamarin.Forms.Rectangle(x, y, width, height));

                            context.DrawImage(new CGRect(boundingBox.X, boundingBox.Y, boundingBox.Width, boundingBox.Height), cgImage);
                        }
                    }
                }
                context.DrawImage(new CGRect(x, y, width, height), cgImage);
            }
        }
예제 #5
0
        /// <summary>
        /// Get image stream from points
        /// </summary>
        /// <param name="points">Drawing points</param>
        /// <param name="imageSize">Image size</param>
        /// <param name="lineWidth">Line Width</param>
        /// <param name="strokeColor">Line color</param>
        /// <param name="backgroundColor">Image background color</param>
        /// <returns>Image stream</returns>
        public static Stream GetImageStream(IList <Point> points,
                                            Size imageSize,
                                            float lineWidth,
                                            Color strokeColor,
                                            Color backgroundColor)
        {
            if (points.Count < 2)
            {
                return(Stream.Null);
            }

            var image = GetImageInternal(points, lineWidth, strokeColor, backgroundColor);

            if (image is null)
            {
                return(Stream.Null);
            }

            var resizedImage = MaxResizeImage(image, (float)imageSize.Width, (float)imageSize.Height);

            using (resizedImage)
            {
                var stream = new MemoryStream();
                resizedImage.Save(stream, ImageFormat.Jpeg);
                stream.Position = 0;
                return(stream);
            }
        }
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            LoadApplication(new App());

            Profile.EnableUpdatesOnAccessTokenChange(true);
            Settings.AppID       = App.Instance.OAuthSettings.ClientId;
            Settings.DisplayName = "Giggle Gaggle";

            var manager = BITHockeyManager.SharedHockeyManager;

            manager.Configure("616fb4fca5c94837a3df3f2781c0db09");
            manager.StartManager();

            Xamarin.Forms.Size size = new Xamarin.Forms.Size();
            size.Height = UIScreen.MainScreen.Bounds.Height;
            size.Width  = UIScreen.MainScreen.Bounds.Width;

            App.ScreenSize = size;

            App.Scale = UIScreen.MainScreen.Scale;

            Xamarin.FormsMaps.Init();

            return(base.FinishedLaunching(app, options));
        }
예제 #7
0
        public async Task <ICameraPreview> OpenWithPreviewAsync(Xamarin.Forms.Size previewRequestSize)
        {
            await OpenAsync(true);

            var stateCallback = new StateCallback();

            stateCallback.Configured      += SessionConfigured;
            stateCallback.ConfigureFailed += SessionConfigureFailed;
            var previewSurface = _cameraPreview.CreateSurface(previewRequestSize);

            _previewRequestBuilder.AddTarget(previewSurface);
            _previewRequestBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);

            var characteristics = _manager.GetCameraCharacteristics(_cameraDevice.Id);
            var map             = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);

            // ReSharper disable once CoVariantArrayConversion
            _imageSize = (Size)Collections.Max(
                Arrays.AsList(map.GetOutputSizes((int)ImageFormatType.Jpeg)),
                new CompareSizesByArea());

            _imageReader = ImageReader.NewInstance(_imageSize.Width, _imageSize.Height,
                                                   ImageFormatType.Jpeg, /* maxImages */ 2);
            _imageAvailableListener = new ImageAvailableListener();
            _imageAvailableListener.ImageAvailable += CaptureAvailable;
            _imageReader.SetOnImageAvailableListener(_imageAvailableListener, _backgroundThread.Handler);
            var surfaces = new List <Surface> {
                previewSurface, _imageReader.Surface
            };

            _cameraDevice.CreateCaptureSession(surfaces, stateCallback, null);
            return(_cameraPreview);
        }
예제 #8
0
파일: Context.cs 프로젝트: kpalosaa/cross2d
        public void DrawImage(IImage image, float x, float y, float width, float height, Xamarin.Forms.Aspect aspect)
        {
            if (image != null)
            {
                Bitmap bitmap = ((Image)image).NativeImage;
                if (bitmap != null)
                {
                    if (aspect == Xamarin.Forms.Aspect.Fill)
                    {
                        using (RectF rect = new RectF(x, y, x + width - 1, y + height - 1))
                            canvas.DrawBitmap(bitmap, null, rect, null);
                    }
                    else
                    {
                        Xamarin.Forms.Size bounding = new Xamarin.Forms.Size(width, height);

                        if (aspect == Xamarin.Forms.Aspect.AspectFill)
                        {
                            Xamarin.Forms.Rectangle imageBox = MathHelper.Fill(new Xamarin.Forms.Rectangle(Xamarin.Forms.Point.Zero, image.Size), bounding);
                            using (RectF rectB = new RectF(x, y, x + width - 1, y + height - 1))
                                using (Rect rectI = new Rect((int)imageBox.X, (int)imageBox.Y, (int)imageBox.X + (int)imageBox.Width - 1, (int)imageBox.Y + (int)imageBox.Height - 1))
                                    canvas.DrawBitmap(bitmap, rectI, rectB, null);
                        }
                        else
                        {
                            Xamarin.Forms.Rectangle boundingBox = MathHelper.Fit(image.Size, new Xamarin.Forms.Rectangle(x, y, width, height));
                            using (RectF rect = new RectF((float)boundingBox.X, (float)boundingBox.Y, (float)boundingBox.X + (float)boundingBox.Width - 1, (float)boundingBox.Y + (float)boundingBox.Height - 1))
                                canvas.DrawBitmap(bitmap, null, rect, null);
                        }
                    }
                }
            }
        }
예제 #9
0
        public static Size ToAndroidSize(Xamarin.Forms.Size dpSize)
        {
            var(width, height) = dpSize;
            var widthPx  = ConvertDpToPixel((float)width);
            var heightPx = ConvertDpToPixel((float)height);

            return(new Size(widthPx, heightPx));
        }
예제 #10
0
        private void OnMainPageLoaded(object sender, RoutedEventArgs e)
        {
            this.Frame.SizeChanged += (o, args) =>
            {
                Size t = new Size(args.NewSize.Width, args.NewSize.Height);

                ((GrampsView.App)Xamarin.Forms.Application.Current).Services.GetService <IMessenger>().Send(new SSharpMessageWindowSizeChanged(t));
            };
        }
예제 #11
0
        /// <summary>
        /// 设置对话框的Size(安卓单位)
        /// </summary>
        /// <param name="xfSize"></param>
        /// <returns></returns>
        protected virtual Size SetDialogSize(ref Xamarin.Forms.Size xfSize)
        {
            xfSize = _xfView.Measure(DPoint.X, DPoint.Y).Request;
            var density = Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density;
            int width   = (int)Math.Ceiling(xfSize.Width * density);
            int height  = (int)Math.Ceiling(xfSize.Height * density);

            _dialogSize = new Size(width, height);
            return(_dialogSize);
        }
        public static Xamarin.Forms.Rectangle GetXfViewFrame(this FrameworkElement element)
        {
            var transform = element.TransformToVisual(null);
            var point     = transform.TransformPoint(new Windows.Foundation.Point(0, 0));
            //var xfPoint = new Xamarin.Forms.Point(point.X / Display.Scale, point.Y / Display.Scale);
            var xfPoint = point.ToXfPoint();
            var xfSize  = new Xamarin.Forms.Size(element.ActualWidth / Display.Scale, element.ActualHeight / Display.Scale);

            return(new Xamarin.Forms.Rectangle(xfPoint, xfSize));
        }
예제 #13
0
        public Xamarin.Forms.Size MeasureText(string text)
        {
            CanvasTextFormat textFormat = font != null ? ((Font)font).NativeTextFormat : defaultTextFormat;

            CanvasTextLayout textLayout = new CanvasTextLayout(ds, text, textFormat, Single.PositiveInfinity, Single.PositiveInfinity);

            Xamarin.Forms.Size size = new Xamarin.Forms.Size(textLayout.LayoutBounds.Width, textLayout.LayoutBounds.Height);
            textLayout.Dispose();

            return(size);
        }
예제 #14
0
        public Xamarin.Forms.Size GetImageSize(string name)
        {
            UIImage image = UIImage.FromFile(name);

            var size = new Xamarin.Forms.Size(
                (double)image.Size.Width,
                (double)image.Size.Height);

            image.Dispose();

            return(size);
        }
예제 #15
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (_dialogElement != null)
            {
                _dialogElement.OnCreated(_iDialogMsg);
            }
            var size      = new Xamarin.Forms.Size();
            var droidView = _xfView.ConvertFormsToNative(_mContext);

            _dialogSize = SetDialogSize(ref size);
            _xfView.Layout(new Xamarin.Forms.Rectangle(Xamarin.Forms.Point.Zero,
                                                       size));
            return(droidView);
        }
        public void UpdateMarkerLayout()
        {
            Components.MarkerView element = Element;
            if (element == null)
            {
                return;
            }
            var size = element.Measure(double.PositiveInfinity, double.PositiveInfinity, Xamarin.Forms.MeasureFlags.IncludeMargins);

            Xamarin.Forms.Size request = size.Request;
            Frame = new CGRect(element.X, element.Y, request.Width, request.Height);
            LayoutSubviews();
            UpdateCanvasInfo(Frame, UIKit.UIScreen.MainScreen.Scale);
        }
예제 #17
0
        public override Xamarin.Forms.SizeRequest Measure(Xamarin.Forms.Size availableSize)
        {
            var lblSize = base.Measure(availableSize);

            if (_image9 != null)
            {
                return(new Xamarin.Forms.SizeRequest(new Xamarin.Forms.Size(_image9.Width, _image9.Height), new Xamarin.Forms.Size(_image9.Stretch.Horizontal.Margin, _image9.Stretch.Vertical.Margin)));
            }

            if (_image != null)
            {
                return(new Xamarin.Forms.SizeRequest(new Xamarin.Forms.Size(_image.Width, _image.Height), default(Xamarin.Forms.Size)));
            }

            return(lblSize);
        }
예제 #18
0
        void InternalSetPage(Xamarin.Forms.Page page)
        {
            IList <Action <SKCanvas, int, int> > renderChildren = new List <Action <SKCanvas, int, int> >();

            _layout.AddView(new NativeSkiaView(this, new SkiaView((canvas, w, h) =>
            {
                canvas.Clear(SKColors.White);
                _canvas = canvas;
                _size   = new Xamarin.Forms.Size(w, h);
                foreach (var renderer in renderChildren)
                {
                    renderer(canvas, w, h);
                }
            })));

            _layout.BringToFront();

            AddRenderers(page, renderChildren);
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            CrashManager.Register(this, "e4a1f908bf294318a617d37642aec6d4");

            var size    = new Xamarin.Forms.Size();
            var metrics = Resources.DisplayMetrics;

            size.Height = metrics.HeightPixels;
            size.Width  = metrics.WidthPixels;

            App.Scale = metrics.Density;

            Xamarin.FormsMaps.Init(this, bundle);

            LoadApplication(new App());
        }
 protected virtual void SetViewAndText(Toast toast)
 {
     if (_toastView != null)
     {
         //设定文本
         var dialogEle = _toastView as IDialogElement;
         dialogEle?.OnCreated(_dialogMsg);
         var droidView = _toastView.ConvertFormsToNative(_mContext);
         var winWidth  = WindowSize.X / Density;
         var winHeight = WindowSize.Y / Density;
         _toastViewSize = _toastView.Measure(winWidth, winHeight).Request;
         _toastView.Layout(new Xamarin.Forms.Rectangle(0, 0, _toastViewSize.Width, _toastViewSize.Height));
         var lastView = WrapperViewAndControlSize(droidView);
         toast.View = lastView;
     }
     else
     {
         toast.SetText(_dialogMsg.Msg);
     }
 }
예제 #21
0
        public Xamarin.Forms.Size MeasureText(string text)
        {
            if (font == null || font.NativeFont == null)
            {
                return(Xamarin.Forms.Size.Zero);
            }

            var attributedString = new NSAttributedString(text, new CTStringAttributes()
            {
                Font = font.NativeFont, ForegroundColorFromContext = true
            });
            CTLine ctLine = new CTLine(attributedString);

            Xamarin.Forms.Size size = new Xamarin.Forms.Size((float)ctLine.GetTypographicBounds(), font.NativeFont.CapHeightMetric + font.NativeFont.DescentMetric);

            ctLine.Dispose();
            attributedString.Dispose();

            return(size);
        }
 /// <summary>
 /// Get image stream from lines
 /// </summary>
 /// <param name="points">Drawing lines</param>
 /// <param name="imageSize">Image size</param>
 /// <param name="backgroundColor">Image background color</param>
 /// <returns>Image stream</returns>
 public static Stream GetImageStream(IList <Line> lines,
                                     Size imageSize,
                                     Color backgroundColor) =>
 Stream.Null;
예제 #23
0
파일: Context.cs 프로젝트: kpalosaa/cross2d
 public Xamarin.Forms.Size PixelToDip(Xamarin.Forms.Size pixel)
 {
     return(new Xamarin.Forms.Size(pixel.Width * density, pixel.Height * density));
 }
예제 #24
0
 public Xamarin.Forms.Size DipToPixel(Xamarin.Forms.Size dip)
 {
     return(new Xamarin.Forms.Size(dip.Width * scaleInv, dip.Height * scaleInv));
 }
 public static CCSizeI NativeSize(this Xamarin.Forms.Size size)
 {
     return(new CCSizeI((int)size.Width, (int)size.Height));
 }
		public Xamarin.Forms.Size GetCameraSize()
		{
			Xamarin.Forms.Size camSize = new  Xamarin.Forms.Size ();
			Android.Hardware.Camera cam = Android.Hardware.Camera.Open ();
			Android.Hardware.Camera.Parameters cameraParams =  cam.GetParameters ();
			camSize.Height = cameraParams.PictureSize.Height;
			camSize.Width = cameraParams.PictureSize.Width;

			cam.StopPreview ();
			cam.Release ();
			cam.Dispose ();
			return camSize;

		}
 /// <summary>
 /// Overriding Set size
 /// </summary>
 /// <param name="size"></param>
 void IVisualElementRenderer.SetElementSize(Xamarin.Forms.Size size)
 {
     Element.OnSizeChanged((float)size.Width, (float)size.Height);
     SetElementSize(size);
 }
예제 #28
0
 public Xamarin.Forms.Size PixelToDip(Xamarin.Forms.Size pixel)
 {
     return(new Xamarin.Forms.Size(pixel.Width * scale, pixel.Height * scale));
 }
 /// <summary>
 /// Get image stream from points
 /// </summary>
 /// <param name="points">Drawing points</param>
 /// <param name="imageSize">Image size</param>
 /// <param name="lineWidth">Line Width</param>
 /// <param name="strokeColor">Line color</param>
 /// <param name="backgroundColor">Image background color</param>
 /// <returns>Image stream</returns>
 public static Stream GetImageStream(IList <Point> points,
                                     Size imageSize,
                                     float lineWidth,
                                     Color strokeColor,
                                     Color backgroundColor) =>
 Stream.Null;