public PathShape ToFillPathShape(IToolContext context, IBaseShape shape) { using (var geometry = ToPath(context, shape)) { if (geometry != null) { var style = context.DocumentContainer?.StyleLibrary?.Get(shape.StyleId); if (style == null) { style = context.DocumentContainer?.StyleLibrary?.CurrentItem; } var path = SkiaHelper.ToFillPath(context, style, geometry); if (path != null) { var union = SkiaHelper.Op(SKPathOp.Union, new[] { path, path }); if (union != null && !union.IsEmpty) { return(SkiaHelper.ToPathShape(context, union, context.DocumentContainer?.StyleLibrary?.CurrentItem, context?.DocumentContainer?.PointTemplate)); } } } } return(null); }
public void Import(IToolContext context, string path, IContainerView containerView) { try { var picture = SkiaHelper.ToSKPicture(path); if (picture != null) { var image = new ImageShape() { Points = new ObservableCollection <IPointShape>(), StartPoint = new PointShape(0.0, 0.0, context?.DocumentContainer?.PointTemplate), Point = new PointShape(picture.CullRect.Width, picture.CullRect.Height, context?.DocumentContainer?.PointTemplate), Path = path, StretchMode = StretchMode.Center, Text = new Text(), StyleId = context.DocumentContainer?.StyleLibrary?.CurrentItem?.Title, }; image.StartPoint.Owner = image; image.Point.Owner = image; picture.Dispose(); context.DocumentContainer?.ContainerView?.CurrentContainer.Shapes.Add(image); context.DocumentContainer?.ContainerView?.InputService?.Redraw?.Invoke(); } } catch (Exception ex) { Log.WriteLine(ex.Message); Log.WriteLine(ex.StackTrace); } }
private IList <SKPath> ToPaths(IToolContext context, IList <IBaseShape> shapes) { if (shapes == null || shapes.Count <= 0) { return(null); } var paths = new List <SKPath>(); for (int i = 0; i < shapes.Count; i++) { var fillType = SKPathFillType.Winding; if (shapes[i] is PathShape pathShape) { fillType = SkiaHelper.ToSKPathFillType(pathShape.FillType); } var path = new SKPath() { FillType = fillType }; var result = SkiaHelper.AddShape(context, shapes[i], 0.0, 0.0, path); if (result == true && path.IsEmpty == false) { paths.Add(path); } else { path.Dispose(); } } return(paths); }
/// <summary> /// 设置位图矩阵 /// </summary> private void SetMainBitmapMatrix() { //计算矩形范围 var rect = SkiaHelper.CalculateRectangle(SkiaHelper.CalculateRectangle(rectInfo, outImageWidht, outImageHeight).rect, mainBitmap.Bitmap.Width, mainBitmap.Bitmap.Height, config.Aspect); mainBitmap.Matrix = new SKMatrix(rect.scaleX, 0, rectInfo.MidX - rect.rect.Width / 2, 0, rect.scaleY, rectInfo.MidY - rect.rect.Height / 2, 0, 0, 1); }
private SKPath ToPath(IToolContext context, IBaseShape shape) { var fillType = SKPathFillType.Winding; if (shape is PathShape pathShape) { fillType = SkiaHelper.ToSKPathFillType(pathShape.FillType); } var geometry = new SKPath() { FillType = fillType }; if (SkiaHelper.AddShape(context, shape, 0.0, 0.0, geometry) == true) { return(geometry); } else { geometry.Dispose(); } return(null); }
/// <summary> /// Any initialization steps that can be done in the background. /// </summary> public override void Initialize() { // init des location services. typeof(LocationService).Assembly.CreatableTypes() .EndingWith("Service") .AsInterfaces() .RegisterAsLazySingleton(); // static registration => same instance Mvx.IoCProvider.RegisterSingleton(Plugin.Settings.CrossSettings.Current); Mvx.IoCProvider.RegisterSingleton <ITcxActivityService>(() => new TcxActivityService()); Mvx.IoCProvider.RegisterSingleton <IDbActivityService>(() => new DbActivityService()); Mvx.IoCProvider.RegisterSingleton <DatabaseContext>(() => new DatabaseContext()); var context = Mvx.IoCProvider.Resolve <DatabaseContext>(); Mvx.IoCProvider.RegisterSingleton <IRideService>(() => new RideService(context)); // dynamic registration => new service on resolving Mvx.IoCProvider.RegisterType <ICountdownService>(() => new CountdownService()); this.RegisterAppStart <ViewModels.MainPageViewModel>(); SkiaHelper.Initialize((float)DeviceDisplay.MainDisplayInfo.Density); base.Initialize(); }
public PathShape ToFillPathShape(IToolContext context, IBaseShape shape) { using (var geometry = ToPath(context, shape)) { if (geometry != null) { var style = context.DocumentContainer?.StyleLibrary?.Get(shape.StyleId); if (style == null) { style = context.DocumentContainer?.StyleLibrary?.CurrentItem; } using (var disposable = new CompositeDisposable()) { var path = SkiaHelper.ToFillPath(context, style.FillPaint, shape.Effects, geometry, disposable.Disposables); if (path != null) { disposable.Disposables.Add(path); var union = SkiaHelper.Op(SKPathOp.Union, new[] { path, path }); if (union != null && !union.IsEmpty) { disposable.Disposables.Add(union); return(SkiaHelper.ToPathShape(context, union, context.DocumentContainer?.StyleLibrary?.CurrentItem, context?.DocumentContainer?.PointTemplate)); } } } } } return(null); }
public AMButton() { timer = new Timer(); timer.Interval = 10; timer.Tick += (object sender, EventArgs e) => { alpha += 10; color = Color.FromArgb(alpha, HighlightColor); if (alpha > 100) { timer.Stop(); } Invalidate(); }; this.FlatStyle = FlatStyle.Flat; this.FlatAppearance.BorderSize = 1; this.FlatAppearance.BorderColor = Color.LightGray; SKHelper = new SkiaHelper(); SKHelper.Size = new RawSize { Width = this.Width, Height = this.Height }; SKHelper.SwapChain(); }
public PathShape Op(IToolContext context, PathOp op, ICollection <IBaseShape> selected) { var path = default(PathShape); var shapes = GetShapes(selected); if (shapes != null && shapes.Count > 0) { var paths = ToPaths(context, shapes); if (paths != null && paths.Count > 0) { var result = SkiaHelper.Op(SkiaHelper.ToSKPathOp(op), paths); if (result != null) { if (!result.IsEmpty) { var style = context.DocumentContainer?.StyleLibrary?.Get(shapes[0].StyleId); if (style == null) { style = context.DocumentContainer?.StyleLibrary?.CurrentItem; } path = SkiaHelper.ToPathShape(context, result, style, context?.DocumentContainer?.PointTemplate); } result.Dispose(); } for (int i = 0; i < paths.Count; i++) { paths[i].Dispose(); } } } return(path); }
public MainPage() { InitializeComponent(); // - - - - - - MediaPlayer.Current.Playlist.RepeatMode = RepeatMode.Off;; MediaPlayer.Current.Playlist.ShuffleMode = ShuffleMode.Off; // Hook into events MediaPlayer.Current.StateChanged += Current_StateChanged; MediaPlayer.Current.PositionChanged += Current_PositionChanged; MediaPlayer.Current.BufferingChanged += Current_BufferingChanged; MediaPlayer.Current.MediaItemFinished += Current_MediaItemFinished; MediaPlayer.Current.MediaItemChanged += Current_MediaItemChanged; listViewPlaylist.BindingContext = MediaPlayer.Current; listViewPlaylist.ItemsSource = MediaPlayer.Current.Playlist; listViewPlaylist.SetBinding(ListView.SelectedItemProperty, new Binding("Current", BindingMode.TwoWay, source: MediaPlayer.Current.Playlist)); // - - - - - - #region FontIcon stuff switch (Device.RuntimePlatform) { case Device.Android: case Device.UWP: btnPlayPrevious.Text = ""; btnPlayPrevious.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Backward, 64); btnStepBackward.Text = ""; btnStepBackward.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Previous, 64); btnPlayPause.Text = ""; btnPlayPause.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Play_01, 64); btnStepForward.Text = ""; btnStepForward.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Next, 64); btnPlayNext.Text = ""; btnPlayNext.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Fast_Forward, 64); btnStop.Text = ""; btnStop.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Stop, 64); break; case Device.WPF: default: break; } ; #endregion }
private void AddBitmapToCanvas(TouchManipulationBitmap bitmap) { var rectImage = SkiaHelper.CalculateRectangle(rectInfo, outImageWidht, outImageHeight).rect; float scale = 0.25f; var rectSticker = new SKRect(rectImage.Left + rectImage.Width * scale, rectImage.Top + rectImage.Height * scale, rectImage.Right - rectImage.Width * scale, rectImage.Bottom - rectImage.Height * scale); var rect = SkiaHelper.CalculateRectangle(rectSticker, bitmap.Bitmap.Width, bitmap.Bitmap.Height); bitmap.Matrix = new SKMatrix(rect.scaleX, 0, rectInfo.MidX - rect.rect.Width / 2, 0, rect.scaleY, rectInfo.MidY - rect.rect.Height / 2, 0, 0, 1); bitmapCollection.Add(bitmap); }
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy) { using (var renderer = new SkiaShapeRenderer(_context, _view.SelectionState)) using (var background = SkiaHelper.ToSKPaintBrush(_view.PrintBackground, false)) { var canvas = context as SKCanvas; canvas.DrawRect(SkiaHelper.ToSKRect(dx, dy, _view.Width + dx, _view.Height + dy), background); _view.CurrentContainer.Draw(canvas, renderer, dx, dy, zx, null, null); } }
public void DrawConic(object dc, ConicShape conic, string styleId, double dx, double dy, double scale) { var geometry = new SKPath() { FillType = SKPathFillType.Winding }; SkiaHelper.AddConic(null, conic, dx, dy, geometry); _rootNodes[_currentRootNode].Children.Add(new ChildNode(conic, styleId, dx, dy, scale, geometry)); }
public void DrawRectangle(object dc, RectangleShape rectangle, string styleId, double dx, double dy, double scale) { var geometry = new SKPath() { FillType = SKPathFillType.Winding }; SkiaHelper.AddRect(null, rectangle, dx, dy, geometry); _rootNodes[_currentRootNode].Children.Add(new ChildNode(rectangle, styleId, dx, dy, scale, geometry)); }
public void DrawQuadraticBezier(object dc, QuadraticBezierShape quadraticBezier, string styleId, double dx, double dy, double scale) { var geometry = new SKPath() { FillType = SKPathFillType.Winding }; SkiaHelper.AddQuad(null, quadraticBezier, dx, dy, geometry); _rootNodes[_currentRootNode].Children.Add(new ChildNode(quadraticBezier, styleId, dx, dy, scale, geometry)); }
public void DrawText(object dc, TextShape text, string styleId, double dx, double dy, double scale) { var geometry = new SKPath() { FillType = SKPathFillType.Winding }; SkiaHelper.AddText(null, text, dx, dy, geometry); _rootNodes[_currentRootNode].Children.Add(new ChildNode(text, styleId, dx, dy, scale, geometry)); }
public void DrawEllipse(object dc, EllipseShape ellipse, string styleId, double dx, double dy, double scale) { var geometry = new SKPath() { FillType = SKPathFillType.Winding }; SkiaHelper.AddOval(null, ellipse, dx, dy, geometry); _rootNodes[_currentRootNode].Children.Add(new ChildNode(ellipse, styleId, dx, dy, scale, geometry)); }
protected override async void OnInitialized() { Xamarin.Forms.Internals.Log.Listeners.Add(new DelegateLogListener((arg1, arg2) => Console.WriteLine($"{arg1}: {arg2}"))); InitializeComponent(); SkiaHelper.Initialize((float)DeviceDisplay.MainDisplayInfo.Density); await NavigationService.NavigateAsync("NavigationPage/ActivityHeaderPage"); }
public void DrawPath(object dc, PathShape path, string styleId, double dx, double dy, double scale) { var geometry = new SKPath() { FillType = SkiaHelper.ToSKPathFillType(path.FillType) }; SkiaHelper.AddPath(null, path, dx, dy, geometry); _rootNodes[_currentRootNode].Children.Add(new ChildNode(path, styleId, dx, dy, scale, geometry)); }
public string ToSvgPathData(IToolContext context, ICollection <IBaseShape> selected) { var sb = new StringBuilder(); foreach (var shape in selected) { SkiaHelper.ToSvgPathData(context, shape, sb); } return(sb.ToString()); }
public PathShape ToPathShape(IToolContext context, string svgPathData) { if (!string.IsNullOrWhiteSpace(svgPathData)) { using (var path = SkiaHelper.ToPath(svgPathData)) { return(SkiaHelper.ToPathShape(context, path, context.DocumentContainer?.StyleLibrary?.CurrentItem, context?.DocumentContainer?.PointTemplate)); } } return(null); }
public override void Draw(SKCanvas canvas, SKPaint paint) { float vx = _p2.X - _p1.X; float vy = _p2.Y - _p1.Y; float dist = (float)Math.Sqrt(vx * vx + vy * vy); vx /= dist; vy /= dist; DrawArrowhead(canvas, paint, _p2, vx, vy, SkiaHelper.ToPixel(_arrowLength)); }
internal ImageEditorViewModel(SKBitmap bitmap, ImageEditorConfig config) { Config = config; cropperCanvas = new ImageCropperCanvasView(bitmap, config.CropAspectRatio); mainCanvas = new TouchManipulationCanvasView(config); mainCanvas.AddBitmapToCanvas(bitmap.Copy(), BitmapType.Main); mainCanvas.TextBitmapClicked += MainCanvas_TextBitmapClicked; mainCanvas.TrashEnabled += MainCanvas_TrashVisebled; ColorCollect = SkiaHelper.GetColors(); CropCollect = CropItem.GetCropItems(config.CanChangeCropAspectRatio); Message = config?.LoadingText; }
internal ImageEditorViewModel(SKBitmap bitmap, ImageEditorConfig config) { Config = config; cropperCanvas = new ImageCropperCanvasView(bitmap, config.CropAspectRatio); mainCanvas = new TouchManipulationCanvasView(config); mainCanvas.AddBitmapToCanvas(bitmap.Copy(), BitmapType.Main); mainCanvas.TextBitmapClicked += MainCanvas_TextBitmapClicked; mainCanvas.TrashEnabled += MainCanvas_TrashVisebled; ColorCollect = SkiaHelper.GetColors(); CropCollect = CropItem.GetCropItems(config.CanChangeCropAspectRatio); Message = config?.LoadingText; MessagingCenter.Subscribe <Xamarin.Forms.Application>(this, "BBDroidBackButton", (sender) => OnBackPressed()); }
public string ToSvgPathData(IToolContext context, ICollection <IBaseShape> selected) { var sb = new StringBuilder(); var shapes = GetShapes(selected); if (shapes != null && shapes.Count > 0) { foreach (var shape in shapes) { SkiaHelper.ToSvgPathData(context, shape, sb); } } return(sb.ToString()); }
private void GetSKPaintFill(IPaint fillPaint, IPaintEffects effects, double scale, out SKPaint brush) { if (fillPaint.IsTreeDirty() || !_paintCache.TryGetValue(fillPaint, out var brushCached)) { fillPaint.Invalidate(); brushCached = SkiaHelper.ToSKPaint(fillPaint, effects, scale, _disposable.Disposables); _paintCache[fillPaint] = brushCached; } else { SkiaHelper.ToSKPaintUpdate(brushCached, fillPaint, effects, scale, _disposable.Disposables); } brush = brushCached; }
private void GetSKPaintFill(ArgbColor color, bool isAntialias, out SKPaint brush) { if (color.IsDirty == true || !_paintCache.TryGetValue(color, out var brushCached)) { color.Invalidate(); brushCached = SkiaHelper.ToSKPaintBrush(color, isAntialias); _paintCache[color] = brushCached; } else { SkiaHelper.ToSKPaintBrushUpdate(brushCached, color); } brush = brushCached; }
public PathShape ToPathShape(IToolContext context, IBaseShape shape) { using (var geometry = ToPath(context, shape)) { if (geometry != null) { var style = context.DocumentContainer?.StyleLibrary?.Get(shape.StyleId); if (style == null) { style = context.DocumentContainer?.StyleLibrary?.CurrentItem; } return(SkiaHelper.ToPathShape(context, geometry, style, context?.DocumentContainer?.PointTemplate)); } } return(null); }
public IActionResult GetAppendMark(string bucket, string name, string query) { string visitUrl = $"/{bucket}/{name}"; var item = _bucketImageService.GetByVisitUrl(visitUrl); if (item == null) { return(NotFile()); } string abPath = Path.Combine(_hostingEnvironment.ContentRootPath, item.IOPath); if (!System.IO.File.Exists(abPath)) { return(NotFile()); } string cut = null, resize = null; Stream stream = null; if (!String.IsNullOrEmpty(query)) { var arr = query.Split(','); foreach (var q in arr) { string temp = q.ToLower(); if (temp.StartsWith("m_")) { cut = temp; } if (temp.StartsWith("w_") || temp.StartsWith("h_")) { resize = temp; } if (temp.Equals("l_logo")) { stream = _markLogoService.GetStream(); } } } using (var img = SkiaHelper.MakeThumb(abPath, cut, resize, item.ExtName, stream)) { return(File(img.ToArray(), $"image/{item.ExtName?.Substring(1)}")); } }
public MainForm() { /* * using (var g = this.CreateGraphics()) * { * SizeF sngScaleFactor = new SizeF(); * if (g.DpiX > 96) * { * sngScaleFactor.Width = g.DpiX / 96; * sngScaleFactor.Height = g.DpiY / 96; * } * * if (this.AutoScaleDimensions == this.CurrentAutoScaleDimensions) * { * this.Scale(sngScaleFactor); * } * } */ SKHelper = new SkiaHelper() { Size = new RawSize { Width = this.Width, Height = this.Height }, PostChain = new SkiaHelper.CanvasDelegate((SKCanvas Canvas) => { using (var paint = new SKPaint()) using (var shader = SKShader.CreateLinearGradient( new SKPoint(SKHelper.Size.Width - 200, 200), new SKPoint(SKHelper.Size.Width, 0), new SKColor[] { SKColors.Orange, SKColors.Orange, SKColors.Gold }, null, SKShaderTileMode.Clamp)) { paint.IsAntialias = true; paint.Shader = shader; SKHelper.Skia_Canvas.DrawPaint(paint); } }) }; InitializeComponent(); DoubleBuffered = true; SKHelper.SwapChain(); }