70000278 Crop a vdImage into a new Bitmap

Article 70000278
Type Wish
Product Engine
Version 7002
Date Added 1/30/2015
Fixed (1/30/2015)
Submitted by Yannis Makarounis

Summary

Crop a vdImage into a new Bitmap from a passed rectangle in World Coordinate System.

Solution

In version 7003.0.6 the following methods were added that help to crop a vdImage object.
1.PixelToECSMatrix method of vdImage
This method returns a Matrix that tranforms a pixel point relative to selected Bitmap Rectangle, into ECSMatrix of vdImage object.
2.Crop method of ImageBind: Bitmap Crop(Rectangle r)
This method returns a Bitmap that is a portion of the original image defined by passed Rectangle.
r: is the Rectangle portion of this Image.This must be completely inside the rectangle of this Image, or else the method will return null.

Example

//suppose that we want to crop a vdImage (img) using a vdRect (rc) object.
//get a matrix that transforms from vdRect BoundingBox which is in World Coordinate system to Pixel relative to the upperleft corner of Image.
Matrix world2ImagePixel = (img.PixelToECSMatrix() * img.ECSMatrix).GetInvertion();
System.Drawing.Rectangle r = rc.BoundingBox.GetTransformRectangle(world2ImagePixel);
//get the portion of the vdImage from the passed rectangle.
Bitmap bmp = img.ImageDefinition.Image.Crop(r);
if (bmp == null) return;
bmp.Save("d:\\temp\\test.bmp");

Send comments on this topic.