public void Initialize() { SetBackgroundColor(Color.Transparent); _scale = Resources.DisplayMetrics.Density; _canvas = new SKCanvasView(Context); _canvas.PaintSurface += CanvasOnPaintSurface; AddView(_canvas); Map = new Map(); _renderer = new Rendering.Skia.MapRenderer(); TryInitializeViewport(); Touch += MapView_Touch; _gestureDetector = new GestureDetector(Context, new GestureDetector.SimpleOnGestureListener()); _gestureDetector.SingleTapConfirmed += OnSingleTapped; _gestureDetector.DoubleTap += OnDoubleTapped; }
public MonkeyThroughKeyholePage() { Title = "Monkey through Keyhole"; SKCanvasView canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; Content = canvasView; string resourceID = "SkiaSharpFormsDemos.Media.SeatedMonkey.jpg"; Assembly assembly = GetType().GetTypeInfo().Assembly; using (Stream stream = assembly.GetManifestResourceStream(resourceID)) using (SKManagedStream skStream = new SKManagedStream(stream)) { bitmap = SKBitmap.Decode(skStream); } }
private void Initialize() { var window = new Window("SkiaSharp"); window.BackButtonPressed += OnBackButtonPressed; window.AvailableRotations = DisplayRotation.Degree_0 | DisplayRotation.Degree_180 | DisplayRotation.Degree_270 | DisplayRotation.Degree_90; window.Show(); var skiaView = new SKCanvasView(window); skiaView.PaintSurface += OnPaintSurface; skiaView.Show(); var conformant = new Conformant(window); conformant.Show(); conformant.SetContent(skiaView); }
public void Draw(SKCanvasView skCanvasView, SKCanvas skCanvas) { skCanvas.Clear(); if (_highlightState == null) { return; } if (_skPaint == null) { _skPaint = CreateHighlightSkPaint(skCanvasView, _highlightSettings, _highlightState.HighlightPath); } var strokeDash = _highlightState.StrokeDash; // Comment the next line to see whole path without dash effect _skPaint.PathEffect = SKPathEffect.CreateDash(strokeDash.Intervals, strokeDash.Phase); skCanvas.DrawPath(_highlightState.HighlightPath.Path, _skPaint); }
protected override void OnElementChanged(ElementChangedEventArgs <Layout> e) { base.OnElementChanged(e); _clipper = new SKClipperView(Forms.NativeParent); _clipper.Show(); _clipper.PassEvents = true; _clipper.PaintSurface += OnCliperPaint; Control.Children.Add(_clipper); BackgroundCanvas?.StackAbove(_clipper); _shadowCanvasView = new SKCanvasView(Forms.NativeParent); _shadowCanvasView.Show(); _shadowCanvasView.PassEvents = true; _shadowCanvasView.PaintSurface += OnShadowPaint; Control.Children.Add(_shadowCanvasView); _shadowCanvasView.Lower(); _shadowCanvasView.SetClip(null); }
public CornerToCornerGradientPage() { Title = "Corner-to-Corner Gradient"; SKCanvasView canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; Content = canvasView; TapGestureRecognizer tap = new TapGestureRecognizer(); tap.Tapped += (sender, args) => { drawBackground ^= true; canvasView.InvalidateSurface(); }; canvasView.GestureRecognizers.Add(tap); }
public MainPage() { Title = "MyTests"; InitializeComponent(); _cam = new Camera(5, 9, 16); _hlist.Add(new Sphere(new Vector3(0, 0, 2), 1.0, new Lamberian(new Vector3(0.8, 0.3, 0.3)))); _hlist.Add(new Sphere(new Vector3(0, -100, 20), 100.0, new Lamberian(new Vector3(0.8, 0.8, 0.0)))); _hlist.Add(new Sphere(new Vector3(2, 0, 2), 1.0, new Metal(new Vector3(0.8, 0.6, 0.2), 0.0))); _hlist.Add(new Sphere(new Vector3(-2, 0, 2), 1.0, new Dielectric(1.5))); canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; Content = canvasView; }
private void CreateTouchInterface() { this.Content = null; _touchPoints.Clear(); if (this.VerticalTouchPoints <= 0 || this.HorizontalTouchPoints <= 0) { return; } _canvas = new SKCanvasView(); _canvas.IgnorePixelScaling = false; _canvas.EnableTouchEvents = true; _canvas.PaintSurface += CanvasOnPaintSurface; _canvas.Touch += CanvasOnTouch; this.Content = _canvas; }
public MainPage() { InitializeComponent(); PopulatePointsList(); string resourceID = "SolixTest.Resources.image.png"; Assembly assembly = GetType().GetTypeInfo().Assembly; using (Stream stream = assembly.GetManifestResourceStream(resourceID)) { bitmap = SKBitmap.Decode(stream); } SKCanvasView canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; var Content = canvasView; }
public ClippingTextPage() { Title = "Clipping Text"; SKCanvasView canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; Content = canvasView; string resourceID = "SkiaSharpFormsDemos.Media.PageOfCode.png"; Assembly assembly = GetType().GetTypeInfo().Assembly; using (Stream stream = assembly.GetManifestResourceStream(resourceID)) using (SKManagedStream skStream = new SKManagedStream(stream)) { bitmap = SKBitmap.Decode(skStream); } }
public TileAlignmentPage() { Title = "Tile Alignment"; SKCanvasView canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; // Add tap handler TapGestureRecognizer tap = new TapGestureRecognizer(); tap.Tapped += (sender, args) => { isAligned ^= true; canvasView.InvalidateSurface(); }; canvasView.GestureRecognizers.Add(tap); Content = canvasView; }
public PredictionResultsPage(MediaDetails media, ImagePrediction prediction) { Title = ApplicationResource.PagePredictionResultsTitle; BindingContext = viewModel = new PredictionResultsViewModel(Navigation, media, prediction); viewModel.PredictionsChanged += OnPredictionsChanged; var screenSize = new Size(App.ScreenWidth, App.ScreenHeight); // Image View photoView = new Image(); photoView.Source = ImageSource.FromFile(media.FullPath); AbsoluteLayout.SetLayoutBounds(photoView, new Rectangle(0, 0, 1, 1)); AbsoluteLayout.SetLayoutFlags(photoView, AbsoluteLayoutFlags.All); // Canvas View canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; AbsoluteLayout.SetLayoutBounds(canvasView, new Rectangle(0, 0, 1, 1)); AbsoluteLayout.SetLayoutFlags(canvasView, AbsoluteLayoutFlags.All); // Slider view Slider confidenceSlider = new Slider() { Minimum = 0, Maximum = 1 }; confidenceSlider.SetBinding(Slider.ValueProperty, new Binding("Confidence")); AbsoluteLayout.SetLayoutBounds(confidenceSlider, new Rectangle(.5, 1, .8, .1)); AbsoluteLayout.SetLayoutFlags(confidenceSlider, AbsoluteLayoutFlags.All); var layout = new AbsoluteLayout(); layout.Margin = new Thickness(10); layout.Children.Add(photoView); layout.Children.Add(canvasView); layout.Children.Add(confidenceSlider); layout.SizeChanged += Layout_SizeChanged; Content = layout; var orientation = ImageUtils.GetImageOrientation(media.FullPath); imageBytes = File.ReadAllBytes(media.FullPath); masterBitmap = ImageUtils.HandleOrientation(SKBitmap.Decode(imageBytes), orientation); }
private void _readyOption( PageComponentType pcType, IGameOption opt, EventHandler PressFunc = null ) { if (null == opt) { return; } if (null != opt.SubOptions) { _readyOptionSet( pcType, opt.SubOptions, PressFunc ); return; } SKCanvasView Img = new SKCanvasView(); IFlorineSkiaConnectable conn = opt as IFlorineSkiaConnectable; if (null != conn) { conn.ConnectCanvasView(Img); } IFlorineSkiaEventDriver econn = opt as IFlorineSkiaEventDriver; if (null != econn) { if (null != PressFunc) { econn.OnEventTriggered += PressFunc; } } _components.Add( new PageComponent( _inc(pcType), Img ) ); }
public ConveyorBeltPage() { Title = "Conveyor Belt"; canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; Content = canvasView; // Create the path for the bucket starting with the handle bucketPath.AddRect(new SKRect(-5, -3, 25, 3)); // Sides bucketPath.AddRoundedRect(new SKRect(25, -19, 27, 18), 10, 10, SKPathDirection.CounterClockwise); bucketPath.AddRoundedRect(new SKRect(63, -19, 65, 18), 10, 10, SKPathDirection.CounterClockwise); // Five slats for (int i = 0; i < 5; i++) { bucketPath.MoveTo(25, -19 + 8 * i); bucketPath.LineTo(25, -13 + 8 * i); bucketPath.ArcTo(50, 50, 0, SKPathArcSize.Small, SKPathDirection.CounterClockwise, 65, -13 + 8 * i); bucketPath.LineTo(65, -19 + 8 * i); bucketPath.ArcTo(50, 50, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 25, -19 + 8 * i); bucketPath.Close(); } // Arc to suggest the hidden side bucketPath.MoveTo(25, -17); bucketPath.ArcTo(50, 50, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 65, -17); bucketPath.LineTo(65, -19); bucketPath.ArcTo(50, 50, 0, SKPathArcSize.Small, SKPathDirection.CounterClockwise, 25, -19); bucketPath.Close(); // Make it a little bigger and correct the orientation bucketPath.Transform(SKMatrix.MakeScale(-2, 2)); bucketPath.Transform(SKMatrix.MakeRotationDegrees(90)); }
public PixelDimensionsPage() { Title = "Pixel Dimensions"; // Load the bitmap from a resource string resourceID = "SkiaSharpFormsDemos.Media.Banana.jpg"; Assembly assembly = GetType().GetTypeInfo().Assembly; using (Stream stream = assembly.GetManifestResourceStream(resourceID)) { bitmap = SKBitmap.Decode(stream); } // Create the SKCanvasView and set the PaintSurface handler SKCanvasView canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; Content = canvasView; }
//CONSTRUCTOR public CongestionControlDraw() { textSize = 5; strokeWidth = 0.2f; // crate the canvas skiaview = new SKCanvasView(); skiaview.PaintSurface += PaintSurface; AddGestureRecognizers(); stateR = CongestionControl.stateR; stateT = CongestionControl.stateT; maxCwnd = CongestionControl.maxCwnd; numberOfRounds = CongestionControl.numberOfRounds; xWidth = 92f / (numberOfRounds + 1); yWidth = 93f / (maxCwnd + 1); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it _canvasView = FindViewById <SKCanvasView>(Resource.Id.canvasView); _canvasView.PaintSurface += OnPaint; _touchHandler = new TouchHandler() { UseTouchSlop = true }; _touchHandler.RegisterEvents(_canvasView); _touchHandler.TouchAction += OnTouch; }
public void Initialize() { SetBackgroundColor(Color.Transparent); _density = PixelsPerDeviceIndependentUnit; _canvas = new SKCanvasView(Context) { IgnorePixelScaling = true }; _canvas.PaintSurface += CanvasOnPaintSurface; AddView(_canvas); Map = new Map(); TryInitializeViewport(ScreenWidth, ScreenHeight); Touch += MapView_Touch; _gestureDetector = new GestureDetector(Context, new GestureDetector.SimpleOnGestureListener()); _gestureDetector.SingleTapConfirmed += OnSingleTapped; _gestureDetector.DoubleTap += OnDoubleTapped; }
public CakeOrientation(CarbonFootprint co2, SKCanvasView canvasView) { this.CanvasView = canvasView; this.Width = (float)canvasView.Width; this.Height = (float)canvasView.Height; this.CurrentlySelected = null; this.Center = new SKPoint(Width / 2, Height / 2); this.Thickness = Width / 10; this.IconOffset = Width / 50; this.IconRadius = Width / 12; this.Radius = Math.Min(Width / 2, Height / 2) - 1.5f * Width / 12; //System.Diagnostics.Debug.WriteLine("Width: " + size.Width); this.TotalValues = 0; this.CO2 = co2; this.PopOver = new PopOver(Radius - Thickness * 1.3f, Width / 5, Width / 14, Width / 18); this.BoldFont = new SKPaint { IsAntialias = true, Style = SKPaintStyle.Fill, TextAlign = SKTextAlign.Center, Typeface = SKTypeface.FromFile("OpenSans-Bold.ttf") }; this.NormalFont = new SKPaint { IsAntialias = true, Style = SKPaintStyle.Fill, TextAlign = SKTextAlign.Center, Typeface = SKTypeface.FromFile("OpenSans-Normal.ttf") }; foreach (IEmission Emission in CO2.Emissions) { TotalValues += (float)Emission.KgCO2; } PiecesOfCake = new PieceOfCake[co2.Emissions.Length]; InitializeCake(); }
public override void ViewDidLoad() { base.ViewDidLoad(); Controller = new LS.UI.GameController(this); Controller.Startup(new FileStorage()); Canvas = new CanvasView(View.Frame) { IgnorePixelScaling = true }; Canvas.PaintSurface += OnPlatformPaint; View.AddSubview(Canvas); Canvas.AutoresizingMask = NSViewResizingMask.MinXMargin | NSViewResizingMask.MinYMargin | NSViewResizingMask.MaxXMargin | NSViewResizingMask.MaxYMargin | NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; }
private void menuItemCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e) { if (sender == null) { return; } SKCanvasView canvasView = (SKCanvasView)sender; GHMenuItem menuitem = (GHMenuItem)canvasView.BindingContext; if (menuitem != null) { //SKImageInfo info = e.Info; SKSurface surface = e.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(SKColors.Transparent); //float width = info.Width; //float height = info.Height; float canvaswidth = canvasView.CanvasSize.Width; float canvasheight = canvasView.CanvasSize.Height; int signed_glyph = menuitem.Glyph; int glyph = Math.Abs(signed_glyph); bool hflip = (signed_glyph < 0); if (glyph < _gamePage.Glyph2Tile.Length) { int ntile = _gamePage.Glyph2Tile[glyph]; int sheet_idx = _gamePage.TileSheetIdx(ntile); int tile_x = _gamePage.TileSheetX(ntile); int tile_y = _gamePage.TileSheetY(ntile); int tile_extra_y = GHConstants.TileHeight / 2; SKRect sourcerect = new SKRect(tile_x, tile_y + tile_extra_y, tile_x + GHConstants.TileWidth, tile_y + GHConstants.TileHeight); SKRect targetrect = new SKRect(0, 0, canvaswidth, canvasheight); canvas.DrawBitmap(_gamePage.TileMap[sheet_idx], sourcerect, targetrect); } } }
public App() { _canvasView = new SKCanvasView { HeightRequest = 100, WidthRequest = 100 }; // use a closure so can bind to our contextual items data // painting on rapidly triggered callback means OpenGL surface calcs are done // and dimensions known at that point _canvasView.PaintSurface += (object sender, SKPaintSurfaceEventArgs paintArgs) => { SKImageInfo info = paintArgs.Info; SKSurface surface = paintArgs.Surface; SKCanvas canvas = surface.Canvas; Debug.WriteLine($"canvas bounds {canvas.LocalClipBounds}"); canvas.Clear(); DrawImageFromResource(canvas, _paint); }; // The root page of your application var content = new ContentPage { Title = "SkiaImageDraw", Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { new Label { HorizontalTextAlignment = TextAlignment.Center, Text = "png drawn by Image then within Skia canvas" }, new Image { Source = "day_shift.png" }, _canvasView } } }; MainPage = new NavigationPage(content); }
protected override void OnElementChanged(ElementChangedEventArgs<Layout> e) { if (Control == null) { SetNativeControl(new Canvas(Forms.NativeParent)); _canvasView = new SKCanvasView(Forms.NativeParent); _canvasView.PaintSurface += OnPaintSurface; _canvasView.Show(); Control.Children.Add(_canvasView); Interop.evas_object_clip_unset(_canvasView); Control.LayoutUpdated += OnLayoutUpdated; if (ShadowsElement.Shades is INotifyCollectionChanged items) { items.CollectionChanged += OnShadesCollectionChanged; } _shadesSource = ShadowsElement.Shades; } base.OnElementChanged(e); }
public PrimaryColorsPage() { Title = "Primary Colors"; SKCanvasView canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; // Switch between additive and subtractive primaries at tap TapGestureRecognizer tap = new TapGestureRecognizer(); tap.Tapped += (sender, args) => { isSubtractive ^= true; canvasView.InvalidateSurface(); }; canvasView.GestureRecognizers.Add(tap); Content = canvasView; }
public PosterizePage() { Title = "Posterize"; unsafe { uint *ptr = (uint *)bitmap.GetPixels().ToPointer(); int pixelCount = bitmap.Width * bitmap.Height; for (int i = 0; i < pixelCount; i++) { *ptr++ &= 0xE0E0E0FF; } } SKCanvasView canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; Content = canvasView; }
public ModelViewSurface(RodModelVM viewModel, SKCanvasView view) { RModelView = view; modelVM = viewModel; RModelView.PaintSurface += OnPaintSurface; RModelView.SizeChanged += OnViewSizeChanged; ModelViewFragment = new IssoPoint2D() { X = 0, Y = 0 }; StartPt = new IssoPoint2D() { X = 0, Y = 0 }; EndPt = new IssoPoint2D() { X = 0, Y = 0 }; Grid = new SurfaceGrid(); }
public XFrame() { //this.HasShadow = false; //this.Padding = 0; this.BackgroundColor = Color.Transparent; canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; Console.WriteLine(":::::>>>>> COLOR " + BaseColor); InitAll(); //Content = canvasView; // Draw Rectangle }
private async void Button_Clicked(object sender, EventArgs e) { Success.IsVisible = false; //var webClient = new WebClient(); //byte[] imageData = webClient.DownloadData("https://kasikornbank.com/SiteCollectionDocuments/about/img/logo/logo.png"); ICreateReceipt photoLibrary = DependencyService.Get <ICreateReceipt>(); string filename = DateTime.Now.ToString("yyyyMMdd-hhmmss"); string extension = ".png"; var data = CreateImage(); bool result = await photoLibrary.SavePhotoAsync(data, "Xamarin", filename + extension); SKCanvasView sKCanvasView = new SKCanvasView(); sKCanvasView.HeightRequest = 300; sKCanvasView.HorizontalOptions = LayoutOptions.CenterAndExpand; sKCanvasView.WidthRequest = 50; sKCanvasView.PaintSurface += SKCanvasView_PaintSurface; stack.Children.Add(sKCanvasView); Success.IsVisible = true; }
public ShapeView(EvasObject parent) : base(parent) { _skPaint = new SKPaint(); _skPaint.IsAntialias = true; _skCanvasView = new SKCanvasView(parent); _skCanvasView.PaintSurface += OnPaintSurface; _skCanvasView.Show(); Children.Add(_skCanvasView); LayoutUpdated += OnLayoutUpdated; _pathFillBounds = new SKRect(); _pathStrokeBounds = new SKRect(); _skPaint.StrokeCap = SKStrokeCap.Butt; _skPaint.StrokeJoin = SKStrokeJoin.Miter; _strokeWidth = 1f; _strokeDashOffset = 0f; _strokeMiterLimit = 10f; _stretch = Stretch.None; }
public void Initialize() { Xamarin.Forms.View view; if (UseGPU) { // Use GPU backend _glView = new SKGLView { HasRenderLoop = false, EnableTouchEvents = true, }; // Events _glView.Touch += OnTouch; _glView.PaintSurface += OnGLPaintSurface; _invalidate = () => { RunOnUIThread(() => _glView.InvalidateSurface()); }; view = _glView; } else { // Use CPU backend _canvasView = new SKCanvasView { EnableTouchEvents = true, }; // Events _canvasView.Touch += OnTouch; _canvasView.PaintSurface += OnPaintSurface; _invalidate = () => { RunOnUIThread(() => _canvasView.InvalidateSurface()); }; view = _canvasView; } view.SizeChanged += OnSizeChanged; Content = view; Map = new Map(); BackgroundColor = Color.White; _initialized = true; }