Crainiate Community

Support and discussion for users of Crainiate component software products
Welcome to Crainiate Community Sign in | Join | Help
in Search

How to save a portion of a diagram to a bitmap (or jpeg/png/gif etc)

Last post 02-03-2006 1:41 PM by James Westgate. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 02-03-2006 1:41 PM

    How to save a portion of a diagram to a bitmap (or jpeg/png/gif etc)

    You need a bit of insider knowledge on how the Render class works to save a portion of a diagram to disk without disrupting the user experience on the control itself.  The following code saves the first 200 x 200 pixels of a diagram to a bitmap file, and allows you to choose the elements you want rendered.

    RenderList list = new RenderList();  

    //Create render list, add only the shapes you want
    foreach (Shape shape in flowchart1.Shapes.Values)
    {
        list.Add(shape);
    }
    foreach (Line line in flowchart1.Lines.Values)
    {
        list.Add(line);
    }

    //Sort for correct zorder
    list.Sort();

    //Save existing render rectangle
    Rectangle rect = flowchart1.Render.RenderRectangle;

    //Set up renderer for output render
    flowchart1.RenderDesign.DrawGrid = false;
    flowchart1.Render.Elements = list;
    flowchart1.Render.RenderDiagram(new Rectangle(0,0,200,200));
    flowchart1.Render.Bitmap.Save "c:\\test200x200.bmp",System.Drawing.Imaging.ImageFormat.Bmp);

    //Reset render
    flowchart1.RenderDesign.DrawGrid = true;
    flowchart1.Render.RenderDiagram(rect);
    flowchart1.Refresh();


    Change the Imageformat enumeration option if you prefer to create a .jpg, .gif or .png file instead.

    • 213.205.229.207
Page 1 of 1 (1 items)