internal void Initialize() { // Initialize Berry Blast BerryBlastColors = new SKColor[] { new SKColor(255, 255, 255, 255), Strawberry, Grape, new SKColor(0, 0, 0, 255) }; BerryBlastWeights = new float[] { 0f, 0.2490276f, 0.7245682f, 0.9662447f }; BerryBlast = SKShader.CreateLinearGradient(new SKPoint(82.51563f, 6.023438f), new SKPoint(79.83594f, 168.4258f), BerryBlastColors, BerryBlastWeights, SKShaderTileMode.Clamp); // Shadow color for VeryBerryFill var VeryBerryFillShadowColor = new SKColor(51, 51, 51, 255); // Build shadow for VeryBerryFill var VeryBerryFillShadow = SKImageFilter.CreateDropShadow(1.864249f, 13.81737f, 7.484411f, 7.639765f, VeryBerryFillShadowColor, SKDropShadowImageFilterShadowMode.DrawShadowAndForeground, null, null); // Fill color for Very Berry var VeryBerryFillColor = new SKColor(230, 230, 230, 255); // Initialize Very Berry fill paint VeryBerryFillPaint = new SKPaint() { Style = SKPaintStyle.Fill, Color = VeryBerryFillColor, BlendMode = SKBlendMode.SrcOver, IsAntialias = true, Shader = BerryBlast, ImageFilter = VeryBerryFillShadow }; // Initialize Very Berry frame paint VeryBerryFramePaint = new SKPaint() { Style = SKPaintStyle.Stroke, Color = StrawberryCream, BlendMode = SKBlendMode.SrcOver, IsAntialias = true, StrokeWidth = 1.897327f, StrokeMiter = 4f, StrokeJoin = SKStrokeJoin.Mitter, StrokeCap = SKStrokeCap.Butt }; // Fill color for Custom var CustomFillColor = new SKColor(255, 255, 255, 255); // Initialize Custom fill paint CustomFillPaint = new SKPaint() { Style = SKPaintStyle.Fill, Color = CustomFillColor, BlendMode = SKBlendMode.SrcOver, IsAntialias = true, Typeface = SKTypeface.FromFamilyName("System", SKTypefaceStyle.Normal), TextSize = 24f, TextAlign = SKTextAlign.Center, StrikeThruText = false, UnderlineText = false, IsVerticalText = false, TextScaleX = 1f, TextSkewX = 0f }; }
public override void PreProcess(SKCanvas canvas, SKRect bounds, SKPaint paint) { paint.ImageFilter = SKImageFilter.CreateColorFilter(SKColorFilter.CreateColorMatrix(Properties.ColorMatrix.CurrentValue), paint.ImageFilter); }
public static void DrawShadowView( ThumbnailsRenderContext ctx, ISkView view, SKImage?decorationImage = null, SKColor?backgroundColor = null, SKSize?maxSize = null, SKSize?minSize = null, SKFilterQuality resizeQuality = SKFilterQuality.None) { // max width = 128 - 12 - 12 // max height = 128 - 20 - 20 maxSize ??= new SKSize(DefaultMaxWidth, DefaultMaxHeight); minSize ??= new SKSize(0, 0); backgroundColor ??= new SKColor(0xff, 0xff, 0xff); var imageSize = ContainSize(new SKSize(view.Size.Width, view.Size.Height), maxSize.Value); var imageRect = CentralRect(imageSize); var borderSize = new SKSize(Math.Max(imageSize.Width, minSize.Value.Width), Math.Max(imageSize.Height, minSize.Value.Height)); var borderRect = CentralRect(new SKSize(borderSize.Width + 1, borderSize.Height + 1)); using (new SKAutoCanvasRestore(ctx.Canvas)) { ctx.Canvas.Clear(); using (var rectFillPaint = new SKPaint { Style = SKPaintStyle.Fill, Color = backgroundColor.Value, ImageFilter = SKImageFilter.CreateDropShadow(0, 1, 4, 4, new SKColor(136, 136, 136, 128)) }) using (var rectStrokePaint = new SKPaint { Style = SKPaintStyle.Stroke, StrokeWidth = 1, Color = new SKColor(136, 136, 136, 64), BlendMode = SKBlendMode.Src }) { // draw border using SKRoundRect roundRect = new(borderRect, 5); ctx.Canvas.DrawRoundRect(roundRect, rectFillPaint); ctx.Canvas.DrawRoundRect(roundRect, rectStrokePaint); } using (new SKAutoCanvasRestore(ctx.Canvas)) using (var imagePaint = new SKPaint { FilterQuality = resizeQuality }) using (var decorationImagePaint = new SKPaint { FilterQuality = SKFilterQuality.Medium }) { using SKRoundRect roundRect = new(imageRect, 4.5f); using (new SKAutoCanvasRestore(ctx.Canvas)) { ctx.Canvas.ClipRoundRect(roundRect); // draw image view.Draw(ctx.Canvas, imageRect, imagePaint); } if (decorationImage != null) { var decorationRect = SKRect.Create(borderRect.Right - 24.5f, borderRect.Bottom - 22.5f, 36, 36); ctx.Canvas.DrawImage(decorationImage, decorationRect, decorationImagePaint); } } } }
protected override void OnBackgroundPaint(object sender, SKPaintSurfaceEventArgs e) { var canvas = e.Surface.Canvas; var bound = e.Info.Rect; canvas.Clear(); var bgColor = Element.BackgroundColor == Color.Default ? s_defaultColor : SKColor.Parse(Element.BackgroundColor.ToHex()); var borderColor = ShadowElement.BorderColor == Color.Default ? s_defaultColor : SKColor.Parse(ShadowElement.BorderColor.ToHex()); using (var paint = new SKPaint { IsAntialias = true, }) { using (var path = GetRoundRectPath(false)) { // Draw shadow here only if you choose useShadowClip = true. (this means no use of shadow canvas) if (UseShadowClipping && ShadowElement.HasShadow) { using (var path2 = GetRoundRectPath(true)) { paint.Style = SKPaintStyle.StrokeAndFill; var scaledOffsetX = Forms.ConvertToScaledPixel(ShadowElement.ShadowOffsetX); var scaledOffsetY = Forms.ConvertToScaledPixel(ShadowElement.ShadowOffsetY); var scaledBlurRadius = Forms.ConvertToScaledPixel(ShadowElement.ShadowBlurRadius); canvas.Save(); canvas.ClipPath(path2, SKClipOperation.Difference, true); paint.ImageFilter = SKImageFilter.CreateDropShadowOnly( scaledOffsetX, scaledOffsetY, scaledBlurRadius, scaledBlurRadius, ShadowElement.ShadowColor.MultiplyAlpha(ShadowElement.ShadowOpacity).ToSK()); canvas.DrawPath(path2, paint); canvas.Restore(); canvas.Save(); canvas.ClipPath(path2, SKClipOperation.Intersect, true); canvas.DrawPath(path2, paint); canvas.Restore(); } } // Draw background color paint.ImageFilter = null; paint.Style = SKPaintStyle.Fill; paint.Color = bgColor; canvas.DrawPath(path, paint); // Draw Background (Brush) using (var brushPaint = Element.GetBackgroundPaint(bound)) { if (brushPaint != null) { canvas.DrawPath(path, brushPaint); } } // Draw border if (ShadowElement.BorderWidth != 0) { paint.IsAntialias = true; paint.Style = SKPaintStyle.Stroke; paint.StrokeWidth = Forms.ConvertToScaledPixel(ShadowElement.BorderWidth); paint.Color = borderColor; canvas.DrawPath(path, paint); } } } }
public List <BitmapData> DrawSections(ShopV2 shop) { int maxEntriesPerRow = 6; var result = new List <BitmapData>(); maxEntriesPerRow = Math.Clamp(shop.Sections.Max(x => x.Value.Count), 0, maxEntriesPerRow); int th = (int)(ChicRatios.Get1024(200) * EntryHeight); int hf = (int)(ChicRatios.Get1024(150) * EntryHeight); int h = (int)(ChicRatios.Get1024(100) * EntryHeight); int f = (int)(ChicRatios.Get1024(50) * EntryHeight); int width = h + maxEntriesPerRow * (EntryWidth + h); foreach (var section in shop.Sections) { var sectionInfo = shop.SectionInfos.Find(x => x.SectionId == section.Key); int extraHeight = sectionInfo.HasName ? th : 0; int height = extraHeight + (int)Math.Ceiling((decimal)section.Value.Count / maxEntriesPerRow) * (EntryHeight + h); using (SKBitmap bitmap = new SKBitmap(width, height)) { using (SKCanvas c = new SKCanvas(bitmap)) { using (var paint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = SKColor.Parse("#e7accb")//new SKColor(40, 40, 40) }) c.DrawRect(0, 0, width, height, paint); int x = f;//100; int y = extraHeight; int row = 0; int column = 0; for (int i = 0; i < section.Value.Count; i++) { var entry = section.Value[i]; using (var b = DrawEntry(entry) /*LoadFromCache(entry.CacheId)*/) { using (var paint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High }) c.DrawBitmap(b, x, y, paint); } GC.Collect(); if (++column == maxEntriesPerRow) { row++; column = 0; //x = 50;//100; } x = f + (EntryWidth + h) * column; /*+ 50*/ y = extraHeight + (EntryHeight + h /*+ 50*/) * row; } using (var paint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = SKColors.White, TextSize = h, Typeface = ChicTypefaces.BurbankBigRegularBlack, TextAlign = SKTextAlign.Left, ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black) }) if (sectionInfo.HasName) { c.DrawText(sectionInfo.DisplayName, h, hf, paint); } } result.Add(SaveToCache(bitmap, section.Key)); } } return(result); }
/*public SKBitmap B(List<Section> sections, Dictionary<Section, SKBitmap> bitmaps) * { * List<int> featured = new List<int>(); * List<int> others = new List<int>(); * * int featuredCount = 0; * * foreach (var section in sections) * { * if (section.SectionId.Contains("Featured")) * { * featured.Add(bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value.Width); * featuredCount++; * continue; * } * else //if (section.SectionId.Contains("Daily")) * { * others.Add(bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value.Width); * continue; * } * }; * * int columnCount = featured.Count > 0 ? 2 : 1; * * int width = columnCount * featured.Max(); * int featuredHeight = 0; * int othersHeight = 0; * * bitmaps.ToList().ForEach(pair => * { * if (pair.Key.SectionId.Contains("Featured")) featuredHeight += pair.Value.Height; * else othersHeight += pair.Value.Height; * }); * * int height = Math.Max(featuredHeight, othersHeight) + 250; * * int ratio = 0; * * int fullHeight = 0; * int fullWidth = 0; * * if (height >= width) ratio = height / 9; * else ratio = width / 16; * * fullHeight = ratio * 9; * fullWidth = ratio * 16; * * var full = new SKBitmap(fullWidth, fullHeight); * * using (var merge = new SKBitmap(width, height)) * { * using (var c = new SKCanvas(merge)) * { * int y = 0; * int x = 0; * int i = 0; * * sections.ToList().ForEach(section => * { * var bitmap = bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value; * * c.DrawBitmap(bitmap, x, y); * y += bitmap.Height; * i++; * * if (i == featuredCount) * { * y = 0; * x += width / columnCount; * } * }); * } * * using (var c = new SKCanvas(full)) * { * c.DrawRect(0, 0, full.Width, full.Height, * new SKPaint * { * IsAntialias = true, * FilterQuality = SKFilterQuality.High, * Color = new SKColor(40, 40, 40) * }); * * c.DrawBitmap(merge, (full.Width - merge.Width) / 2, 0, * new SKPaint * { * IsAntialias = true, * FilterQuality = SKFilterQuality.High * }); * * var textPaint = new SKPaint * { * IsAntialias = true, * FilterQuality = SKFilterQuality.High, * TextSize = 200, * Color = SKColors.White, * Typeface = ChicTypefaces.BurbankBigRegularBlack, * ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black) * }; * * var sacText = "Code 'Chic' #Ad"; * * c.DrawText(sacText, (full.Width - textPaint.MeasureText(sacText)) / 2, * full.Height - 50, textPaint); * } * * return full; * } * }*/ public Dictionary <Section, BitmapData> GenerateSections(Dictionary <StorefrontEntry, BitmapData> entries) { int maxEntriesPerRow = 6; Dictionary <Section, BitmapData> sectionsBitmaps = new Dictionary <Section, BitmapData>(); var content = FortniteContent.Get(); List <Section> sections = new List <Section>(); entries.Keys.ToList().ForEach(key => { if (!sections.Contains(x => x.SectionId == key.SectionId)) { if (content.ShopSections.Contains(key.SectionId)) { sections.Add(content.ShopSections.Get(key.SectionId)); } else { sections.Add(new Section { SectionId = key.SectionId, DisplayName = "", LandingPriority = 49 }); } } }); List <int> entriesCount = new List <int>(); sections.ForEach(section => { int count = 0; entries.ToList().ForEach(entry => { if (entry.Key.SectionId == section.SectionId) { count++; } }); entriesCount.Add(count); }); maxEntriesPerRow = Math.Clamp(entriesCount.Max(), 0, maxEntriesPerRow); int th = (int)(ChicRatios.Get1024(200) * EntryHeight); int hf = (int)(ChicRatios.Get1024(150) * EntryHeight); int h = (int)(ChicRatios.Get1024(100) * EntryHeight); int f = (int)(ChicRatios.Get1024(50) * EntryHeight); foreach (var section in sections) { Dictionary <StorefrontEntry, BitmapData> se = new Dictionary <StorefrontEntry, BitmapData>(); entries.ToList().ForEach(entry => { if (entry.Key.SectionId == section.SectionId) { se.Add(entry); } }); Dictionary <StorefrontEntry, BitmapData> sectionEntries = new Dictionary <StorefrontEntry, BitmapData>(); sectionEntries.Add(se.ToList().Sort(EntryComparer.Comparer, 0)); int extraHeight = section.HasName ? th : 0; SKBitmap bitmap = new SKBitmap(h /*150*/ + maxEntriesPerRow * (EntryWidth + h /*+ 50*/), extraHeight + (int)Math.Ceiling((decimal)sectionEntries.Count / maxEntriesPerRow) * (EntryHeight + h /*+ 50*/)); using (SKCanvas c = new SKCanvas(bitmap)) { using (var paint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = SKColor.Parse("#e7accb")//new SKColor(40, 40, 40) }) c.DrawRect(0, 0, bitmap.Width, bitmap.Height, paint); int x = f;//100; int y = extraHeight; int row = 0; int column = 0; for (int i = 0; i < sectionEntries.Count; i++) { var entry = sectionEntries.ToList()[i]; using (var b = LoadFromCache(entry.Value)) { using (var paint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High }) c.DrawBitmap(b, x, y, paint); } GC.Collect(); if (++column == maxEntriesPerRow) { row++; column = 0; //x = 50;//100; } x = f + (EntryWidth + h) * column; /*+ 50*/ y = extraHeight + (EntryHeight + h /*+ 50*/) * row; } using (var paint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = SKColors.White, TextSize = h, Typeface = ChicTypefaces.BurbankBigRegularBlack, TextAlign = SKTextAlign.Left, ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black) }) if (section.HasName) { c.DrawText(section.DisplayName, h, hf, paint); } } sectionEntries = null; sectionsBitmaps.Add(section, SaveToCache(bitmap, "section_" + section.SectionId)); } content = null; sections = null; entries = null; GC.Collect(); return(sectionsBitmaps); }
public override void PostProcess(SKCanvas canvas, SKImageInfo canvasInfo, SKPath renderBounds, SKPaint paint) { paint.ImageFilter = SKImageFilter.CreateColorFilter(SKColorFilter.CreateColorMatrix(Properties.ColorMatrix.CurrentValue), paint.ImageFilter); }
private void DrawIndicators(SKCanvas canvas, float radius) { var threashHold = radius.Scale(0.05f); var previousDirection = Direction; canvas.Save(); var baseRadius = radius.Scale(0.80f); var size = radius.Scale(0.08f); _indicatorPath = SKPath.ParseSvgPathData($"M-{size} 0L0 {size}L{size} 0L-{size} 0Z"); _indicatorPaint.ImageFilter = SKImageFilter.CreateDropShadow(0, 1, baseRadius.Scale(0.005f), baseRadius.Scale(0.005f), SKColors.Gray); // Top canvas.Save(); var isForward = _position.Y > threashHold; _indicatorPaint.Color = isForward ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled); Direction = isForward ? Direction & (~JoystickDirection.None) | JoystickDirection.Forward : Direction & (~JoystickDirection.Forward); canvas.Translate(0, baseRadius); canvas.RotateDegrees(0); canvas.DrawPath(_indicatorPath, _indicatorPaint); canvas.Restore(); // Rigth canvas.Save(); var isRigth = _position.X > threashHold; _indicatorPaint.Color = isRigth ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled); Direction = isRigth ? Direction & (~JoystickDirection.None) | JoystickDirection.Right : Direction & (~JoystickDirection.Right); canvas.Translate(baseRadius, 0); canvas.RotateDegrees(-90); canvas.DrawPath(_indicatorPath, _indicatorPaint); canvas.Restore(); // Backward canvas.Save(); var isBackward = _position.Y < -threashHold; _indicatorPaint.Color = isBackward ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled); Direction = isBackward ? Direction & (~JoystickDirection.None) | JoystickDirection.Backward : Direction & (~JoystickDirection.Backward); canvas.Translate(0, -baseRadius); canvas.RotateDegrees(180); canvas.DrawPath(_indicatorPath, _indicatorPaint); canvas.Restore(); // Left canvas.Save(); var isLeft = _position.X < -threashHold; _indicatorPaint.Color = isLeft ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled); Direction = isLeft ? Direction & (~JoystickDirection.None) | JoystickDirection.Left : Direction & (~JoystickDirection.Left); canvas.Translate(-baseRadius, 0); canvas.RotateDegrees(90); canvas.DrawPath(_indicatorPath, _indicatorPaint); canvas.Restore(); if (!isForward && !isBackward && !isRigth && !isLeft) { Direction = JoystickDirection.None; } if (Direction != previousDirection) { DigitalMoved?.Invoke(this, new EventArgs()); Execute(Command); } canvas.Restore(); }
public static void DrawBackground(SKCanvas c, BaseIcon icon) { /*var pathTop = new SKPath { FillType = SKPathFillType.EvenOdd }; * pathTop.MoveTo(icon.Margin, icon.Margin); * pathTop.LineTo(icon.Margin + icon.Width, icon.Margin); * pathTop.LineTo(icon.Margin + icon.Width, icon.Margin + 20); * pathTop.LineTo(icon.Margin, icon.Margin + 30); * pathTop.Close(); * c.DrawPath(pathTop, new SKPaint * { * IsAntialias = true, * FilterQuality = SKFilterQuality.High, * Color = new SKColor(30, 30, 30), //new SKColor(206, 155, 181), * ImageFilter = SKImageFilter.CreateDropShadow(0, 3, 5, 5, SKColors.Black, null, new SKImageFilter.CropRect(SKRect.Create(icon.Margin, icon.Margin, icon.Width - icon.Margin, icon.Height - icon.Margin))) * });*/ using (var rarityPath = new SKPath { FillType = SKPathFillType.EvenOdd }) { rarityPath.MoveTo(0, icon.Height); rarityPath.LineTo(0, icon.Height - icon.Height * ChicRatios.Get(75)); rarityPath.LineTo(icon.Width, icon.Height - icon.Height * ChicRatios.Get(85)); rarityPath.LineTo(icon.Width, icon.Height); rarityPath.Close(); SKColor rarityColor = icon.RarityColors[0]; using (var filter = SKImageFilter.CreateDropShadow(0, -3, icon.Height * ChicRatios.Get(5), icon.Height * ChicRatios.Get(5), SKColors.Black)) using (var paint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = rarityColor, ImageFilter = filter }) c.DrawPath(rarityPath, paint); } using (var pathBottom = new SKPath { FillType = SKPathFillType.EvenOdd }) { pathBottom.MoveTo(0, icon.Height); pathBottom.LineTo(0, icon.Height - icon.Height * ChicRatios.Get(65)); pathBottom.LineTo(icon.Width, icon.Height - icon.Height * ChicRatios.Get(75)); pathBottom.LineTo(icon.Width, icon.Height); pathBottom.Close(); c.DrawPath(pathBottom, new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = new SKColor(30, 30, 30) }); } using (var pathBottomBottom = new SKPath { FillType = SKPathFillType.EvenOdd }) { pathBottomBottom.MoveTo(0, icon.Height); pathBottomBottom.LineTo(0, icon.Height - icon.Height * ChicRatios.Get(22)); pathBottomBottom.LineTo(icon.Width, icon.Height - icon.Height * ChicRatios.Get(32)); pathBottomBottom.LineTo(icon.Width, icon.Height); pathBottomBottom.Close(); c.DrawPath(pathBottomBottom, new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = new SKColor(20, 20, 20) }); } }
private void InitializePaints() { // Left thumb _leftThumbDraw.Paint = new SKPaint { Color = SKColors.White, IsAntialias = true }; _leftThumbDraw.ValueTextDraw.Paint = new SKPaint { Color = SKColors.Black, IsAntialias = true, }; _leftThumbDraw.IconTextDraw.Paint = new SKPaint { Color = SKColors.White, IsAntialias = true, Typeface = SkiaSharpHelper.LoadTtfFont(Fonts.Icons) }; // Right thumb _rightThumbDraw.Paint = new SKPaint { Color = SKColors.White, IsAntialias = true }; _rightThumbDraw.ValueTextDraw.Paint = new SKPaint { Color = SKColors.Black, IsAntialias = true }; _rightThumbDraw.IconTextDraw.Paint = new SKPaint { Color = SKColors.White, IsAntialias = true, Typeface = SkiaSharpHelper.LoadTtfFont(Fonts.Icons) }; // Thumbs shadow _leftThumbDraw.Paint.ImageFilter = _rightThumbDraw.Paint.ImageFilter = SKImageFilter.CreateDropShadow( 0, 0, 5, 5, SKColor.Parse("#EFEFEF"), SKDropShadowImageFilterShadowMode.DrawShadowAndForeground ); // Value segment _valueSegmentPaint = new SKPaint { Color = SKColors.Black, IsAntialias = true, }; // Remaining value segment _remainingValueSegmentPaint = new SKPaint { Color = SKColors.Gray, IsAntialias = true, }; }
void Process(SKImage image, List <RestrictedFaceArea> hiddenRects, int jpegQuality) { this.jpegQuality = jpegQuality; bytes = null; using (SKBitmap bitmap = SKBitmap.FromImage(image)) { for (int f = 0; f < hiddenRects.Count; f++) { SKBitmap faceBlurBitmap = null; SKBitmap ovalMask = null; // кварат зоны наложения маски SKRect target = new SKRect(hiddenRects[f].x, hiddenRects[f].y, hiddenRects[f].x + hiddenRects[f].w, hiddenRects[f].y + hiddenRects[f].h); float rotateAngle = hiddenRects[f].a; float blurSideSize = (float)(Math.Max(target.Width, target.Height) * 1.5); float sigma = blurSideSize / 25; // квадрат с запасом для равномерного размыливания изображения SKRect targetPlus = new SKRect(target.MidX - blurSideSize / 2, target.MidY - blurSideSize / 2, target.MidX + blurSideSize / 2, target.MidY + blurSideSize / 2); using (SKSurface surfaceBlur = SKSurface.Create(new SKImageInfo((int)targetPlus.Width, (int)targetPlus.Height))) using (SKCanvas canvasBlur = surfaceBlur.Canvas) { using (SKImageFilter imageFilterBlur = SKImageFilter.CreateBlur(sigma, sigma)) using (SKPaint paintBlur = new SKPaint { ImageFilter = imageFilterBlur, IsAntialias = false, }) { canvasBlur.DrawImage(image, targetPlus, new SKRect(0, 0, targetPlus.Width, targetPlus.Height), paintBlur); } using (SKImage imageBlur = surfaceBlur.Snapshot()) { faceBlurBitmap = SKBitmap.FromImage(imageBlur); //if (trace) SaveJpegImage(imageBlur, "FaceBlur.jpg"); } } // формируем эллипс-маску с учётом требуемого наклона float width = Math.Max(target.Width, target.Height); using (SKSurface surfaceOval = SKSurface.Create(new SKImageInfo((int)width, (int)width))) using (SKCanvas canvasOval = surfaceOval.Canvas) { using (SKRoundRect roundRectOval = new SKRoundRect(new SKRect((width - target.Width) / 2, (width - target.Height) / 2, (width - target.Width) / 2 + target.Width, (width - target.Height) / 2 + target.Height), (float)(target.Width / 2.2), (float)(target.Height / 2.2))) using (SKPaint paintOval = new SKPaint { IsAntialias = true, Style = SKPaintStyle.Fill, Color = SKColors.White }) { canvasOval.Save(); canvasOval.RotateDegrees(rotateAngle, (float)(width / 2), (float)(width / 2)); canvasOval.DrawRoundRect(roundRectOval, paintOval); // на прежнем канвасе canvasOval.Restore(); } using (SKImage imageOval = surfaceOval.Snapshot()) { ovalMask = SKBitmap.FromImage(imageOval); //if (trace) SaveJpegImage(imageOval, "OvalMask.jpg"); } } bytes = ovalMask.Bytes; int imageX = 0, imageY = 0, blurX = 0, blurY = 0; int deltaBlurXImage = (int)(target.MidX - (float)ovalMask.Width / 2); int deltaBlurYImage = (int)(target.MidY - (float)ovalMask.Height / 2); int deltaMaskBlurX = (int)Math.Round((float)faceBlurBitmap.Width / 2 - (float)ovalMask.Width / 2); int deltaMaskBlurY = (int)Math.Round((float)faceBlurBitmap.Height / 2 - (float)ovalMask.Height / 2); int col = 0; int row = 0; try { for (int i = 3; i < bytes.Length; i = i + 4) { if (bytes[i] > 0) { imageX = col + deltaBlurXImage; imageY = row + deltaBlurYImage; blurX = col + deltaMaskBlurX; blurY = row + deltaMaskBlurY; if (imageX < bitmap.Width && imageY < bitmap.Height && imageX < bitmap.Width && imageY < bitmap.Height) { bitmap.SetPixel(imageX, imageY, faceBlurBitmap.GetPixel(blurX, blurY)); } } col++; if (col >= ovalMask.RowBytes >> 2) { col = 0; row++; } } } catch (Exception exc) { } using (SKImage sKImage = SKImage.FromBitmap(bitmap)) using (SKData tmpData = sKImage.Encode(SKEncodedImageFormat.Jpeg, jpegQuality)) { bytes = tmpData.ToArray(); if (trace) { using (FileStream tmpStream = new FileStream("Blur result.jpg", FileMode.Create)) tmpData.SaveTo(tmpStream); } } faceBlurBitmap = null; ovalMask = null; } } dtStop = DateTime.Now; }
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; //determine find smallet axis length MinorAxisLength = info.Width > info.Height ? info.Height : info.Width; arcWidth = MinorAxisLength / 30; arcPadding = MinorAxisLength / 15; KnobRadius = MinorAxisLength / 30; float radius = (MinorAxisLength / 2); //update center Center = new SKPoint(info.Width / 2, info.Height / 2); SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); // canvas.Scale((float)(canvasView.CanvasSize.Width / canvasView.Width)); // SKPaint BackgroundPaint = new SKPaint // { // Style = SKPaintStyle.Fill, // Shader = SKShader.CreateColor(BackgroundColor.ToSKColor()), // }; // // canvas.DrawRect(new SKRect(Center.X-(MinorAxisLength/2), Center.Y - (MinorAxisLength / 2), Center.X + (MinorAxisLength / 2), Center.Y + (MinorAxisLength / 2)), BackgroundPaint); SKPaint arcPaint = new SKPaint { Style = SKPaintStyle.Stroke, Shader = SKShader.CreateColor(ArcColor.ToSKColor()), StrokeCap = SKStrokeCap.Round, StrokeWidth = arcWidth + 1, IsAntialias = true, }; SKPaint arcBackgroundPaint = new SKPaint { Style = SKPaintStyle.Stroke, Shader = SKShader.CreateColor(ArcBackgroundColor.ToSKColor()), StrokeCap = SKStrokeCap.Round, StrokeWidth = arcWidth, IsAntialias = true, // ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 2, 2, Color.Black.ToSKColor(), SKDropShadowImageFilterShadowMode.DrawShadowAndForeground) }; SKPaint KnobPaint = new SKPaint { Style = SKPaintStyle.Fill, Shader = SKShader.CreateColor(KnobColor.ToSKColor()), IsAntialias = true, ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 3, 3, ArcColor.MultiplyAlpha(.5).ToSKColor(), SKDropShadowImageFilterShadowMode.DrawShadowAndForeground) }; SKPaint TextPaint = new SKPaint { Style = SKPaintStyle.Fill, Shader = SKShader.CreateColor(Color.Black.ToSKColor()), IsAntialias = true, TextSize = 40f, IsStroke = false, TextAlign = SKTextAlign.Center, }; //create the rectangle that contains the arc //SKRect rect = new SKRect(arcPadding, arcPadding, MinorAxisLength - arcPadding, MinorAxisLength - arcPadding); SKRect rect = new SKRect(arcPadding + Center.X - (MinorAxisLength / 2), arcPadding + Center.Y - (MinorAxisLength / 2), Center.X + (MinorAxisLength / 2) - arcPadding, Center.Y + (MinorAxisLength / 2) - arcPadding); //var point = LastTouchedPoint; //calcualte the angle of the last touched point realtive to the center of the arc var sweepAngle = getsweepangle(); float realAngle = startAngle + sweepAngle; //Debug.WriteLine($"realAngle:{realAngle % 360}"); float arcRadius = (MinorAxisLength / 2) - arcPadding;; //get x and y compoents o the point on ther arc float x = arcRadius * (float)Math.Cos(DegreeToRadian(realAngle)); float y = arcRadius * (float)Math.Sin(DegreeToRadian(realAngle)); //move the points realitve to the center of the chart // SKRect rect = new SKRect(arcPadding + Center.X - (MinorAxisLength / 2), arcPadding + Center.Y - (MinorAxisLength / 2), Center.X + (MinorAxisLength / 2) - arcPadding, Center.Y + (MinorAxisLength / 2) - arcPadding); float realtiveX = x + Center.X; float realtiveY = y + Center.Y; using (SKPath path = new SKPath()) { //draw background arc path.AddArc(rect, startAngle, 300); canvas.DrawPath(path, arcBackgroundPaint); } using (SKPath path = new SKPath()) { //draw arc showing value path.AddArc(rect, startAngle, sweepAngle); canvas.DrawPath(path, arcPaint); } //draw current postion var TextBounds = new SKRect(); var ValueString = String.Format("{0:F" + Precision + "}", Value); TextPaint.MeasureText(ValueString, ref TextBounds); canvas.DrawOval(new SKRect(realtiveX - KnobRadius, realtiveY - KnobRadius, realtiveX + KnobRadius, realtiveY + KnobRadius), KnobPaint); if (ShowValue) { canvas.DrawText(ValueString, Center.X, Center.Y + (TextBounds.Height / 2), TextPaint); } }
public void Render(IDrawingContextImpl context) { var leaseFeature = context.GetFeature <ISkiaSharpApiLeaseFeature>(); if (leaseFeature == null) { using (var c = new DrawingContext(context, false)) { c.DrawText(_noSkia, new Point()); } } else { using var lease = leaseFeature.Lease(); var canvas = lease.SkCanvas; canvas.Save(); // create the first shader var colors = new SKColor[] { new SKColor(0, 255, 255), new SKColor(255, 0, 255), new SKColor(255, 255, 0), new SKColor(0, 255, 255) }; var sx = Animate(100, 2, 10); var sy = Animate(1000, 5, 15); var lightPosition = new SKPoint( (float)(Bounds.Width / 2 + Math.Cos(St.Elapsed.TotalSeconds) * Bounds.Width / 4), (float)(Bounds.Height / 2 + Math.Sin(St.Elapsed.TotalSeconds) * Bounds.Height / 4)); using (var sweep = SKShader.CreateSweepGradient(new SKPoint((int)Bounds.Width / 2, (int)Bounds.Height / 2), colors, null)) using (var turbulence = SKShader.CreatePerlinNoiseFractalNoise(0.05f, 0.05f, 4, 0)) using (var shader = SKShader.CreateCompose(sweep, turbulence, SKBlendMode.SrcATop)) using (var blur = SKImageFilter.CreateBlur(Animate(100, 2, 10), Animate(100, 5, 15))) using (var paint = new SKPaint { Shader = shader, ImageFilter = blur }) canvas.DrawPaint(paint); using (var pseudoLight = SKShader.CreateRadialGradient( lightPosition, (float)(Bounds.Width / 3), new [] { new SKColor(255, 200, 200, 100), SKColors.Transparent, new SKColor(40, 40, 40, 220), new SKColor(20, 20, 20, (byte)Animate(100, 200, 220)) }, new float[] { 0.3f, 0.3f, 0.8f, 1 }, SKShaderTileMode.Clamp)) using (var paint = new SKPaint { Shader = pseudoLight }) canvas.DrawPaint(paint); canvas.Restore(); } }
public static void DrawHeaderPaint(SKCanvas c, BaseBundle icon) { c.DrawRect(new SKRect(0, 0, icon.Width, icon.HeaderHeight), new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = icon.DisplayStyle.PrimaryColor }); if (icon.DisplayStyle.CustomBackground != null && icon.DisplayStyle.CustomBackground.Height != icon.DisplayStyle.CustomBackground.Width) { icon.IsDisplayNameShifted = false; var bgPaint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, BlendMode = SKBlendMode.Screen }; if (Properties.Settings.Default.UseChallengeBanner) { bgPaint.Color = SKColors.Transparent.WithAlpha((byte)Properties.Settings.Default.ChallengeBannerOpacity); } c.DrawBitmap(icon.DisplayStyle.CustomBackground, new SKRect(0, 0, 1024, 256), bgPaint); } else if (icon.DisplayStyle.DisplayImage != null) { icon.IsDisplayNameShifted = true; if (icon.DisplayStyle.CustomBackground != null && icon.DisplayStyle.CustomBackground.Height == icon.DisplayStyle.CustomBackground.Width) { c.DrawBitmap(icon.DisplayStyle.CustomBackground, new SKRect(0, 0, icon.HeaderHeight, icon.HeaderHeight), new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, BlendMode = SKBlendMode.Screen, ImageFilter = SKImageFilter.CreateDropShadow(2.5F, 0, 20, 0, icon.DisplayStyle.SecondaryColor.WithAlpha(25)) }); } c.DrawBitmap(icon.DisplayStyle.DisplayImage, new SKRect(0, 0, icon.HeaderHeight, icon.HeaderHeight), new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, ImageFilter = SKImageFilter.CreateDropShadow(-2.5F, 0, 20, 0, icon.DisplayStyle.SecondaryColor.WithAlpha(50)) }); } SKPath pathTop = new SKPath { FillType = SKPathFillType.EvenOdd }; pathTop.MoveTo(0, icon.HeaderHeight); pathTop.LineTo(icon.Width, icon.HeaderHeight); pathTop.LineTo(icon.Width, icon.HeaderHeight - 19); pathTop.LineTo(icon.Width / 2 + 7, icon.HeaderHeight - 23); pathTop.LineTo(icon.Width / 2 + 13, icon.HeaderHeight - 7); pathTop.LineTo(0, icon.HeaderHeight - 19); pathTop.Close(); c.DrawPath(pathTop, new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = icon.DisplayStyle.SecondaryColor, ImageFilter = SKImageFilter.CreateDropShadow(-5, -5, 0, 0, icon.DisplayStyle.AccentColor.WithAlpha(75)) }); c.DrawRect(new SKRect(0, icon.HeaderHeight, icon.Width, icon.HeaderHeight + icon.AdditionalSize), new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = icon.DisplayStyle.PrimaryColor.WithAlpha(200) // default background is black, so i'm kinda lowering the brightness here and that's what i want }); }
//C++ TO C# CONVERTER TODO TASK: The implementation of the following method could not be found: // BackdropFilterLayer(); //C++ TO C# CONVERTER TODO TASK: The implementation of the following method could not be found: // public void Dispose(); public void set_filter(SKImageFilter filter) { filter_ = filter; }
public static SKBitmap GenerateIcon(BaseIcon icon) { int h = (int)(ChicRatios.Get1024(100) * icon.Height); var bitmap = new SKBitmap(icon.Width + h, icon.Height + h); using (var bmp = new SKBitmap(icon.Width, icon.Height, SKColorType.Rgba8888, SKAlphaType.Premul)) { using (var c = new SKCanvas(bmp)) { //#CE9BB5 //Background ChicRarity.DrawRarity(c, icon); //Draw item icon ChicImage.DrawPreviewImage(c, icon); //Draw Text Background ChicText.DrawBackground(c, icon); //Display Name ChicText.DrawDisplayName(c, icon); ChicText.DrawBundleInfo(c, icon); if (!icon.ShortDescription.Equals(icon.DisplayName)) { //Draw Item Type ChicText.DrawToBottom(c, icon, SKTextAlign.Left, icon.ShortDescription.ToUpper()); } ChicText.DrawVbuck(c, icon); { string priceText = icon.Price > 0 ? icon.Price.ToString("N0", CultureInfo.GetCultureInfo("en-US")) : "FREE"; ChicText.DrawToBottom(c, icon, SKTextAlign.Right, priceText); } //Watermark //ChicWatermark.DrawWatermark(c, icon.Size, shadow: true); // watermark should only be applied on icons with width = 512 //ChicWatermark.DrawWatermark(c, icon, 18, "@ChicIsCoolio", 2); //ChicWatermark.DrawChicFace(c, SKColors.White, icon.Size - 120); //Shows the image //ImageBoxVm.imageBoxViewModel.Set(ret, assetName); } using (var c = new SKCanvas(bitmap)) { int f = (int)(ChicRatios.Get1024(50) * icon.Height); int t = (int)(ChicRatios.Get1024(20) * icon.Height); using (var paint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, ImageFilter = SKImageFilter.CreateDropShadow(0, 0, t, t, SKColors.Black) }) c.DrawBitmap(bmp, f, f, paint); if (icon.HasBanner) { ChicBanner.DrawBanner(c, icon); } } } return(bitmap); }
public void PaintText(object sender, SKSurface surface, SKImageInfo info) { bool textForLobby = false; bool textForFriend = false; var Bind = sender as Xamarin.Forms.View; string text = (string)Bind.BindingContext; text = text.ToUpper(); if (text[text.Length - 1] == ':') { text = text.Remove(text.Length - 1); textForLobby = true; } if (text[text.Length - 1] == ';') { text = text.Remove(text.Length - 1); textForFriend = true; } using (SKCanvas canvas = surface.Canvas) { canvas.Clear(); float dx = -10; float dy = 10; float sigmaX = 3; float sigmaY = 3; // Create an SKPaint object to display the text using (SKPaint textPaint = new SKPaint { Style = SKPaintStyle.Stroke, StrokeWidth = 4, IsAntialias = true, Color = SKColor.Parse("#000") }) { using (SKPaint textPaintFill = new SKPaint { Style = SKPaintStyle.Fill, IsAntialias = true, Color = SKColor.Parse("#E7D014") }) { textPaintFill.Typeface = GetTypeface("AmericanCaptain.ttf"); textPaint.Typeface = textPaintFill.Typeface; // Adjust TextSize property so text is 95% of screen width float textWidth = textPaint.MeasureText(text); if (textForLobby && text.Length < 10) { textWidth = 70; } if (textForFriend && text.Length < 10) { textWidth = 50; } textPaint.TextSize = 0.80f * info.Width * textPaint.TextSize / textWidth; textPaintFill.TextSize = 0.80f * info.Width * textPaintFill.TextSize / textWidth; // Find the text bounds SKRect textBounds = new SKRect(); textPaint.MeasureText(text, ref textBounds); textPaintFill.ImageFilter = SKImageFilter.CreateDropShadow( dx, dy, sigmaX, sigmaY, SKColor.Parse("#55000000")); textPaintFill.MeasureText(text, ref textBounds); // Calculate offsets to center the text on the screen float xText = info.Width / 2 - textBounds.MidX; float yText = info.Height / 2 - textBounds.MidY; // And draw the text canvas.DrawText(text, xText, yText, textPaint); canvas.DrawText(text, xText, yText, textPaintFill); } } } }
/// <inheritdoc/> public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, ImageOrientation?orientation, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat) { if (string.IsNullOrWhiteSpace(inputPath)) { throw new ArgumentNullException(nameof(inputPath)); } if (string.IsNullOrWhiteSpace(inputPath)) { throw new ArgumentNullException(nameof(outputPath)); } var skiaOutputFormat = GetImageFormat(selectedOutputFormat); var hasBackgroundColor = !string.IsNullOrWhiteSpace(options.BackgroundColor); var hasForegroundColor = !string.IsNullOrWhiteSpace(options.ForegroundLayer); var blur = options.Blur ?? 0; var hasIndicator = options.AddPlayedIndicator || options.UnplayedCount.HasValue || !options.PercentPlayed.Equals(0); using (var bitmap = GetBitmap(inputPath, options.CropWhiteSpace, autoOrient, orientation)) { if (bitmap == null) { throw new ArgumentOutOfRangeException($"Skia unable to read image {inputPath}"); } var originalImageSize = new ImageDimensions(bitmap.Width, bitmap.Height); if (!options.CropWhiteSpace && options.HasDefaultOptions(inputPath, originalImageSize) && !autoOrient) { // Just spit out the original file if all the options are default return(inputPath); } var newImageSize = ImageHelper.GetNewImageSize(options, originalImageSize); var width = newImageSize.Width; var height = newImageSize.Height; using (var resizedBitmap = new SKBitmap(width, height, bitmap.ColorType, bitmap.AlphaType)) { // scale image bitmap.ScalePixels(resizedBitmap, SKFilterQuality.High); // If all we're doing is resizing then we can stop now if (!hasBackgroundColor && !hasForegroundColor && blur == 0 && !hasIndicator) { Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); using (var outputStream = new SKFileWStream(outputPath)) using (var pixmap = new SKPixmap(new SKImageInfo(width, height), resizedBitmap.GetPixels())) { pixmap.Encode(outputStream, skiaOutputFormat, quality); return(outputPath); } } // create bitmap to use for canvas drawing used to draw into bitmap using (var saveBitmap = new SKBitmap(width, height)) // , bitmap.ColorType, bitmap.AlphaType)) using (var canvas = new SKCanvas(saveBitmap)) { // set background color if present if (hasBackgroundColor) { canvas.Clear(SKColor.Parse(options.BackgroundColor)); } // Add blur if option is present if (blur > 0) { // create image from resized bitmap to apply blur using (var paint = new SKPaint()) using (var filter = SKImageFilter.CreateBlur(blur, blur)) { paint.ImageFilter = filter; canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint); } } else { // draw resized bitmap onto canvas canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height)); } // If foreground layer present then draw if (hasForegroundColor) { if (!double.TryParse(options.ForegroundLayer, out double opacity)) { opacity = .4; } canvas.DrawColor(new SKColor(0, 0, 0, (byte)((1 - opacity) * 0xFF)), SKBlendMode.SrcOver); } if (hasIndicator) { DrawIndicator(canvas, width, height, options); } Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); using (var outputStream = new SKFileWStream(outputPath)) { using (var pixmap = new SKPixmap(new SKImageInfo(width, height), saveBitmap.GetPixels())) { pixmap.Encode(outputStream, skiaOutputFormat, quality); } } } } } return(outputPath); }
/// <summary> /// Creates the filter. /// </summary> /// <param name="drawingContext">The drawing context.</param> /// <returns></returns> public override void CreateFilter(SkiaSharpDrawingContext drawingContext) { SKImageFilter = SKImageFilter.CreateBlur(_sigmaX, _sigmaY, _filter, _cropRect); }
public SKBitmap A(List <Section> sections, Dictionary <Section, BitmapData> bitmaps) { int width = 0; int height = 250; bitmaps.Values.ToList().ForEach(b => { if (b.Width > width) { width = b.Width; } height += b.Height; }); var merge = new SKBitmap(width, height); using (var c = new SKCanvas(merge)) { int y = 0; using (var paint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = SKColor.Parse("#e7accb")//new SKColor(40, 40, 40) }) c.DrawRect(0, 0, merge.Width, merge.Height, paint); sections.ToList().ForEach(section => { var bitmapData = bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value; using (var bitmap = LoadFromCache(bitmapData)) { c.DrawBitmap(bitmap, 0, y); y += bitmap.Height; } GC.Collect(); ; }); using (var textPaint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, TextSize = (int)(ChicRatios.Get1024(150) * EntryHeight), Color = SKColors.White, Typeface = ChicTypefaces.BurbankBigRegularBlack, ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black) }) { var sacText = "Code 'Chic'\n#Ad"; int textWidth = (int)textPaint.MeasureText(sacText); int left = (merge.Width - textWidth) / 2; int top = merge.Height - (int)(ChicRatios.Get1024(150) * EntryHeight * 2); int right = left + textWidth; int bottom = merge.Height - (int)(ChicRatios.Get1024(150) * EntryHeight); ChicText.DrawMultilineText(c, sacText, new SKRect(left, top, right, bottom), textPaint); sacText = ""; } using (var shadow = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black) }) { using (var heart = SKBitmap.Decode($"{Root}Resources/heartTopLeft.png")) { c.DrawBitmap(heart, 0, 0, shadow); } using (var hearts = SKBitmap.Decode($"{Root}Resources/heartsBottomRight.png")) { c.DrawBitmap(hearts, merge.Width - hearts.Width, merge.Height - hearts.Height, shadow); } } } sections = null; bitmaps = null; return(merge); }
void OnPaintCanvas(object sender, SKPaintSurfaceEventArgs e) { var canvas = e.Surface.Canvas; canvas.Clear(); var left = formsGeometry.Left - canvasView.Geometry.Left; var top = formsGeometry.Top - canvasView.Geometry.Top; var path = new SKPath(); var rect = new SKRect(left, top, left + formsGeometry.Width, top + formsGeometry.Height); var borderTop = new SKPath(); var borderRight = new SKPath(); var borderBottom = new SKPath(); var borderLeft = new SKPath(); var topLeft = new SKRect(rect.Left, rect.Top, rect.Left + (float)Self.Border.TopLeft.Width * 2, rect.Top + (float)Self.Border.TopLeft.Height * 2); var topRight = new SKRect(rect.Right - (float)Self.Border.TopRight.Width * 2, rect.Top, rect.Right, rect.Top + (float)Self.Border.TopRight.Height * 2); var bottomLeft = new SKRect(rect.Left, rect.Bottom - (float)Self.Border.BottomLeft.Height * 2, rect.Left + (float)Self.Border.BottomLeft.Width * 2, rect.Bottom); var bottomRight = new SKRect(rect.Right - (float)Self.Border.BottomRight.Width * 2, rect.Bottom - (float)Self.Border.BottomRight.Height * 2, rect.Right, rect.Bottom); path.ArcTo(topLeft, 180, 90, false); path.ArcTo(topRight, 270, 90, false); path.ArcTo(bottomRight, 0, 90, false); path.ArcTo(bottomLeft, 90, 90, false); path.Close(); borderTop.ArcTo(topLeft, 225, 45, false); borderTop.ArcTo(topRight, 270, 45, false); borderLeft.ArcTo(bottomLeft, 135, 45, false); borderLeft.ArcTo(topLeft, 180, 45, false); borderRight.ArcTo(topRight, 315, 45, false); borderRight.ArcTo(bottomRight, 0, 45, false); borderBottom.ArcTo(bottomRight, 45, 45, false); borderBottom.ArcTo(bottomLeft, 90, 45, false); using (var paint = new SKPaint()) { paint.IsAntialias = true; paint.Style = SKPaintStyle.StrokeAndFill; foreach (var shadow in Self.Shadows) { if (shadow.Inset) { continue; } canvas.Save(); canvas.ClipPath(path, SKClipOperation.Difference, true); paint.StrokeWidth = (float)shadow.SpreadRadius; paint.ImageFilter = SKImageFilter.CreateDropShadow((float)shadow.OffsetX, (float)shadow.OffsetY, (float)shadow.BlurRadius, (float)shadow.BlurRadius, shadow.Color.ToSK(), SKDropShadowImageFilterShadowMode.DrawShadowOnly); canvas.DrawPath(path, paint); canvas.Restore(); } paint.ImageFilter = null; foreach (var bg in Self.Backgrounds) { switch (bg.Source) { case SolidColor solid: paint.Style = SKPaintStyle.Fill; paint.Color = solid.Color.ToSK(); canvas.DrawPath(path, paint); break; case LinearGradient linear: path.GetBounds(out var bgRect); paint.Style = SKPaintStyle.Fill; paint.StrokeWidth = 0; var rad = Math.PI / 180 * linear.Angle; var cx = bgRect.Left + bgRect.Width / 2; var cy = bgRect.Top + bgRect.Height / 2; var tan = (float)Math.Tan(rad); var cos = (float)Math.Cos(rad); float x1 = 0, y1 = 0, x2 = 0, y2 = 0, px = 0, py = 0; if (tan == 0) { x1 = bgRect.Left; y1 = cy; x2 = bgRect.Right; y2 = cy; } else if (cos == 0) { x1 = cx; y1 = bgRect.Top; x2 = cx; y2 = bgRect.Bottom; } else { if (tan > 0 && cos > 0) { px = bgRect.Right; py = bgRect.Bottom; } else if (tan > 0 && cos < 0) { px = bgRect.Left; py = bgRect.Top; } else if (tan < 0 && cos > 0) { px = bgRect.Right; py = bgRect.Top; } else if (tan < 0 && cos < 0) { px = bgRect.Left; py = bgRect.Bottom; } var p = (-tan * px + py + tan * cx - cy) / (tan * tan + 1); x1 = p * tan + px; y1 = py - p; x2 = 2 * cx - x1; y2 = 2 * cy - y1; } paint.StrokeWidth = 0; paint.Style = SKPaintStyle.Fill; paint.Shader = SKShader.CreateLinearGradient( new SKPoint(x1, y1), new SKPoint(x2, y2), linear.Colors.Select(color => color.ToSK()).ToArray(), linear.ColorPosition.ToArray(), SKShaderTileMode.Repeat); canvas.DrawPath(path, paint); break; } } paint.Shader = null; paint.Style = SKPaintStyle.Stroke; foreach (var shadow in Self.Shadows) { if (!shadow.Inset) { continue; } canvas.Save(); paint.StrokeWidth = (float)shadow.SpreadRadius; paint.ImageFilter = SKImageFilter.CreateDropShadow((float)shadow.OffsetX, (float)shadow.OffsetY, (float)shadow.BlurRadius, (float)shadow.BlurRadius, shadow.Color.ToSK(), SKDropShadowImageFilterShadowMode.DrawShadowOnly); canvas.ClipPath(path, antialias: true); canvas.DrawPath(path, paint); canvas.Restore(); } paint.ImageFilter = null; paint.StrokeCap = SKStrokeCap.Square; paint.Style = SKPaintStyle.Stroke; if (Self.Border.TopWidth > 0) { paint.Color = Self.Border.TopColor.ToSK(); paint.StrokeWidth = (float)Self.Border.TopWidth; canvas.DrawPath(borderTop, paint); } if (Self.Border.RightWidth > 0) { paint.Color = Self.Border.RightColor.ToSK(); paint.StrokeWidth = (float)Self.Border.RightWidth; canvas.DrawPath(borderRight, paint); } if (Self.Border.BottomWidth > 0) { paint.Color = Self.Border.BottomColor.ToSK(); paint.StrokeWidth = (float)Self.Border.BottomWidth; canvas.DrawPath(borderBottom, paint); } if (Self.Border.LeftWidth > 0) { paint.Color = Self.Border.LeftColor.ToSK(); paint.StrokeWidth = (float)Self.Border.LeftWidth; canvas.DrawPath(borderLeft, paint); } } }
public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat) { if (string.IsNullOrWhiteSpace(inputPath)) { throw new ArgumentNullException("inputPath"); } if (string.IsNullOrWhiteSpace(inputPath)) { throw new ArgumentNullException("outputPath"); } var skiaOutputFormat = GetImageFormat(selectedOutputFormat); var hasBackgroundColor = !string.IsNullOrWhiteSpace(options.BackgroundColor); var hasForegroundColor = !string.IsNullOrWhiteSpace(options.ForegroundLayer); var blur = options.Blur ?? 0; var hasIndicator = options.AddPlayedIndicator || options.UnplayedCount.HasValue || !options.PercentPlayed.Equals(0); using (var bitmap = GetBitmap(inputPath, options.CropWhiteSpace)) { if (bitmap == null) { throw new Exception(string.Format("Skia unable to read image {0}", inputPath)); } //_logger.Info("Color type {0}", bitmap.Info.ColorType); var originalImageSize = new ImageSize(bitmap.Width, bitmap.Height); ImageHelper.SaveImageSize(inputPath, dateModified, originalImageSize); if (!options.CropWhiteSpace && options.HasDefaultOptions(inputPath, originalImageSize)) { // Just spit out the original file if all the options are default return(inputPath); } var newImageSize = ImageHelper.GetNewImageSize(options, originalImageSize); var width = Convert.ToInt32(Math.Round(newImageSize.Width)); var height = Convert.ToInt32(Math.Round(newImageSize.Height)); using (var resizedBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType)) { // scale image var resizeMethod = SKBitmapResizeMethod.Lanczos3; bitmap.Resize(resizedBitmap, resizeMethod); // If all we're doing is resizing then we can stop now if (!hasBackgroundColor && !hasForegroundColor && blur == 0 && !hasIndicator) { using (var outputStream = new SKFileWStream(outputPath)) { resizedBitmap.Encode(outputStream, skiaOutputFormat, quality); return(outputPath); } } // create bitmap to use for canvas drawing using (var saveBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType)) { // create canvas used to draw into bitmap using (var canvas = new SKCanvas(saveBitmap)) { // set background color if present if (hasBackgroundColor) { canvas.Clear(SKColor.Parse(options.BackgroundColor)); } // Add blur if option is present if (blur > 0) { using (var paint = new SKPaint()) { // create image from resized bitmap to apply blur using (var filter = SKImageFilter.CreateBlur(blur, blur)) { paint.ImageFilter = filter; canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint); } } } else { // draw resized bitmap onto canvas canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height)); } // If foreground layer present then draw if (hasForegroundColor) { Double opacity; if (!Double.TryParse(options.ForegroundLayer, out opacity)) { opacity = .4; } canvas.DrawColor(new SKColor(0, 0, 0, (Byte)((1 - opacity) * 0xFF)), SKBlendMode.SrcOver); } if (hasIndicator) { DrawIndicator(canvas, width, height, options); } using (var outputStream = new SKFileWStream(outputPath)) { saveBitmap.Encode(outputStream, skiaOutputFormat, quality); } } } } } return(outputPath); }
public void DrawPopover() { // Define paint if (CakeOrientation.CurrentlySelected != null) { SKPaint fillPaint = new SKPaint { Color = SKColors.Transparent, IsAntialias = true }; PopOver popOver = CakeOrientation.PopOver; PieceOfCake Slice = CakeOrientation.CurrentlySelected; SKPath centerCircle = new SKPath(); fillPaint.Color = CakeOrientation.CurrentlySelected.Color; fillPaint.ImageFilter = SKImageFilter.CreateDropShadow(1, 1, 20 * popOver.Factor, 20 * popOver.Factor, SKColors.Black.WithAlpha(80), SKDropShadowImageFilterShadowMode.DrawShadowAndForeground); float radius = popOver.Radius * popOver.Factor; float amountFontSize = popOver.AmountFontSize * popOver.Factor; float unitFontSize = popOver.UnitFontSize * popOver.Factor; float titleFontSize = popOver.TitleFontSize * popOver.Factor; SKColor testColor = SKColors.White; SKColor titleFontColor = testColor; SKColor amountFontColor = testColor; SKColor unitFontColor = testColor; //connectRect.AddRect(rect); centerCircle.AddCircle(CakeOrientation.Center.X, CakeOrientation.Center.Y, radius); // Draw path canvas.DrawPath(centerCircle, fillPaint); // Define paint SKPaint titlePaint = CakeOrientation.NormalFont; titlePaint.Color = titleFontColor; titlePaint.TextSize = titleFontSize; SKPaint amountPaint = CakeOrientation.BoldFont; amountPaint.Color = amountFontColor; amountPaint.TextSize = amountFontSize; SKPaint unitPaint = titlePaint; SKPoint amountTextCenter = CakeOrientation.Center; SKPoint titleTextCenter = CakeOrientation.Center; SKPoint unitTextCenter = CakeOrientation.Center; float amountTextHeight = amountFontSize / 0.75f; float titleTextHeight = titleFontSize / 0.75f; amountTextCenter.Y += amountFontSize / 2 * 0.75f; titleTextCenter.Y -= (amountTextHeight / 2 - titleTextHeight / 2 + 5); unitTextCenter.Y += (amountTextHeight / 2 + 5); // Draw Text canvas.DrawText(((int)Slice.Emission.KgCO2).ToString(), amountTextCenter, amountPaint); canvas.DrawText(CakeUtil.GetTitle(Slice.Emission), titleTextCenter, titlePaint); canvas.DrawText("kg CO2", unitTextCenter, unitPaint); } }