void RunSampleE(PixelFarm.Drawing.Painter p) { //version 4: p.Clear(PixelFarm.Drawing.Color.White); p.UseSubPixelLcdEffect = this.EnableSubPix; //-------------------------- p.StrokeColor = PixelFarm.Drawing.Color.Black; p.StrokeWidth = 2.0f; p.DrawLine(2, 0, 10, 15); int lineLen = 10; int x = 30; int y = 30; p.FillColor = PixelFarm.Drawing.Color.Black; p.FillRect(0, 0, 1, 1); for (int i = 0; i < 360; i += 30) { p.DrawLine(x, y, x + lineLen * Math.Cos(DegToRad(i)), y + lineLen * Math.Sin(DegToRad(i))); } y += 10; for (int i = 0; i < 360; i += 360) { p.DrawLine(x, y, x + lineLen * Math.Cos(DegToRad(i)), y + lineLen * Math.Sin(DegToRad(i))); } }
public override void Draw(PixelFarm.Drawing.Painter p) { var aggPainter = p as PixelFarm.Agg.AggPainter; if (aggPainter == null) { return; } switch (DrawStrokeSample) { default: throw new System.NotSupportedException(); case DrawStrokeSample.A: DrawA(aggPainter); break; case DrawStrokeSample.B: DrawB(aggPainter); break; case DrawStrokeSample.C: DrawC(aggPainter); break; case DrawStrokeSample.D: DrawD(aggPainter); break; case DrawStrokeSample.E: DrawE(aggPainter); break; } }
void DrawD(PixelFarm.Drawing.Painter painter) { PathWriter ps = new PathWriter(); painter.Clear(PixelFarm.Drawing.Color.White); painter.StrokeColor = PixelFarm.Drawing.Color.Red; //p.Line(10, 10, 50, 10); //p.Line(50, 10, 50, 50); //p.Line(50, 50, 10, 50); //p.Line(50, 10, 10, 10); ps.Clear(); ps.MoveTo(10, 10); ps.LineTo(50, 10); ps.LineTo(50, 50); ps.LineTo(10, 50); ps.CloseFigure(); // //ps.MoveTo(15, 15); //ps.LineTo(15, 45); //ps.LineTo(45, 45); //ps.LineTo(45, 15); //ps.CloseFigure(); // //p.Fill(ps.Vxs, PixelFarm.Drawing.Color.Black); painter.Draw(ps.Vxs, PixelFarm.Drawing.Color.Red); }
void RunSampleD(PixelFarm.Drawing.Painter p) { //version 4: p.Clear(PixelFarm.Drawing.Color.White); p.UseSubPixelLcdEffect = this.EnableSubPix; //-------------------------- p.StrokeColor = PixelFarm.Drawing.Color.Black; p.StrokeWidth = 1.0f; //p.Line(2, 0, 10, 15); int lineLen = 10; int x = 30; int y = 30; for (int i = 0; i < 360; i += 15) { p.DrawLine(x, y, x + lineLen * Math.Cos(DegToRad(i)), y + lineLen * Math.Sin(DegToRad(i))); y += 5; } //y += 10; //for (int i = 0; i < 360; i += 360) //{ // p.Line(x, y, x + lineLen * Math.Cos(DegToRad(i)), y + lineLen * Math.Sin(DegToRad(i))); //} }
public override void Draw(PixelFarm.Drawing.Painter p) { p.RenderQuality = RenderQuality.Fast; Brush prevBrush = p.CurrentBrush; Brush selectedBrush = _linearGrBrush; p.Clear(Color.White); switch (SelectedBrushKind) { case BrushKind.LinearGradient: break; case BrushKind.CircularGradient: selectedBrush = _circularGrBrush; break; case BrushKind.PolygonGradient: selectedBrush = _polygonGradientBrush; break; } // p.CurrentBrush = selectedBrush; p.FillRect(0, 100, 500, 500); //p.FillRect(0, 200, 200, 50); //p.Fill(_triangleVxs); ////------------- p.CurrentBrush = prevBrush; }
void RunSampleF(PixelFarm.Drawing.Painter p) { //version 4: p.Clear(PixelFarm.Drawing.Color.White); p.UseSubPixelLcdEffect = this.EnableSubPix; //-------------------------- p.StrokeColor = PixelFarm.Drawing.Color.Black; p.StrokeWidth = 2.0f; p.DrawLine(2, 0, 10, 15); int lineLen = 10; int x = 30; int y = 30; p.FillColor = PixelFarm.Drawing.Color.Black; VertexStorePool pool = new VertexStorePool(); using (System.IO.FileStream fs = new System.IO.FileStream("c:\\Windows\\Fonts\\tahoma.ttf", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { Typography.OpenFont.OpenFontReader reader = new Typography.OpenFont.OpenFontReader(); Typography.OpenFont.Typeface typeface = reader.Read(fs); var builder = new Typography.Contours.GlyphPathBuilder(typeface); builder.BuildFromGlyphIndex((ushort)typeface.LookupIndex('C'), 16); PixelFarm.Drawing.Fonts.GlyphTranslatorToVxs tovxs = new Drawing.Fonts.GlyphTranslatorToVxs(); builder.ReadShapes(tovxs); VertexStore vxs = new VertexStore(); tovxs.WriteOutput(vxs); p.Fill(vxs); } p.FillRect(0, 0, 20, 20); }
void RunSampleC(PixelFarm.Drawing.Painter p) { //version 3: p.Clear(PixelFarm.Drawing.Color.White); //--------------------------------------------- p.StrokeColor = PixelFarm.Drawing.Color.Black; p.StrokeWidth = 1.0f; p.UseSubPixelLcdEffect = this.EnableSubPix; p.DrawLine(0, 1, 15, 20); }
void DrawPoint(PixelFarm.Drawing.Painter p, Vector2 v) { Color prev = p.FillColor; p.FillColor = Color.Red; p.FillRect(v.X, v.Y, 4, 4); p.FillColor = prev; }
public override void Draw(PixelFarm.Drawing.Painter p) { var aggPainter = p as PixelFarm.Agg.AggPainter; if (aggPainter == null) { return; } Draw(aggPainter); }
public override void Draw(PixelFarm.Drawing.Painter p) { p.Clear(Drawing.Color.White); p.FillColor = Drawing.Color.Black; int j = myBrushPathList.Count; for (int n = 0; n < j; ++n) { var brushPath = myBrushPathList[n]; if (brushPath.Vxs != null) { switch (brushPath.BrushMode) { case SmoothBrushMode.CutBrush: { } break; default: { //TODO: review PixelCache here p.FillColor = brushPath.FillColor; p.Fill(brushPath.Vxs); #if DEBUG //if (brushPath.StrokeColor.alpha > 0) //{ // p.StrokeColor = Drawing.Color.Red; // p.Draw(brushPath.Vxs); //} #endif } break; } } else { //current drawing brush var contPoints = brushPath.contPoints; int pcount = contPoints.Count; for (int i = 1; i < pcount; ++i) { var p0 = contPoints[i - 1]; var p1 = contPoints[i]; p.DrawLine(p0.x, p0.y, p1.x, p1.y); } } } }
void DrawE(PixelFarm.Drawing.Painter painter) { PathWriter ps = new PathWriter(); painter.Clear(PixelFarm.Drawing.Color.White); painter.StrokeColor = PixelFarm.Drawing.Color.Red; //p.Line(10, 10, 50, 10); //p.Line(50, 10, 50, 50); //p.Line(50, 50, 10, 50); //p.Line(50, 10, 10, 10); ps.Clear(); //ps.MoveTo(10, 10); //ps.LineTo(50, 10); //ps.LineTo(50, 50); //ps.MoveTo(10, 10); //ps.LineTo(50, 10); //ps.LineTo(10, 20); ps.MoveTo(150, 10); ps.LineTo(110, 10); ps.LineTo(150, 20); //ps.MoveTo(50, 50); //ps.LineTo(40, 50); //ps.LineTo(80, 70); //ps.CloseFigure(); //p.Fill(ps.Vxs, PixelFarm.Drawing.Color.Black); VertexStore output = new VertexStore(); StrokeGen2 gen2 = new StrokeGen2(); gen2.LineCapStyle = LineCap.Butt; gen2.LineJoinStyle = LineJoin.Miter; gen2.HalfStrokeWidth = 7;// gen2.Generate(ps.Vxs, output); //----------------------------------------------------- painter.Fill(output, PixelFarm.Drawing.Color.Red); painter.StrokeWidth = 1f; painter.Draw(ps.Vxs, PixelFarm.Drawing.Color.Black); }
void DrawBoneJoint(PixelFarm.Drawing.Painter painter, GlyphBoneJoint joint) { //-------------- EdgeLine p_contactEdge = joint.dbugGetEdge_P(); //mid point Vector2 jointPos = joint.OriginalJointPos * _pxscale;//scaled joint pos painter.FillRect(jointPos.X, jointPos.Y, 4, 4, PixelFarm.Drawing.Color.Yellow); if (joint.TipEdgeP != null) { EdgeLine tipEdge = joint.TipEdgeP; double p_x, p_y, q_x, q_y; tipEdge.dbugGetScaledXY(out p_x, out p_y, out q_x, out q_y, _pxscale); // painter.Line( jointPos.X, jointPos.Y, p_x, p_y, PixelFarm.Drawing.Color.White); painter.FillRect(p_x, p_y, 3, 3, PixelFarm.Drawing.Color.Green); //marker // painter.Line( jointPos.X, jointPos.Y, q_x, q_y, PixelFarm.Drawing.Color.White); painter.FillRect(q_x, q_y, 3, 3, PixelFarm.Drawing.Color.Green); //marker } if (joint.TipEdgeQ != null) { EdgeLine tipEdge = joint.TipEdgeQ; double p_x, p_y, q_x, q_y; tipEdge.dbugGetScaledXY(out p_x, out p_y, out q_x, out q_y, _pxscale); // painter.Line( jointPos.X, jointPos.Y, p_x, p_y, PixelFarm.Drawing.Color.White); painter.FillRect(p_x, p_y, 3, 3, PixelFarm.Drawing.Color.Green); //marker // painter.Line( jointPos.X, jointPos.Y, q_x, q_y, PixelFarm.Drawing.Color.White); painter.FillRect(q_x, q_y, 3, 3, PixelFarm.Drawing.Color.Green); //marker } }
void RenderGrids(int width, int height, int sqSize, PixelFarm.Drawing.Painter p) { //render grid p.FillColor = PixelFarm.Drawing.Color.Gray; float pointW = (sqSize >= 100) ? 2 : 1; for (int y = 0; y < height;) { for (int x = 0; x < width;) { p.FillRect(x, y, pointW, pointW); x += sqSize; } y += sqSize; } }
public override void Draw(PixelFarm.Drawing.Painter p) { if (myvxs == null) { var transform = Affine.NewMatix( AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y), AffinePlan.Scale(spriteScale, spriteScale), AffinePlan.Rotate(angle + Math.PI), AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0), AffinePlan.Translate(Width / 2, Height / 2) ); //create vertextStore again from original path myvxs = new VertexStore(); transform.TransformToVxs(lionShape.Vxs, myvxs); if (AutoFlipY) { //flip the lion PixelFarm.Agg.Transform.Affine aff = PixelFarm.Agg.Transform.Affine.NewMatix( PixelFarm.Agg.Transform.AffinePlan.Scale(-1, -1), PixelFarm.Agg.Transform.AffinePlan.Translate(0, 600)); // var v2 = new VertexStore(); myvxs = transform.TransformToVxs(myvxs, v2); } } //--------------------------------------------------------------------------------------------- { int j = lionShape.NumPaths; int[] pathList = lionShape.PathIndexList; Drawing.Color[] colors = lionShape.Colors; //graphics2D.UseSubPixelRendering = true; for (int i = 0; i < j; ++i) { p.FillColor = colors[i]; p.Fill(new VertexStoreSnap(myvxs, pathList[i])); } } //test if (SharpenRadius > 0) { //p.DoFilter(new RectInt(0, p.Height, p.Width, 0), 2); //PixelFarm.Agg.Imaging.SharpenFilterARGB.Sharpen() } }
public static void DrawVxsPoints(VertexStore vxs, PixelFarm.Drawing.Painter p) { int j = vxs.Count; for (int i = 0; i < j; ++i) { double x, y; var cmd = vxs.GetVertex(i, out x, out y); switch (cmd) { case VertexCmd.MoveTo: { p.FillColor = PixelFarm.Drawing.Color.Blue; p.FillRect(x, y, 5, 5); p.DrawString(i.ToString(), x, y + 5); } break; case VertexCmd.C3: { p.FillColor = PixelFarm.Drawing.Color.Red; p.FillRect(x, y, 5, 5); p.DrawString(i.ToString(), x, y + 5); } break; case VertexCmd.C4: { p.FillColor = PixelFarm.Drawing.KnownColors.Gray; p.FillRect(x, y, 5, 5); p.DrawString(i.ToString(), x, y + 5); } break; case VertexCmd.LineTo: { p.FillColor = PixelFarm.Drawing.Color.Yellow; p.FillRect(x, y, 5, 5); p.DrawString(i.ToString(), x, y + 5); } break; } } }
void RunSampleA(PixelFarm.Drawing.Painter p) { //1. create simple vertical line to test agg's lcd rendernig technique //create gray-scale actual image ActualImage glyphImg = new ActualImage(100, 100, PixelFormat.ARGB32); AggRenderSurface glyph2d = new AggRenderSurface(glyphImg); AggPainter painter = new AggPainter(glyph2d); painter.StrokeColor = PixelFarm.Drawing.Color.Black; painter.StrokeWidth = 2.0f * 3; int x = 10, y = 10; painter.DrawLine(x * 3, 0, y * 3, 20); //scale horizontal 3 times, int lineLen = 4; //painter.Line(x * 3, 0, y * 3, 20); //scale horizontal 3 times, //painter.Line(2, 0, 2, 15); //painter.Line(2, 0, 20, 20); //painter.Line(2, 0, 30, 15); //painter.Line(2, 0, 30, 5); //clear surface bg p.Clear(PixelFarm.Drawing.Color.White); //draw img into that bg //--------------- //convert glyphImg from RGBA to grey Scale buffer //--------------- //lcd process ... byte[] glyphGreyScale = CreateGreyScaleBuffer(glyphImg); //--------------- //swap gray scale int newGreyImgStride; byte[] expanedGreyScaleBuffer = CreateNewExpandedLcdGrayScale(glyphGreyScale, glyphImg.Width, glyphImg.Height, out newGreyImgStride); //blend lcd var aggPainer = (PixelFarm.Agg.AggPainter)p; Blend(aggPainer.RenderSurface.DestActualImage, expanedGreyScaleBuffer, newGreyImgStride, glyphImg.Height); //--------------- p.DrawImage(glyphImg, 0, 50); }
public override void Draw(PixelFarm.Drawing.Painter p) { AggPainter aggPainter = (AggPainter)p; //---------------- //5. use PixelFarm's Agg to render to bitmap... //5.1 clear background p.Clear(PixelFarm.Drawing.Color.White); if (FillBG) { //5.2 p.FillColor = PixelFarm.Drawing.Color.Black; //5.3 //p.Fill(vxs); float x = aggPainter.OriginX; float y = aggPainter.OriginY; p.Fill(left_vxs); aggPainter.SetOrigin(x + 50, y + 20); p.Fill(right_vxs); aggPainter.SetOrigin(x, y); } if (FillBorder) { //5.4 p.StrokeColor = PixelFarm.Drawing.Color.Green; //user can specific border width here... //p.StrokeWidth = 2; //5.5 //p.Draw(vxs); float x = aggPainter.OriginX; float y = aggPainter.OriginY; p.Fill(left_vxs); aggPainter.SetOrigin(x + 50, y + 20); p.Fill(right_vxs); aggPainter.SetOrigin(x, y); } }
void RunSampleA(PixelFarm.Drawing.Painter p) { //1. create simple vertical line to test agg's lcd rendernig technique //create gray-scale actual image using (MemBitmap glyphBmp = new MemBitmap(100, 100)) { int x = 10, y = 10; using (AggPainterPool.Borrow(glyphBmp, out var painter)) { painter.StrokeColor = PixelFarm.Drawing.Color.Black; painter.StrokeWidth = 2.0f * 3; painter.DrawLine(x * 3, 0, y * 3, 20); //scale horizontal 3 times, s } //painter.Line(x * 3, 0, y * 3, 20); //scale horizontal 3 times, //painter.Line(2, 0, 2, 15); //painter.Line(2, 0, 20, 20); //painter.Line(2, 0, 30, 15); //painter.Line(2, 0, 30, 5); //clear surface bg p.Clear(PixelFarm.Drawing.Color.White); //draw img into that bg //--------------- //convert glyphImg from RGBA to grey Scale buffer //--------------- //lcd process ... byte[] glyphGreyScale = CreateGreyScaleBuffer(glyphBmp); //--------------- //swap gray scale int newGreyImgStride; byte[] expanedGreyScaleBuffer = CreateNewExpandedLcdGrayScale(glyphGreyScale, glyphBmp.Width, glyphBmp.Height, out newGreyImgStride); //blend lcd var aggPainer = (PixelFarm.CpuBlit.AggPainter)p; Blend(aggPainer.RenderSurface.DestBitmap, expanedGreyScaleBuffer, newGreyImgStride, glyphBmp.Height); //--------------- p.DrawImage(glyphBmp, 0, 50); } }
void DrawPointKind(PixelFarm.Drawing.Painter painter, GlyphPoint point) { if (!DrawGlyphPoint) { return; } switch (point.PointKind) { case PointKind.C3Start: case PointKind.C3End: case PointKind.C4Start: case PointKind.C4End: case PointKind.LineStart: case PointKind.LineStop: painter.FillRect(point.OX * _pxscale, point.OY * _pxscale, 5, 5, PixelFarm.Drawing.Color.Red); break; } }
void RunSampleB(PixelFarm.Drawing.Painter p) { //version 2: //1. create simple vertical line to test agg's lcd rendernig technique //create gray-scale actual image using (MemBitmap glyphBmp = new MemBitmap(100, 100)) { AggPainter painter = AggPainter.Create(glyphBmp); // painter.StrokeColor = PixelFarm.Drawing.Color.Black; painter.StrokeWidth = 2.0f; painter.DrawLine(2, 0, 3, 15); //not need to scale3 // //clear surface bg p.Clear(PixelFarm.Drawing.Color.White); //-------------------------- var aggPainer = (PixelFarm.CpuBlit.AggPainter)p; BlendWithLcdTechnique(aggPainer.RenderSurface.DestBitmap, glyphBmp, PixelFarm.Drawing.Color.Black); //--------------- p.DrawImage(glyphBmp, 0, 50); //--------------- } }
public override void Draw(PixelFarm.Drawing.Painter p) { //specific for agg if (!(p is PixelFarm.Agg.AggPainter)) { return; } switch (Sample) { default: throw new NotSupportedException(); case Sample.A: RunSampleA(p); break; case Sample.B: RunSampleB(p); break; case Sample.C: RunSampleC(p); break; case Sample.D: RunSampleD(p); break; case Sample.E: RunSampleE(p); break; case Sample.F: RunSampleF(p); break; } }
void RunSampleB(PixelFarm.Drawing.Painter p) { //version 2: //1. create simple vertical line to test agg's lcd rendernig technique //create gray-scale actual image ActualImage glyphImg = new ActualImage(100, 100, PixelFormat.ARGB32); AggRenderSurface glyph2d = new AggRenderSurface(glyphImg); AggPainter painter = new AggPainter(glyph2d); // painter.StrokeColor = PixelFarm.Drawing.Color.Black; painter.StrokeWidth = 2.0f; painter.DrawLine(2, 0, 3, 15);//not need to scale3 // //clear surface bg p.Clear(PixelFarm.Drawing.Color.White); //-------------------------- var aggPainer = (PixelFarm.Agg.AggPainter)p; BlendWithLcdTechnique(aggPainer.RenderSurface.DestActualImage, glyphImg, PixelFarm.Drawing.Color.Black); //--------------- p.DrawImage(glyphImg, 0, 50); //--------------- }
public virtual void Draw(PixelFarm.Drawing.Painter p) { }
public override void Draw(PixelFarm.Drawing.Painter p) { //specific for agg if (!(p is AggPainter)) { return; } throw new NotSupportedException(); AggPainter p2 = (AggPainter)p; AggRenderSurface aggRdsf = p2.RenderSurface; if (aggRdsf.DestImage != null) { IImageReaderWriter backBuffer = aggRdsf.DestImage; IPixelBlender currentPixelBlender = aggRdsf.PixelBlender; int distBetween = backBuffer.BytesBetweenPixelsInclusive; //use different pixel blender var redImageBuffer = new SubImageRW(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.R, 8); var greenImageBuffer = new SubImageRW(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.G, 8); var blueImageBuffer = new SubImageRW(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.B, 8); ClipProxyImage clippingProxy = new ClipProxyImage(backBuffer); ClipProxyImage clippingProxyRed = new ClipProxyImage(redImageBuffer); ClipProxyImage clippingProxyGreen = new ClipProxyImage(greenImageBuffer); ClipProxyImage clippingProxyBlue = new ClipProxyImage(blueImageBuffer); ScanlineRasterizer sclineRas = aggRdsf.ScanlineRasterizer; ScanlinePacked8 scline = aggRdsf.ScanlinePacked8; Drawing.Color clearColor = this.UseBlackBlackground ? Drawing.Color.FromArgb(0, 0, 0) : Drawing.Color.FromArgb(255, 255, 255); clippingProxy.Clear(clearColor); Drawing.Color fillColor = this.UseBlackBlackground ? new Drawing.Color((byte)(this.AlphaValue), 255, 255, 255) : new Drawing.Color((byte)(this.AlphaValue), 0, 0, 0); ScanlineRasToDestBitmapRenderer sclineRasToBmp = aggRdsf.ScanlineRasToDestBitmap; VertexSource.Ellipse er = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); // VectorToolBox.GetFreeVxs(out var v1); sclineRas.AddPath(er.MakeVxs(v1)); v1.Clear(); sclineRasToBmp.RenderWithColor(clippingProxyRed, sclineRas, scline, fillColor); VertexSource.Ellipse eg = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); sclineRas.AddPath(eg.MakeVertexSnap(v1)); v1.Clear(); sclineRasToBmp.RenderWithColor(clippingProxyGreen, sclineRas, scline, fillColor); VertexSource.Ellipse eb = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100); sclineRas.AddPath(eb.MakeVertexSnap(v1)); v1.Clear(); sclineRasToBmp.RenderWithColor(clippingProxyBlue, sclineRas, scline, fillColor); VectorToolBox.ReleaseVxs(ref v1); } // else if (graphics2D.DestImageFloat != null) // { //#if false // IImageFloat backBuffer = graphics2D.DestImageFloat; // int distBetween = backBuffer.GetFloatsBetweenPixelsInclusive(); // ImageBufferFloat redImageBuffer = new ImageBufferFloat(); // redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8); // ImageBufferFloat greenImageBuffer = new ImageBufferFloat(); // greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8); // ImageBufferFloat blueImageBuffer = new ImageBufferFloat(); // blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8); // ImageClippingProxy clippingProxy = new ImageClippingProxy(backBuffer); // ImageClippingProxy clippingProxyRed = new ImageClippingProxy(redImageBuffer); // ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer); // ImageClippingProxy clippingProxyBlue = new ImageClippingProxy(blueImageBuffer); // ScanlineRasterizer ras = new ScanlineRasterizer(); // ScanlineCachePacked8 sl = new ScanlineCachePacked8(); // RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255); // clippingProxy.clear(clearColor); // alphaSlider.View.BackGroundColor = clearColor; // RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value)); // VertexSource.Ellipse er = new AGG.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); // ras.add_path(er); // agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyRed, ras, sl, FillColor); // VertexSource.Ellipse eg = new AGG.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); // ras.add_path(eg); // agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyGreen, ras, sl, FillColor); // VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100); // ras.add_path(eb); // agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor); //#endif // } }
void DrawLine(PixelFarm.Drawing.Painter p, Vector2 v0, Vector2 v1) { p.Line(v0.x, v0.y, v1.x, v1.Y, p.StrokeColor); }
void DrawPerpendicularEdgeControlPoints(PixelFarm.Drawing.Painter painter, OutsideEdgeLine internalEdgeLine) { //Vector2 regen0 = edge._newRegen0 * _pxscale; //Vector2 regen1 = edge._newRegen1 * _pxscale; //painter.FillRectLBWH(regen0.X, regen0.Y, 5, 5, PixelFarm.Drawing.Color.Green); //painter.FillRectLBWH(regen1.X, regen1.Y, 5, 5, PixelFarm.Drawing.Color.Blue); bool foundSomePerpendicularEdge = false; if (internalEdgeLine.ControlEdge_P != null && internalEdgeLine.ControlEdge_Q != null) { Vector2 m0 = internalEdgeLine.ControlEdge_P.GetMidPoint(); Vector2 m1 = internalEdgeLine.ControlEdge_Q.GetMidPoint(); //find angle from m0-> m1 Vector2 v2 = (m0 + m1) / 2; //find perpendicular line from midpoint_m0m1 to edge Vector2 cutpoint; if (MyMath.FindPerpendicularCutPoint(internalEdgeLine, v2, out cutpoint)) { painter.Line( v2.X * _pxscale, v2.Y * _pxscale, cutpoint.X * _pxscale, cutpoint.Y * _pxscale, PixelFarm.Drawing.Color.Red); foundSomePerpendicularEdge = true; } //Vector2 e0_fitpos = internalEdgeLine.ControlEdge_P.GetFitPos() * _pxscale; //Vector2 e1_fitpos = internalEdgeLine.ControlEdge_Q.GetFitPos() * _pxscale; //painter.Line( // e0_fitpos.X, e0_fitpos.Y, // regen0.X, regen0.Y, // PixelFarm.Drawing.Color.Yellow); //painter.Line( // e1_fitpos.X, e1_fitpos.Y, // regen1.X, regen1.Y, // PixelFarm.Drawing.Color.Yellow); } if (internalEdgeLine.ControlEdge_P != null) { Vector2 v2 = internalEdgeLine.ControlEdge_P.GetMidPoint(); //Vector2 cutpoint = internalEdgeLine._ctrlEdge_P_cutAt; //painter.Line( // v2.X * _pxscale, v2.Y * _pxscale, // cutpoint.X * _pxscale, cutpoint.Y * _pxscale, // PixelFarm.Drawing.Color.Green); //foundSomePerpendicularEdge = true; } if (internalEdgeLine.ControlEdge_Q != null) { Vector2 v2 = internalEdgeLine.ControlEdge_Q.GetMidPoint(); //Vector2 cutpoint = internalEdgeLine._ctrlEdge_Q_cutAt; //painter.Line( // v2.X * _pxscale, v2.Y * _pxscale, // cutpoint.X * _pxscale, cutpoint.Y * _pxscale, // PixelFarm.Drawing.Color.Green); //foundSomePerpendicularEdge = true; } if (!foundSomePerpendicularEdge) { //TODO: reimplement this again //Vector2 midpoint = edge.GetMidPoint(); //painter.FillRectLBWH(midpoint.X, midpoint.Y, 5, 5, PixelFarm.Drawing.Color.White); } }
void DrawEdge(PixelFarm.Drawing.Painter painter, EdgeLine edge) { if (edge.IsOutside) { //free side { GlyphPoint p = edge.P; GlyphPoint q = edge.Q; DrawPointKind(painter, p); DrawPointKind(painter, q); _infoView.ShowEdge(edge); switch (edge.SlopeKind) { default: painter.StrokeColor = PixelFarm.Drawing.Color.Green; break; case LineSlopeKind.Vertical: if (edge.IsLeftSide) { painter.StrokeColor = PixelFarm.Drawing.Color.Blue; } else { painter.StrokeColor = PixelFarm.Drawing.Color.LightGray; } break; case LineSlopeKind.Horizontal: if (edge.IsUpper) { painter.StrokeColor = PixelFarm.Drawing.Color.Red; } else { //lower edge painter.StrokeColor = PixelFarm.Drawing.Color.Magenta; } break; } } float scale = this._pxscale; //show info: => edge point if (this.DrawPerpendicularLine && _infoView.HasDebugMark) { double prevWidth = painter.StrokeWidth; painter.StrokeWidth = 3; painter.Line(edge.PX * scale, edge.PY * scale, edge.QX * scale, edge.QY * scale, PixelFarm.Drawing.Color.Yellow); painter.StrokeWidth = prevWidth; //draw GlyphPoint p = edge.P; GlyphPoint q = edge.Q; // //AssocBoneCollection p_bones = glyphEdge._P.dbugGetAssocBones(); //if (p_bones != null) //{ // Vector2 v2 = new Vector2(q.x, q.y); // foreach (GlyphBone b in p_bones) // { // Vector2 v3 = b.GetMidPoint(); // painter.Line(v2.X * scale, v2.Y * scale, v3.X * scale, v3.Y * scale, PixelFarm.Drawing.Color.Yellow); // } //} //AssocBoneCollection q_bones = glyphEdge._Q.dbugGetAssocBones(); //if (q_bones != null) //{ // Vector2 v2 = new Vector2(p.x, p.y); // foreach (GlyphBone b in q_bones) // { // //Vector2 v2 = new Vector2(q.x, q.y); // Vector2 v3 = b.GetMidPoint(); // painter.Line(v2.X * scale, v2.Y * scale, v3.X * scale, v3.Y * scale, PixelFarm.Drawing.Color.Green); // } //} { //TODO: reimplement this again //Vector2 orginal_MidPoint = glyphEdge.GetMidPoint() * _pxscale; //Vector2 newMidPoint = glyphEdge.GetNewMidPoint() * _pxscale; //painter.FillRectLBWH(newMidPoint.X, newMidPoint.Y, 3, 3, PixelFarm.Drawing.Color.Red); //painter.Line(newMidPoint.X, newMidPoint.Y, orginal_MidPoint.X, orginal_MidPoint.Y, PixelFarm.Drawing.Color.LightGray); //painter.FillRectLBWH(glyphEdge.newEdgeCut_P_X * _pxscale, glyphEdge.newEdgeCut_P_Y * _pxscale, 6, 6, PixelFarm.Drawing.Color.Blue); //painter.FillRectLBWH(glyphEdge.newEdgeCut_Q_X * _pxscale, glyphEdge.newEdgeCut_Q_Y * _pxscale, 6, 6, PixelFarm.Drawing.Color.Blue); } } else { painter.DrawLine(edge.PX * scale, edge.PY * scale, edge.QX * scale, edge.QY * scale); } { GlyphPoint p = edge.P; GlyphPoint q = edge.Q; //--------- { //TODO: reimplement this again //Vector2 orginal_MidPoint = glyphEdge.GetMidPoint() * _pxscale; //Vector2 newMidPoint = glyphEdge.GetNewMidPoint() * _pxscale; //if (DrawEdgeMidPoint) //{ // painter.FillRectLBWH(newMidPoint.X, newMidPoint.Y, 3, 3, PixelFarm.Drawing.Color.Red); //} //// //painter.Line(newMidPoint.X, newMidPoint.Y, orginal_MidPoint.X, orginal_MidPoint.Y, PixelFarm.Drawing.Color.LightGray); //painter.FillRectLBWH(glyphEdge.newEdgeCut_P_X * _pxscale, glyphEdge.newEdgeCut_P_Y * _pxscale, 4, 4, PixelFarm.Drawing.Color.Blue); //painter.FillRectLBWH(glyphEdge.newEdgeCut_Q_X * _pxscale, glyphEdge.newEdgeCut_Q_Y * _pxscale, 4, 4, PixelFarm.Drawing.Color.Blue); } //--------- if (this.DrawPerpendicularLine) { var asOutsideEdge = edge as OutsideEdgeLine; if (asOutsideEdge != null) { DrawPerpendicularEdgeControlPoints(painter, asOutsideEdge); } } } } else { //draw inside edge painter.Line( edge.PX * _pxscale, edge.PY * _pxscale, edge.QX * _pxscale, edge.QY * _pxscale, PixelFarm.Drawing.Color.Gray); } }
public override void Draw(PixelFarm.Drawing.Painter p) { //specific for agg if (!(p is AggPainter)) { return; } AggPainter p2 = (AggPainter)p; AggRenderSurface asx = p2.RenderSurface; if (asx.DestBitmapBlender != null) { IBitmapBlender backBuffer = asx.DestBitmapBlender; //use different pixel blender var redImageBuffer = new SubBitmapBlender(backBuffer, new PixelBlenderGrey()); var greenImageBuffer = new SubBitmapBlender(backBuffer, new PixelBlenderGrey()); var blueImageBuffer = new SubBitmapBlender(backBuffer, new PixelBlenderGrey()); ClipProxyImage clippingProxy = new ClipProxyImage(backBuffer); ClipProxyImage clippingProxyRed = new ClipProxyImage(redImageBuffer); ClipProxyImage clippingProxyGreen = new ClipProxyImage(greenImageBuffer); ClipProxyImage clippingProxyBlue = new ClipProxyImage(blueImageBuffer); // ScanlineRasterizer sclineRas = asx.ScanlineRasterizer; ScanlinePacked8 scline = asx.ScanlinePacked8; Drawing.Color clearColor = this.UseBlackBlackground ? Drawing.Color.FromArgb(0, 0, 0) : Drawing.Color.FromArgb(255, 255, 255); clippingProxy.Clear(clearColor); Drawing.Color fillColor = this.UseBlackBlackground ? new Drawing.Color((byte)(this.AlphaValue), 255, 255, 255) : new Drawing.Color((byte)(this.AlphaValue), 0, 0, 0); DestBitmapRasterizer bmpRas = asx.BitmapRasterizer; using (VectorToolBox.Borrow(out Ellipse ellipse)) using (VxsTemp.Borrow(out var v1)) { ellipse.Set(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); sclineRas.AddPath(ellipse.MakeVxs(v1)); v1.Clear();//** bmpRas.RenderWithColor(clippingProxyRed, sclineRas, scline, fillColor); //// ellipse.Set(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); sclineRas.AddPath(ellipse.MakeVxs(v1)); v1.Clear();//*** bmpRas.RenderWithColor(clippingProxyGreen, sclineRas, scline, fillColor); // ellipse.Set(Width / 2, Height / 2 + 50, 100, 100, 100); sclineRas.AddPath(ellipse.MakeVxs(v1)); v1.Clear(); //*** bmpRas.RenderWithColor(clippingProxyBlue, sclineRas, scline, fillColor); } } // else if (graphics2D.DestImageFloat != null) // { //#if false // IImageFloat backBuffer = graphics2D.DestImageFloat; // int distBetween = backBuffer.GetFloatsBetweenPixelsInclusive(); // ImageBufferFloat redImageBuffer = new ImageBufferFloat(); // redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8); // ImageBufferFloat greenImageBuffer = new ImageBufferFloat(); // greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8); // ImageBufferFloat blueImageBuffer = new ImageBufferFloat(); // blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8); // ImageClippingProxy clippingProxy = new ImageClippingProxy(backBuffer); // ImageClippingProxy clippingProxyRed = new ImageClippingProxy(redImageBuffer); // ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer); // ImageClippingProxy clippingProxyBlue = new ImageClippingProxy(blueImageBuffer); // ScanlineRasterizer ras = new ScanlineRasterizer(); // ScanlineCachePacked8 sl = new ScanlineCachePacked8(); // RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255); // clippingProxy.clear(clearColor); // alphaSlider.View.BackGroundColor = clearColor; // RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value)); // VertexSource.Ellipse er = new AGG.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); // ras.add_path(er); // agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyRed, ras, sl, FillColor); // VertexSource.Ellipse eg = new AGG.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); // ras.add_path(eg); // agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyGreen, ras, sl, FillColor); // VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100); // ras.add_path(eb); // agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor); //#endif // } }
void DrawControllerPair(PixelFarm.Drawing.Painter p, BezierControllerArmPair c) { DrawLine(p, c.left, c.mid); DrawLine(p, c.mid, c.right); DrawPoint(p, c.mid); }
public override void Draw(PixelFarm.Drawing.Painter p) { p.Clear(Drawing.Color.White); p.StrokeColor = Color.Black; p.StrokeWidth = 2; p.StrokeColor = Color.Green; p.Draw(_triangleVxs); if (!ShowReconstructionCurve) { return; } //draw Ci line p.StrokeColor = KnownColors.OrangeRed; DrawLine(p, a01, a12); DrawLine(p, a12, a20); DrawLine(p, a20, a01); //find B //DrawPoint(p, a01); //DrawPoint(p, a12); //DrawPoint(p, a20); BezierControllerArmPair c1 = BezierControllerArmPair.ReconstructControllerArms(v0, v1, v2); BezierControllerArmPair c2 = BezierControllerArmPair.ReconstructControllerArms(v1, v2, v0); BezierControllerArmPair c0 = BezierControllerArmPair.ReconstructControllerArms(v2, v0, v1); c0.UniformSmoothCoefficient = SmoothCoefficientValue; c1.UniformSmoothCoefficient = SmoothCoefficientValue; c2.UniformSmoothCoefficient = SmoothCoefficientValue; //DrawPoint(p, c0 = FindB(v0, v1, v2, out c1)); //DrawPoint(p, b2 = FindB(v1, v2, v0, out c2)); //DrawPoint(p, b0 = FindB(v2, v0, v1, out c0)); p.StrokeColor = Color.Red; DrawControllerPair(p, c0); DrawControllerPair(p, c1); DrawControllerPair(p, c2); p.StrokeColor = Color.Blue; using (Tools.BorrowVxs(out var tmpVxs1, out var tmpVxs2)) using (Tools.BorrowPathWriter(tmpVxs1, out var pw)) { pw.MoveTo(c0.mid.X, c0.mid.y); pw.Curve4(c0.right.x, c0.right.y, c1.left.x, c1.left.y, c1.mid.x, c1.mid.y); //1st curve pw.Curve4(c1.right.x, c1.right.y, c2.left.x, c2.left.y, c2.mid.x, c2.mid.y); //2nd curve pw.Curve4(c2.right.x, c2.right.y, c0.left.x, c0.left.y, c0.mid.x, c0.mid.y); //3rd curve _curveflattener.MakeVxs(tmpVxs1, tmpVxs2); p.Draw(tmpVxs2); } }