public FloodFillDemo() { BackgroundColor = RGBA_Bytes.White; imageToFillOn = new ImageBuffer(400, 300, 32, new BlenderBGRA()); Graphics2D imageToFillGraphics = imageToFillOn.NewGraphics2D(); imageToFillGraphics.Clear(RGBA_Bytes.White); imageToFillGraphics.DrawString("Click to fill", 20, 30); imageToFillGraphics.Circle(new Vector2(200, 150), 35, RGBA_Bytes.Black); imageToFillGraphics.Circle(new Vector2(200, 150), 30, RGBA_Bytes.Green); imageToFillGraphics.Rectangle(20, 50, 210, 280, RGBA_Bytes.Black); imageToFillGraphics.Rectangle(imageToFillOn.GetBounds(), RGBA_Bytes.Blue); Random rand = new Random(); for (int i = 0; i < 20; i++) { Ellipse elipse = new Ellipse(rand.Next(imageToFillOn.Width), rand.Next(imageToFillOn.Height), rand.Next(10, 60), rand.Next(10, 60)); Stroke outline = new Stroke(elipse); imageToFillGraphics.Render(outline, RGBA_Bytes.Black); } m_slider1 = new Slider(new Vector2(80, 10), 510); m_slider2 = new Slider(new Vector2(80, 10 + 20), 510); m_slider1.ValueChanged += new EventHandler(NeedsRedraw); m_slider2.ValueChanged += new EventHandler(NeedsRedraw); AddChild(m_slider1); AddChild(m_slider2); m_slider1.Text = "Pixel size={0:F3}"; m_slider1.SetRange(8, 100); m_slider1.NumTicks = 23; m_slider1.Value = 32; m_slider2.Text = "gamma={0:F3}"; m_slider2.SetRange(0.0, 3.0); m_slider2.Value = 1.0; }
public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); IImageByte backBuffer = widgetsSubImage; if (firstTime) { firstTime = false; m_SuperFast = new MatterHackers.Agg.UI.CheckBox(10, 10, "Run Super Fast"); AddChild(m_SuperFast); m_Controller = new CController(backBuffer, 30, 40, .1, .7, .3, 4, 1, 2000); } graphics2D.Clear(new RGBA_Floats(1, 1, 1, 1)); graphics2D.Rasterizer.SetVectorClipBox(0, 0, (int)Width, (int)Height); m_Controller.FastRender(m_SuperFast.Checked); m_Controller.Render(graphics2D); //m_SuperFast.Render(graphics2D); base.OnDraw(graphics2D); }
private void Initialize(ImageBuffer sourceImage, RectangleInt boundsToCopyFrom) { if (sourceImage == this) { throw new Exception("We do not create a temp buffer for this to work. You must have a source distinct from the dest."); } Deallocate(); Allocate(boundsToCopyFrom.Width, boundsToCopyFrom.Height, boundsToCopyFrom.Width * sourceImage.BitDepth / 8, sourceImage.BitDepth); SetRecieveBlender(sourceImage.GetRecieveBlender()); if (width != 0 && height != 0) { RectangleInt DestRect = new RectangleInt(0, 0, boundsToCopyFrom.Width, boundsToCopyFrom.Height); RectangleInt AbsoluteSourceRect = boundsToCopyFrom; // The first thing we need to do is make sure the frame is cleared. LBB [3/15/2004] MatterHackers.Agg.Graphics2D graphics2D = NewGraphics2D(); graphics2D.Clear(new RGBA_Bytes(0, 0, 0, 0)); int x = -boundsToCopyFrom.Left - (int)sourceImage.OriginOffset.x; int y = -boundsToCopyFrom.Bottom - (int)sourceImage.OriginOffset.y; graphics2D.Render(sourceImage, x, y, 0, 1, 1); } }
private double PrintTopOfPage(ImageBuffer plateInventoryImage, Graphics2D plateGraphics) { plateGraphics.Clear(RGBA_Bytes.White); double currentlyPrintingHeightPixels = plateInventoryImage.Height - PageMarginMM.Top * PixelPerMM; string logoPathAndFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "PartSheetLogo.png"); if(File.Exists(logoPathAndFile)) { ImageBuffer logoImage = new ImageBuffer(); ImageIO.LoadImageData(logoPathAndFile, logoImage); currentlyPrintingHeightPixels -= logoImage.Height; plateGraphics.Render(logoImage, (plateInventoryImage.Width - logoImage.Width) / 2, currentlyPrintingHeightPixels); } currentlyPrintingHeightPixels -= PartPaddingPixels; double underlineHeightMM = 1; RectangleDouble lineBounds = new RectangleDouble(0, 0, plateInventoryImage.Width - PageMarginPixels.Left * 2, underlineHeightMM * PixelPerMM); lineBounds.Offset(PageMarginPixels.Left, currentlyPrintingHeightPixels - lineBounds.Height); plateGraphics.FillRectangle(lineBounds, RGBA_Bytes.Black); return currentlyPrintingHeightPixels - (lineBounds.Height + PartPaddingPixels); }
public override void OnDraw(Graphics2D graphics2D) { graphics2D.Clear(RGBA_Bytes.White); base.OnDraw(graphics2D); }
public static void Main(string[] args) { // first we will show how to use the simple drawing functions in graphics 2D { ImageBuffer simpleImage = new ImageBuffer(640, 480, 32, new BlenderBGRA()); Graphics2D simpleImageGraphics2D = simpleImage.NewGraphics2D(); // clear the image to white simpleImageGraphics2D.Clear(Color.White); // draw a circle simpleImageGraphics2D.Circle(50, 50, 30, Color.Blue); // draw a line simpleImageGraphics2D.Line(10, 100, 520, 50, new Color(20, 200, 200)); // draw a filled box simpleImageGraphics2D.FillRectangle(60, 260, 200, 280, Color.Yellow); // and an outline around it simpleImageGraphics2D.Rectangle(60, 260, 200, 280, Color.Magenta); // draw some text simpleImageGraphics2D.DrawString("A Simple Example", 300, 400, 20); // and save this image out ImageTgaIO.Save(simpleImage, "SimpleDrawAndSave.tga"); } // now we will we will show how to use the render function to draw more complex things { ImageBuffer lessSimpleImage = new ImageBuffer(640, 480, 32, new BlenderBGRA()); Graphics2D lessSimpleImageGraphics2D = lessSimpleImage.NewGraphics2D(); // clear the image to white lessSimpleImageGraphics2D.Clear(Color.White); // draw a circle Ellipse ellipseTest = new Ellipse(0, 0, 100, 50); for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5) { VertexSourceApplyTransform rotatedTransform = new VertexSourceApplyTransform(ellipseTest, Affine.NewRotation(MathHelper.DegreesToRadians(angleDegrees))); VertexSourceApplyTransform rotatedAndTranslatedTransform = new VertexSourceApplyTransform(rotatedTransform, Affine.NewTranslation(lessSimpleImage.Width / 2, 150)); lessSimpleImageGraphics2D.Render(rotatedAndTranslatedTransform, Color.Yellow); Stroke ellipseOutline = new Stroke(rotatedAndTranslatedTransform, 3); lessSimpleImageGraphics2D.Render(ellipseOutline, Color.Blue); } // and a little polygon VertexStorage littlePoly = new VertexStorage(); littlePoly.MoveTo(50, 50); littlePoly.LineTo(150, 50); littlePoly.LineTo(200, 200); littlePoly.LineTo(50, 150); littlePoly.LineTo(50, 50); lessSimpleImageGraphics2D.Render(littlePoly, Color.Cyan); // draw some text TypeFacePrinter textPrinter = new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center); IVertexSource translatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewTranslation(new Vector2(lessSimpleImage.Width / 2, lessSimpleImage.Height / 4 * 3))); lessSimpleImageGraphics2D.Render(translatedText, Color.Red); Stroke strokedText = new Stroke(translatedText); lessSimpleImageGraphics2D.Render(strokedText, Color.Black); IVertexSource rotatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewRotation(MathHelper.DegreesToRadians(90))); IVertexSource rotatedTranslatedText = new VertexSourceApplyTransform(rotatedText, Affine.NewTranslation(new Vector2(40, lessSimpleImage.Height / 2))); lessSimpleImageGraphics2D.Render(rotatedTranslatedText, Color.Black); // and save this image out ImageTgaIO.Save(lessSimpleImage, "LessSimpleDrawAndSave.tga"); } }
public override void OnDraw(Graphics2D graphics2D) { graphics2D.Clear(Color.White); base.OnDraw(graphics2D); }
public override void OnDraw(Graphics2D graphics2D) { CameraCalibrationWidget_OnDraw.Start(); graphics2D.Clear(RGBA_Bytes.White); rect_d rect = new rect_d(Width - 40, 10, Width - 10, 40); graphics2D.Rectangle(rect, RGBA_Bytes.Black); Invalidate(rect); base.OnDraw(graphics2D); CameraCalibrationWidget_OnDraw.Stop(); }
private double PrintTopOfPage(ImageBuffer plateInventoryImage, Graphics2D plateGraphics) { plateGraphics.Clear(RGBA_Bytes.White); double currentlyPrintingHeightPixels = plateInventoryImage.Height - PageMarginMM.Top * PixelPerMM; // TODO: Application should not save data back to StaticDataPath - use application data dir instead string logoPathAndFile = "PartSheetLogo.png"; if (StaticData.Instance.FileExists(logoPathAndFile)) { ImageBuffer logoImage = StaticData.Instance.LoadImage(logoPathAndFile); currentlyPrintingHeightPixels -= logoImage.Height; plateGraphics.Render(logoImage, (plateInventoryImage.Width - logoImage.Width) / 2, currentlyPrintingHeightPixels); } currentlyPrintingHeightPixels -= PartPaddingPixels; double underlineHeightMM = 1; RectangleDouble lineBounds = new RectangleDouble(0, 0, plateInventoryImage.Width - PageMarginPixels.Left * 2, underlineHeightMM * PixelPerMM); lineBounds.Offset(PageMarginPixels.Left, currentlyPrintingHeightPixels - lineBounds.Height); plateGraphics.FillRectangle(lineBounds, RGBA_Bytes.Black); return currentlyPrintingHeightPixels - (lineBounds.Height + PartPaddingPixels); }
public override void OnDraw(Graphics2D graphics2D) { MatterCadWidget_OnDraw.Start(); graphics2D.Clear(RGBA_Bytes.White); rect_d rect = new rect_d(Width - 40, 10, Width - 10, 40); graphics2D.FillRectangle(rect, previewWindowRayTrace.mouseOverColor); graphics2D.Rectangle(rect, RGBA_Bytes.Black); Invalidate(rect); base.OnDraw(graphics2D); MatterCadWidget_OnDraw.Stop(); }