public AggTextSpanPrinter(GLPainter canvasPainter, int w, int h) { //this class print long text into agg canvas //then copy pixel buffer from aff canvas to gl-bmp //then draw the gl-bmp into target gl canvas //TODO: review here this.canvasPainter = canvasPainter; this._glsx = canvasPainter.Canvas; bmpWidth = w; bmpHeight = h; _actualImage = new ActualImage(bmpWidth, bmpHeight); _aggsx = new AggRenderSurface(_actualImage); _aggPainter = new AggPainter(_aggsx); _aggPainter.FillColor = Color.Black; _aggPainter.StrokeColor = Color.Black; //set default1 _aggPainter.CurrentFont = canvasPainter.CurrentFont; var openFontStore = new Typography.TextServices.OpenFontStore(); _vxsTextPrinter = new VxsTextPrinter(_aggPainter, openFontStore); _aggPainter.TextPrinter = _vxsTextPrinter; }
void DrawString(AggPainter p, string text, double x, double y) { if (text != null) { DrawString(p, text.ToCharArray(), 0, text.Length, x, y); } }
public override void Draw(Painter p) { AggPainter painter = p as AggPainter; if (painter == null) { return; } painter.Clear(Color.White); int width = painter.Width; int height = painter.Height; //switch to alpha mask painter.TargetBufferName = TargetBufferName.AlphaMask; //draw white rect on the mask painter.FillColor = Color.White; painter.FillRect(20, 20, 50, 50); painter.FillRect(20, 5, 20, 10); //------------------------------------ //switch back to default color painter.TargetBufferName = TargetBufferName.Default; painter.FillColor = Color.Red; //enable mask composite painter.EnableBuiltInMaskComposite = true; painter.FillRect(0, 0, 100, 100); //disable mask buffer painter.EnableBuiltInMaskComposite = false; painter.FillColor = Color.Yellow; painter.FillRect(0, 0, 20, 20); //if (!_maskReady) //{ // SetupMaskPixelBlender(width, height); // _maskReady = true; //} //// ////painter.DestBitmapBlender.OutputPixelBlender = maskPixelBlender; //change to new blender //painter.DestBitmapBlender.OutputPixelBlender = maskPixelBlenderPerCompo; //change to new blender ////4. //painter.FillColor = Color.Black; ////this test lcd-effect => we need to draw it 3 times with different color component, on the same position ////(same as we do with OpenGLES rendering surface) //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.B; //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.B; //painter.FillRect(0, 0, 200, 100); //// //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.G; //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.G; //painter.FillRect(0, 0, 200, 100); //// //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.R; //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.R; //painter.FillRect(0, 0, 200, 100); }
public FontAtlasTextPrinter(AggPainter painter) { StartDrawOnLeftTop = true; _painter = painter; this.PositionTechnique = PositionTechnique.OpenFont; _textServices = new LayoutFarm.OpenFontTextService(); //2. _bmpFontMx = new BitmapFontManager <MemBitmap>( _textServices, atlas => { GlyphImage totalGlyphImg = atlas.TotalGlyph; if (atlas.UseSharedGlyphImage) { if (!_sharedGlyphImgs.TryGetValue(totalGlyphImg, out MemBitmap found)) { found = MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer()); _sharedGlyphImgs.Add(totalGlyphImg, found); } return(found); } else { return(MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer())); } } ); //3. ChangeFont(painter.CurrentFont); SetupMaskPixelBlender(painter.Width, painter.Height); }
public FontAtlasTextPrinter(AggPainter painter) { StartDrawOnLeftTop = true; _painter = painter; this.PositionTechnique = PositionTechnique.OpenFont; _textServices = new LayoutFarm.OpenFontTextService(); //2. create manager _bmpFontMx = new BitmapFontManager <MemBitmap>( TextureKind.StencilLcdEffect, _textServices, atlas => { GlyphImage totalGlyphImg = atlas.TotalGlyph; return(MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer())); } ); //3. ChangeFont(new RequestFont("tahoma", 10)); SetupMaskPixelBlender(painter.Width, painter.Height); }
public CpuBlitTextSpanPrinter(GLPainter canvasPainter, int w, int h) { //this class print long text into agg canvas //then copy pixel buffer from aff canvas to gl-bmp //then draw the gl-bmp into target gl canvas //TODO: review here _canvasPainter = canvasPainter; _pcx = canvasPainter.Canvas; _bmpWidth = w; _bmpHeight = h; _memBmp = new MemBitmap(_bmpWidth, _bmpHeight); #if DEBUG _memBmp._dbugNote = "AggTextSpanPrinter.ctor"; #endif _aggPainter = AggPainter.Create(_memBmp); _aggPainter.FillColor = Color.Black; _aggPainter.StrokeColor = Color.Black; //set default1 _aggPainter.CurrentFont = canvasPainter.CurrentFont; _openFontTextServices = new LayoutFarm.OpenFontTextService(); _vxsTextPrinter = new VxsTextPrinter(_aggPainter, _openFontTextServices); _aggPainter.TextPrinter = _vxsTextPrinter; }
void SetupMaskPixelBlender(int width, int height) { //---------- //same size _alphaBitmap = new MemBitmap(width, height); var alphaPainter = AggPainter.Create(_alphaBitmap, new PixelBlenderBGRA()); alphaPainter.Clear(Color.Black); //------------ System.Random randGenerator = new Random(1432); int i; int num = (int)_maskAlphaSliderValue; num = 50; int elliseFlattenStep = 64; using (VxsTemp.Borrow(out var v1)) using (VectorToolBox.Borrow(out Ellipse ellipseForMask)) { for (i = 0; i < num; i++) { if (i == num - 1) { ////for the last one ellipseForMask.Set(Width / 2, (Height / 2) - 90, 110, 110, elliseFlattenStep); ellipseForMask.MakeVxs(v1); alphaPainter.FillColor = new Color(255, 255, 255, 0); alphaPainter.Fill(v1); v1.Clear(); // ellipseForMask.Set(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, elliseFlattenStep); ellipseForMask.MakeVxs(v1); alphaPainter.FillColor = new Color(255, 255, 0, 0); alphaPainter.Fill(v1); v1.Clear(); // } else { ellipseForMask.Set(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 100 + 20, randGenerator.Next() % 100 + 20, elliseFlattenStep); ellipseForMask.MakeVxs(v1); alphaPainter.FillColor = new Color(100, 255, 0, 0); alphaPainter.Fill(v1); v1.Clear(); } } } maskPixelBlender.SetMaskBitmap(_alphaBitmap); maskPixelBlenderPerCompo.SetMaskBitmap(_alphaBitmap); }
private void Form1_Load(object sender, EventArgs e) { if (DesignMode) { return; } // _basicOptions = basicFontOptionsUserControl1.Options; _basicOptions.TypefaceChanged += (s, e2) => { if (_devVxsTextPrinter != null) { _devVxsTextPrinter.Typeface = e2.SelectedTypeface; } }; _basicOptions.UpdateRenderOutput += (s, e2) => { UpdateRenderOutput(); }; // //---------- _renderOptions = glyphRenderOptionsUserControl1.Options; _renderOptions.UpdateRenderOutput += (s, e2) => { UpdateRenderOutput(); }; //share text printer to our sample textbox //but you can create another text printer that specific to text textbox control destImg = new MemBitmap(800, 600); aggsx = new AggRenderSurface(); aggsx.AttachDstBitmap(destImg); painter = new AggPainter(aggsx); winBmp = new Bitmap(destImg.Width, destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); g = this.sampleTextBox1.CreateGraphics(); painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14); _openFontTextService = new PixelFarm.Drawing.OpenFontTextService(); //.... _devVxsTextPrinter = new PixelFarm.Drawing.VxsTextPrinter(painter, _openFontTextService); _devVxsTextPrinter.ScriptLang = _basicOptions.ScriptLang; _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont; _devVxsTextPrinter.FontSizeInPoints = 10; _controllerForPixelFarm.BindHostGraphics(g); _controllerForPixelFarm.TextPrinter = _devVxsTextPrinter; this.sampleTextBox1.SetController(_controllerForPixelFarm); _readyToRender = true; _basicOptions.UpdateRenderOutput += (s, e2) => UpdateRenderOutput(); //.... //---------- //txtInputChar.TextChanged += (s, e2) => UpdateRenderOutput(); //---------- }
public void DrawString(AggPainter painter, char[] buffer, int startAt, int len, double x, double y) { if (!_fontAtlasPrinterReady) { SetupFontAtlasPrinter(painter); } _printer.DrawString(buffer, startAt, len, (float)x, (float)y); }
public MiniAggCanvasRenderElement(int width, int height) : base(width, height) { _memBmp = new MemBitmap(width, height); #if DEBUG _memBmp._dbugNote = "MiniAggCanvasRenderElement"; #endif _painter = AggPainter.Create(_memBmp); _needUpdate = true; this.BackColor = Color.White; }
void SetupMaskPixelBlender(int width, int height) { //---------- //same size _alphaBmp = new MemBitmap(width, height); _maskBufferPainter = AggPainter.Create(_alphaBmp, new PixelBlenderBGRA()); _maskBufferPainter.Clear(Color.Black); //------------ //draw glyph bmp to _alpha bmp //_maskBufferPainter.DrawImage(_glyphBmp, 0, 0); _maskPixelBlender.SetMaskBitmap(_alphaBmp); _maskPixelBlenderPerCompo.SetMaskBitmap(_alphaBmp); }
public override void Draw(Painter p) { AggPainter painter = p as AggPainter; if (painter == null) { return; } // painter.Clear(Color.White); int width = painter.Width; int height = painter.Height; //change value *** if (_isMaskSliderValueChanged) { SetupMaskPixelBlender(width, height); _isMaskSliderValueChanged = false; // //painter.DestBitmapBlender.OutputPixelBlender = maskPixelBlender; //change to new blender painter.DestBitmapBlender.OutputPixelBlender = maskPixelBlenderPerCompo; //change to new blender } //1. alpha mask... //p2.DrawImage(alphaBitmap, 0, 0); //2. painter.FillColor = Color.Black; painter.FillRect(0, 0, 200, 100); //3. painter.FillColor = Color.Blue; painter.FillCircle(300, 300, 100); painter.DrawImage(lionImg, 20, 20); ////4. //painter.FillColor = Color.Black; ////this test lcd-effect => we need to draw it 3 times with different color component, on the same position ////(same as we do with OpenGLES rendering surface) //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.B; //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.B; //painter.FillRect(0, 0, 200, 100); //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.G; //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.G; //painter.FillRect(0, 0, 200, 100); //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.R; //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.R; //painter.FillRect(0, 0, 200, 100); }
public void BindHostGraphics(Graphics hostControlGraphics) { g = hostControlGraphics; // destImg = new ActualImage(400, 300, PixelFormat.ARGB32); aggsx = new AggRenderSurface(destImg); //no platform p = new AggPainter(aggsx); winBmp = new Bitmap(400, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb); _printer = new VxsTextPrinter(p, null); _visualLine = new VisualLine(); _visualLine.BindLine(_line); _visualLine.Y = 100; }
public void BindHostGraphics(Graphics hostControlGraphics) { g = hostControlGraphics; // destImg = new ActualBitmap(400, 300); p = AggPainter.Create(destImg); winBmp = new Bitmap(400, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb); _openFontTextServices = new LayoutFarm.OpenFontTextService(); _printer = new VxsTextPrinter(p, _openFontTextServices); _visualLine = new VisualLine(); _visualLine.BindLine(_line); _visualLine.Y = 100; }
public override void Paint(PaintVisitor p) { if (Vxs != null) { //1. //convert vxs to bitmap //then render with bitmap cache** //or //2. convert vxs to path data if (backimg == null) { var svgPart = new SvgPart(SvgRenderVxKind.Path); svgPart.FillColor = fillColor; svgPart.SetVxsAsOriginal(Vxs); var svgVx = new SvgRenderVx(new SvgPart[] { svgPart }); if (svgVx != null && !svgVx.HasBitmapSnapshot) { var bounds = svgVx.GetBounds(); //create backimg = new ActualBitmap((int)bounds.Width, (int)bounds.Height); AggRenderSurface renderSurface = new AggRenderSurface(backimg); AggPainter painter = new AggPainter(renderSurface); svgVx.Render(painter); svgVx.SetBitmapSnapshot(backimg); //*** } } if (backimg != null) { p.InnerCanvas.DrawImage(backimg, new RectangleF(0, 0, backimg.Width, backimg.Height)); return; } } if (fillColor.A > 0) { p.FillPath(this.myCachedPath, this.fillColor); } if (this.strokeColor.A > 0) { p.DrawPath(this.myCachedPath, this.strokeColor, this.ActualStrokeWidth); } }
//---------------------------------------------- /// <summary> /// set-up CpuBlit(software-rendering surface) /// </summary> protected virtual void SetupCpuBlitRenderSurface() { //*** _memBmp = new MemBitmap(_width, _height); #if DEBUG _memBmp._dbugNote = "CpuBlitGLESUIElement.SetupCpuBlitRenderSurface()"; #endif _aggPainter = AggPainter.Create(_memBmp); //optional if we want to print text on agg surface _aggPainter.CurrentFont = new PixelFarm.Drawing.RequestFont("Tahoma", 10); _aggPainter.TextPrinter = new PixelFarm.Drawing.Fonts.FontAtlasTextPrinter(_aggPainter); _memBitmapBinder = new MemBitmapBinder(_memBmp, false); // }
//---------------------------------------------- /// <summary> /// set-up CpuBlit(software-rendering surface) /// </summary> protected virtual void SetupCpuBlitRenderSurface() { //*** _memBmp = new MemBitmap(_width, _height); #if DEBUG _memBmp._dbugNote = "CpuBlitGLESUIElement.SetupCpuBlitRenderSurface()"; #endif _aggPainter = AggPainter.Create(_memBmp); //optional if we want to print text on agg surface _aggPainter.CurrentFont = MyFontSettings.DefaultRootGraphicsFont;// _aggPainter.TextPrinter = new PixelFarm.CpuBlit.BitmapAtlas.FontAtlasTextPrinter(_aggPainter); _memBitmapBinder = new MemBitmapBinder(_memBmp, false); // }
protected override void OnReadyForInitGLShaderProgram() { lionShape = new SpriteShape(); lionShape.ParseLion(); RectD lionBounds = lionShape.Bounds; //------------- aggImage = new ActualImage((int)lionBounds.Width, (int)lionBounds.Height, PixelFarm.Agg.PixelFormat.ARGB32); _aggsx = new AggRenderSurface(aggImage); aggPainter = new AggPainter(_aggsx); DrawLion(aggPainter, lionShape, lionShape.Vxs); //convert affImage to texture glBmp = DemoHelper.LoadTexture(aggImage); }
protected override void OnReadyForInitGLShaderProgram() { PaintLab.Svg.VgVisualDoc vgVisualDoc = PaintLab.Svg.VgVisualDocHelper.CreateVgVisualDocFromFile("Samples/lion.svg"); _lionShape = new SpriteShape(vgVisualDoc.VgRootElem); var lionBounds = _lionShape.Bounds; //------------- _memBmp = new MemBitmap((int)lionBounds.Width, (int)lionBounds.Height); _aggPainter = AggPainter.Create(_memBmp); DrawLion(_aggPainter, _lionShape); //convert affImage to texture _glBmp = DemoHelper.LoadTexture(_memBmp); }
public override void Draw(Painter p) { AggPainter painter = p as AggPainter; if (painter == null) { return; } painter.Clear(Color.White); switch (FilterName) { case FilterName.Unknown: painter.RenderSurface.CustomImgSpanGen = null; break; case FilterName.NearestNeighbor: painter.RenderSurface.CustomImgSpanGen = _imgSpanGenNN; break; default: DrawWeightDistributionGraph(p, _lut.WeightArray); painter.RenderSurface.CustomImgSpanGen = _imgSpanGenCustom; break; } VertexProcessing.AffinePlan[] p1 = new VertexProcessing.AffinePlan[] { VertexProcessing.AffinePlan.Translate(-_imgW / 2.0, -_imgH / 2.0), VertexProcessing.AffinePlan.RotateDeg(_rotationDeg), VertexProcessing.AffinePlan.Translate(_imgW / 2.0, _imgH / 2.0), }; p.DrawImage(_orgImg, p1); if (_thumbnailScaleDown > 0 && _thumbnailScaleDown < 1) { using (MemBitmap thumbnail = _orgImg.CreateThumbnailWithSuperSamplingTechnique(_thumbnailScaleDown)) { painter.DrawImage(thumbnail, 400, 300); } } base.Draw(p); }
public FloodFillDemo() { // _magicWandConfigs = new MagicWandConfigGroup(); BackgroundColor = Color.White; _defaultImg = new MemBitmap(400, 300); AggPainter p = AggPainter.Create(_defaultImg); p.Clear(Color.White); p.FillColor = Color.Black; p.FillEllipse(20, 20, 30, 30); for (int i = 0; i < 20; i++) { p.StrokeColor = Color.Black; p.DrawEllipse(i * 10, i * 10, 20, 20); } // this.PixelSize = 32; this.Gamma = 1; _tolerance = 30; _floodFill = new ColorBucket(Color.Red, _tolerance); _magicWand = new MagicWand(_tolerance); // //_lionPng = MemBitmapExtensions.LoadBitmap("../Data/lion1_v2_2.png"); //_lionPng = MemBitmapExtensions.LoadBitmap("../Data/lion1_v2_4_1.png"); _lionPng = MemBitmapExt.LoadBitmap("../Data/lion1.png"); //_lionPng = MemBitmapExtensions.LoadBitmap("../Data/lion_1_v3_2.png"); //_lionPng = MemBitmapExtensions.LoadBitmap("../Data/glyph_a.png"); _starsPng = MemBitmapExt.LoadBitmap("../Data/stars.png"); _test_glyphs = MemBitmapExt.LoadBitmap("../Data/test_glyphs.png"); _rect01 = MemBitmapExt.LoadBitmap("../Data/rect01.png"); //_v_shape = MemBitmapExtensions.LoadBitmap("../Data/shape_v.png"); //_v_shape = MemBitmapExtensions.LoadBitmap("../Data/shape_v3.png"); _bmpToFillOn = _defaultImg; OutlineReconstruction = true; WithOutlineSimplifier = true; }
public override void Draw(Painter p) { //this specific for agg #if DEBUG //low-level scanline rasterizer example if (p is AggPainter) { AggPainter p2 = (AggPainter)p; AggRenderSurface aggsx = p2.RenderSurface; PixelProcessing.SubBitmapBlender subImg = PixelProcessing.BitmapBlenderExtension.CreateSubBitmapBlender(aggsx.DestBitmapBlender, aggsx.GetClippingRect()); //TODO: review here again PixelBlenderBGRA blenderWithGamma = new PixelProcessing.PixelBlenderBGRA(); SubBitmapBlender rasterGamma = new SubBitmapBlender(subImg, blenderWithGamma); ClipProxyImage clippingProxyNormal = new ClipProxyImage(subImg); ClipProxyImage clippingProxyGamma = new ClipProxyImage(rasterGamma); clippingProxyNormal.Clear(Color.White); ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer; var sl = new ScanlineUnpacked8(); int size_mul = this.PixelSize; var sclineToBmpEn2 = new CustomRas_EnlargeV2(size_mul, aggsx.DestBitmap); rasterizer.Reset(); rasterizer.dbugDevMoveTo(_x[0] / size_mul, _y[0] / size_mul); rasterizer.dbugDevLineTo(_x[1] / size_mul, _y[1] / size_mul); rasterizer.dbugDevLineTo(_x[2] / size_mul, _y[2] / size_mul); sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); DestBitmapRasterizer bmpRas = aggsx.BitmapRasterizer; bmpRas.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); //----------------------------------------------------------------------------------------------------------- rasterizer.ResetGamma(new GammaNone()); using (Tools.BorrowVxs(out var v1, out var v2)) using (Tools.BorrowPathWriter(v1, out PathWriter ps)) { ps.Clear(); ps.MoveTo(_x[0], _y[0]); ps.LineTo(_x[1], _y[1]); ps.LineTo(_x[2], _y[2]); ps.LineTo(_x[0], _y[0]); rasterizer.AddPath((new Stroke(2)).MakeVxs(v1, v2)); bmpRas.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160)); } } #endif }
void RenderGrids(int width, int height, int sqSize, AggPainter 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 FontAtlasTextPrinter(AggPainter painter) { _painter = painter; this.PositionTechnique = PositionTechnique.OpenFont; _textServices = new OpenFontTextService(); //2. _bmpFontMx = new BitmapFontManager <MemBitmap>( _textServices, atlas => atlas.MainBitmap ); //3. ChangeFont(painter.CurrentFont); SetupMaskPixelBlender(painter.Width, painter.Height); }
protected override void OnReadyForInitGLShaderProgram() { var _svgRenderVx = PixelFarm.Agg.SvgRenderVxLoader.CreateSvgRenderVxFromFile("Samples/lion.svg"); lionShape = new SpriteShape(_svgRenderVx); RectD lionBounds = lionShape.Bounds; //------------- aggImage = new ActualImage((int)lionBounds.Width, (int)lionBounds.Height); _aggsx = new AggRenderSurface(aggImage); aggPainter = new AggPainter(_aggsx); DrawLion(aggPainter, lionShape); //convert affImage to texture glBmp = DemoHelper.LoadTexture(aggImage); }
public override void Draw(Painter p) { AggPainter painter = p as AggPainter; if (painter == null) { return; } // painter.Clear(Color.White); int width = painter.Width; int height = painter.Height; //change value *** if (!_maskReady) { SetupMaskPixelBlender(width, height); _maskReady = true; } // //painter.DestBitmapBlender.OutputPixelBlender = maskPixelBlender; //change to new blender painter.DestBitmapBlender.OutputPixelBlender = _maskPixelBlenderPerCompo; //change to new blender //4. painter.FillColor = Color.Black; //this test lcd-effect => we need to draw it 3 times with different color component, on the same position //(same as we do with OpenGLES rendering surface) _maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.B; _maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.B; painter.FillRect(0, 0, 200, 100); // _maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.G; _maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.G; painter.FillRect(0, 0, 200, 100); // _maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.R; _maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.R; painter.FillRect(0, 0, 200, 100); }
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(Painter p) { //this specific for agg if (p is AggPainter) { AggPainter p2 = (AggPainter)p; AggRenderSurface aggsx = p2.RenderSurface; SubImageRW subImg = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect()); //TODO: review here again PixelBlenderBGRA blenderWithGamma = new PixelBlenderBGRA(); SubImageRW rasterGamma = new SubImageRW(subImg, blenderWithGamma); ClipProxyImage clippingProxyNormal = new ClipProxyImage(subImg); ClipProxyImage clippingProxyGamma = new ClipProxyImage(rasterGamma); clippingProxyNormal.Clear(Color.White); ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer; var sl = new ScanlineUnpacked8(); int size_mul = this.PixelSize; var sclineToBmpEn2 = new CustomScanlineRasToBmp_EnlargedV2(size_mul, aggsx.DestActualImage); rasterizer.Reset(); rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul); rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul); rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul); sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); ScanlineRasToDestBitmapRenderer sclineRasToBmp = aggsx.ScanlineRasToDestBitmap; sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); //----------------------------------------------------------------------------------------------------------- rasterizer.ResetGamma(new GammaNone()); PathWriter ps = new PathWriter(); ps.Clear(); ps.MoveTo(m_x[0], m_y[0]); ps.LineTo(m_x[1], m_y[1]); ps.LineTo(m_x[2], m_y[2]); ps.LineTo(m_x[0], m_y[0]); VectorToolBox.GetFreeVxs(out var v1); rasterizer.AddPath((new Stroke(2)).MakeVxs(ps.Vxs, v1)); sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160)); VectorToolBox.ReleaseVxs(ref v1); } }
void DrawC(Painter p) { AggPainter aggPainter = p as AggPainter; if (aggPainter == null) { return; //temp } p.Clear(PixelFarm.Drawing.Color.White); //-------------------------- p.StrokeColor = PixelFarm.Drawing.Color.Black; p.StrokeWidth = 2.0f; if (_lineDashGen == null) { //create line dash gen _lineDashGen = new LineDashGenerator(); _lineDashGen.SetDashPattern(4, 2, 2, 2); } aggPainter.LineDashGen = _lineDashGen; // using (VxsTemp.Borrow(out var vxs)) using (VectorToolBox.Borrow(vxs, out PathWriter writer)) { // //writer.MoveTo(20, 10); //writer.LineTo(60, 10); //writer.LineTo(20, 200); //writer.LineTo(20, 0); writer.MoveTo(20, 10); writer.LineTo(60, 10); writer.LineTo(20, 200); writer.CloseFigure(); p.Draw(vxs); } //writer.MoveTo(20, 100); //writer.LineTo(20, 15); //writer.CloseFigure(); aggPainter.LineDashGen = null; }
public CpuBlitAggCanvasRenderElement(RootGraphic rootgfx, int w, int h) : base(rootgfx, w, h) { //TODO: check if we can access raw rootGraphics buffer or not //1. gdi+ create backbuffer _nativeWin32DC = new Win32.NativeWin32MemoryDC(w, h); //2. create actual bitmap that share bitmap data from native _nativeWin32Dc _memBmp = new MemBitmap(w, h, _nativeWin32DC.PPVBits); //---------------------------------------------------------------- //3. create render surface from bitmap => provide basic bitmap fill operations AggRenderSurface aggsx = new AggRenderSurface(); aggsx.AttachDstBitmap(_memBmp); //4. painter wraps the render surface => provide advance operations AggPainter aggPainter = new AggPainter(aggsx); aggPainter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14); _painter = aggPainter; //---------------------------------------------------------------- }