private void PenTipChanged() { //ペン先のstrokeカラー設定 Color strokeColor = PaintColors.Transparent; switch (strokeColorPicker.SelectedItem as string) { default: case "None": strokeColor = PaintColors.Transparent; break; case "Black": strokeColor = PaintColors.Black; break; case "White": strokeColor = PaintColors.White; break; case "Red": strokeColor = PaintColors.Red; break; case "Yellow": strokeColor = PaintColors.Yellow; break; case "Green": strokeColor = PaintColors.Green; break; case "Blue": strokeColor = PaintColors.Blue; break; } anArtBoard.InProgressPath.StrokeColor = strokeColor; anArtBoard.InProgressPath.StrokeSize = (float)strokeSizeStepper.Value; anArtBoard.InProgressPath.StrokeJoin = SKStrokeJoin.Round; anArtBoard.InProgressPath.StrokeCap = SKStrokeCap.Round; anArtBoard.InProgressPath.IsScreentoneBlendMode = screentoneBlendModeSwitch.IsToggled; //ペン先のfillカラー設定 Color fillColor = PaintColors.Transparent; switch (fillColorPicker.SelectedItem as string) { default: case "None": fillColor = PaintColors.Transparent; break; case "Black": fillColor = PaintColors.Black; break; case "White": fillColor = PaintColors.White; break; case "Red": fillColor = PaintColors.Red; break; case "Yellow": fillColor = PaintColors.Yellow; break; case "Green": fillColor = PaintColors.Green; break; case "Blue": fillColor = PaintColors.Blue; break; } SKBitmap bitmap = new SKBitmap(); //ペン先のパターン設定 switch (fillPatternPicker.SelectedItem as string) { default: case "Normal": bitmap = PaintPatterns.NormalPattern(fillColor.ToSKColor()); break; case "Rough3x3": bitmap = PaintPatterns.Rough3x3Pattern(fillColor.ToSKColor()); break; case "Rough2x2": bitmap = PaintPatterns.Rough2x2Pattern(fillColor.ToSKColor()); break; case "Beads4x4": bitmap = PaintPatterns.Beads4x4Pattern(fillColor.ToSKColor()); break; case "StripeX": bitmap = PaintPatterns.StripeXPattern(fillColor.ToSKColor()); break; case "StripeY": bitmap = PaintPatterns.StripeYPattern(fillColor.ToSKColor()); break; case "Checkered": bitmap = PaintPatterns.CheckeredPattern(fillColor.ToSKColor()); break; case "Dense2x2": bitmap = PaintPatterns.Dense2x2Pattern(fillColor.ToSKColor()); break; case "Dense3x3": bitmap = PaintPatterns.Dense3x3Pattern(fillColor.ToSKColor()); break; case "LeftHatching": bitmap = PaintPatterns.LeftHatching8x8Pattern(fillColor.ToSKColor()); break; case "RightHatching": bitmap = PaintPatterns.RightHatching8x8Pattern(fillColor.ToSKColor()); break; } anArtBoard.InProgressPath.Screentone = bitmap; Path.ScreentoneScale = SaveProperties.ScreentoneScale; }
private void OnPaintCanvas(object sender, SKPaintSurfaceEventArgs e) { SKImageInfo info = e.Info; SKSurface surface = e.Surface; SKCanvas canvas = surface.Canvas; int surfaceWidth = info.Width; int surfaceHeight = info.Height; SKPoint surfaceSize = new SKPoint(surfaceWidth, surfaceHeight); //絵画開始 //背景色を塗る canvas.Clear(PaintColors.OutOfRangeBackground.ToSKColor()); //アートボードの絵画 anArtBoard.SizeRecalculation(surfaceSize); using (SKPaint paint = new SKPaint()) { paint.Style = SKPaintStyle.Fill; paint.Color = PaintColors.ArtBoardBackground.ToSKColor(); canvas.DrawRect(anArtBoard.AbsoluteRect, paint); } radius = Math.Min(anArtBoard.Size.X, anArtBoard.Size.Y) / 2.0f * 0.7f; anArtBoard.InProgressPath.StrokeColor = PaintColors.Black; anArtBoard.InProgressPath.StrokeSize = 5; anArtBoard.InProgressPath.StrokeJoin = SKStrokeJoin.Round; anArtBoard.InProgressPath.StrokeCap = SKStrokeCap.Round; anArtBoard.InProgressPath.Screentone = PaintPatterns.CheckeredPattern(PaintColors.Blue.ToSKColor()); anArtBoard.BezierHandleList.Clear(); anArtBoard.BezierHandleList.Add( new BezierHandle( anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2, anArtBoard.Size.Y / 2 - radius), anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 + radius * controlPointCoefficient, anArtBoard.Size.Y / 2 - radius))); anArtBoard.BezierHandleList.Add( new BezierHandle( anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 + radius, anArtBoard.Size.Y / 2), anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 + radius, anArtBoard.Size.Y / 2 + radius * controlPointCoefficient))); anArtBoard.BezierHandleList.Add( new BezierHandle( anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2, anArtBoard.Size.Y / 2 + radius), anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 - radius * controlPointCoefficient, anArtBoard.Size.Y / 2 + radius))); anArtBoard.BezierHandleList.Add( new BezierHandle( anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 - radius, anArtBoard.Size.Y / 2), anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 - radius, anArtBoard.Size.Y / 2 - radius * controlPointCoefficient))); //絶対座標からアスペクト座標に変換 foreach (var bezierHandle in anArtBoard.BezierHandleList) { bezierHandle.AnchorPoint = anArtBoard.MatrixToAspectCoordinates().MapPoint(bezierHandle.AnchorPoint); bezierHandle.MouseControlPoint = anArtBoard.MatrixToAspectCoordinates().MapPoint(bezierHandle.MouseControlPoint); } //暫定Path絵画 if (anArtBoard.BezierHandleList.Count >= 2) { anArtBoard.InProgressPath.Reset(); //bezierHandleList -> inProgressPath anArtBoard.GenerateBezierPath(pathPreview); anArtBoard.InProgressPath.Transform(this.anArtBoard.InverseMatrixToAbsoluteCoordinates()); canvas.DrawPath(anArtBoard.InProgressPath, anArtBoard.InProgressPath.GetFillPaint()); canvas.DrawPath(anArtBoard.InProgressPath, anArtBoard.InProgressPath.GetStrokePaint()); } //コントロールポイントを絵画 SKPaint aBezierHandlePaint = new SKPaint() { IsAntialias = true, Style = SKPaintStyle.Stroke, Color = PaintColors.Lasso.ToSKColor(), StrokeWidth = 2, StrokeJoin = SKStrokeJoin.Round, StrokeCap = SKStrokeCap.Round }; SKPaint aBezierHandleAnchorPaint = new SKPaint() { IsAntialias = true, Style = SKPaintStyle.Fill, Color = PaintColors.Lasso.ToSKColor() }; using (SKPath path = new SKPath()) { foreach (var aBezierHandle in anArtBoard.BezierHandleList) { SKPoint anchorPoint = anArtBoard.InverseMatrixToAbsoluteCoordinates().MapPoint(aBezierHandle.AnchorPoint); SKPoint mouseControlPoint = anArtBoard.InverseMatrixToAbsoluteCoordinates().MapPoint(aBezierHandle.MouseControlPoint); SKPoint theOtherControlPoint = anArtBoard.InverseMatrixToAbsoluteCoordinates().MapPoint(aBezierHandle.TheOtherControlPoint); path.MoveTo(anchorPoint); path.LineTo(mouseControlPoint); canvas.DrawCircle(anchorPoint, 4, aBezierHandleAnchorPaint); path.MoveTo(anchorPoint); path.LineTo(theOtherControlPoint); } canvas.DrawPath(path, aBezierHandlePaint); } }
private void OnPaintCanvas(object sender, SKPaintSurfaceEventArgs e) { SKImageInfo info = e.Info; SKSurface surface = e.Surface; SKCanvas canvas = surface.Canvas; int surfaceWidth = info.Width; int surfaceHeight = info.Height; int aBitmapWidth = surfaceWidth / 4; int aBitmapHeight = surfaceHeight / 2; //絵画開始 //背景色を塗る canvas.Clear(PaintColors.ArtBoardBackground.ToSKColor()); //SKBitmap srcBitmap = PaintPatterns.CheckeredPattern(PaintColors.Black); SKBitmap[] srcBitmapList = new SKBitmap[8]; srcBitmapList[0] = PaintPatterns.Rough3x3Pattern(PaintColors.Black.ToSKColor()); srcBitmapList[1] = PaintPatterns.Rough2x2Pattern(PaintColors.Black.ToSKColor()); srcBitmapList[2] = PaintPatterns.Beads4x4Pattern(PaintColors.Black.ToSKColor()); srcBitmapList[3] = PaintPatterns.StripeXPattern(PaintColors.Black.ToSKColor()); srcBitmapList[4] = PaintPatterns.StripeYPattern(PaintColors.Black.ToSKColor()); srcBitmapList[5] = PaintPatterns.CheckeredPattern(PaintColors.Black.ToSKColor()); srcBitmapList[6] = PaintPatterns.Dense2x2Pattern(PaintColors.Black.ToSKColor()); srcBitmapList[7] = PaintPatterns.Dense3x3Pattern(PaintColors.Black.ToSKColor()); for (int index = 0; index < 8; index++) { SKBitmap dstBitmap = new SKBitmap( new SKImageInfo( srcBitmapList[index].Info.Width * (int)screentoneScaleStepper.Value, srcBitmapList[index].Info.Height * (int)screentoneScaleStepper.Value)); srcBitmapList[index].ScalePixels(dstBitmap, SKFilterQuality.None); SKPaint paint = new SKPaint(); paint.IsAntialias = false; paint.Style = SKPaintStyle.Fill; paint.Shader = SKShader.CreateBitmap(dstBitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat); if (0 <= index && index <= 3) { canvas.DrawRect(new SKRect(aBitmapWidth * index, 0, aBitmapWidth * (index + 1), aBitmapHeight), paint); } else { canvas.DrawRect(new SKRect(aBitmapWidth * (index - 4), aBitmapHeight, aBitmapWidth * ((index - 4) + 1), aBitmapHeight * 2), paint); } } /* * //旧形式 * SKImageInfo srcInfo = new SKImageInfo( * srcBitmap.Width * (int)screentoneScaleStepper.Value, * srcBitmap.Height * (int)screentoneScaleStepper.Value); * SKBitmap dstBitmap = srcBitmap.Resize(srcInfo, SKBitmapResizeMethod.Box); * * * * //新形式 * SKBitmap dstBitmap = new SKBitmap( * new SKImageInfo( * srcBitmap.Info.Width * (int)screentoneScaleStepper.Value, * srcBitmap.Info.Height * (int)screentoneScaleStepper.Value)); * srcBitmap.ScalePixels(dstBitmap,SKFilterQuality.None); * * * * paint.Shader = SKShader.CreateBitmap( * dstBitmap, * SKShaderTileMode.Repeat, * SKShaderTileMode.Repeat); * * * canvas.DrawRect(rect, paint); */ }