This documentation is for the old version. Go to the latest Graphics Mill docs

Using V-objects With the BitmapViewer Control

This topic describes how to use v-objects with the BitmapViewer control.

If you are going to use v-objects with BitmapViewer, please, keep in mind that in case of extensive use of the Vector Objects features it is recommended to use MultiLayerViewer instead. MultiLayerViewer was specifically designed and optimized for Vector Objects, for example, it provides a caching mechanism (allows to handle a large number of v-objects without a performance drop). Use the BitmapViewer control only when just a few v-objects are required.

Enabling Use of V-Objects

Suppose, you have an application that uses the BitmapViewer control, and you want to add vector drawing functionality to it (for more details on creating applications that use the BitmapViewer control, see the Quick Start in Windows Forms topic). To do that, you will need to associate a special rubberband with this control. A rubberband of type VObjectsRubberband should be assigned to the Rubberband property of the BitmapViewer instance. To do that, drag the VObjectsRubberband item from the Toolbox to your form, and in the form properties, select the newly created VObjectsRubberband instance from the menu of the Rubberband property. If you are not quite familiar with rubberbands, you can read more about them in the Using Navigators and Rubberbands (Windows Forms) topic.

The VObjectsRubberband class implements the IVObjectHost interface; the same interface is implemented by the MultiLayerViewer class. That is why the functionality provided by VObjectsRubberband is almost the same as the functionality of MultiLayerViewer. You can work with layers and manipulate objects just as you do it using the MultiLayerViewer control. A more detailed description of working with objects and layers is provided in the topics Basic Concepts of Vector Objects and How to Use Vector Objects.

Rendering the Bitmap with V-objects

After you have added, configured and organized vector objects, you need to save them as part of the bitmap. The bitmap cannot contain multiple layers, so the multi-layered image should be flattened. To do that, you will need to call the VObjectsRubberband.RenderWorkspace method of the rubberband instance. This method renders the added vector objects on a transparent bitmap and returns it. After calling this method you can flatten the returned bitmap and the original one using the Bitmap.Draw method.

Below is an example of adding the VObjectsRubberband object, drawing a rectangle and saving the resulting bitmap.

Visual Basic
'Load the bitmap
BitmapViewer1.Bitmap.Load("D:\image.jpg")

'Create a rectangle object
Dim rectangle As New Aurigma.GraphicsMill.WinControls.RectangleVObject(0.0F, _
        0.0F, 15.0F, 15.0F)

'Modify stroke and fill parameters
rectangle.Pen = New System.Drawing.Pen(System.Drawing.Color.BlanchedAlmond, _
    10.0F)
rectangle.Brush = New System.Drawing.SolidBrush(System.Drawing.Color.Wheat)

'Add the rectangle to a layer
VObjectsRubberband1.Layers.Item(0).VObjects.Add(rectangle)

'Render the rectangle to a bitmap
Dim renderedVObjects As Aurigma.GraphicsMill.Bitmap = _
    vObjectsRubberband1.RenderWorkspace()

'Merge the two bitmaps
renderedVObjects.Draw(bitmapViewer1.Bitmap, 0, 0, bitmapViewer1.Bitmap.Width, _
    bitmapViewer1.Bitmap.Height, Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, _
    1.0F, Aurigma.GraphicsMill.Transforms.InterpolationMode.HighSpeed)

'Clear the rubberband workspace
vObjectsRubberband1.Layers(0).VObjects.Clear()
C#
//Load the bitmap
bitmapViewer1.Bitmap.Load(@"D:\image.jpg");

//Create a rectangle object
Aurigma.GraphicsMill.WinControls.RectangleVObject rectangle = new
    Aurigma.GraphicsMill.WinControls.RectangleVObject(0F, 0F, 15F, 15F);

//Modify stroke and fill parameters
rectangle.Pen = new System.Drawing.Pen(System.Drawing.Color.BlanchedAlmond, 5F);
rectangle.Brush = new System.Drawing.SolidBrush(System.Drawing.Color.Wheat);

//Add the rectangle to a layer
vObjectsRubberband1.Layers[0].VObjects.Add(rectangle);

//Render the rectangle to a bitmap
Aurigma.GraphicsMill.Bitmap renderedVObjects =
    vObjectsRubberband1.RenderWorkspace();

//Merge the two bitmaps
renderedVObjects.Draw(bitmapViewer1.Bitmap, 0, 0, bitmapViewer1.Bitmap.Width,
    bitmapViewer1.Bitmap.Height, Aurigma.GraphicsMill.Transforms.CombineMode.Alpha,
    1f, Aurigma.GraphicsMill.Transforms.InterpolationMode.HighSpeed);

//Clear the rubberband workspace
vObjectsRubberband1.Layers[0].VObjects.Clear();

See Also

Reference

Manual