Type Default Value Read Only Static Description
XRect None Yes No The image bounding box.

This property reflects the physical bounds of the image.

It is more relevant for vector graphics files which operate in terms of physical dimensions rather than pixels.

Note that Postscript files may have bounds which are not anchored at the origin.


Here we use the bounding box to put a 2 pixel dark blue frame around an image.

[C#]Canvas canvas = new Canvas();
XImage image = XImage.FromFile(Server.MapPath("rez/main.jpg"));
canvas.Width = image.BoundingBox.Width + 4;
canvas.Height = image.BoundingBox.Height + 4;
DrawOptions drawOpts = new DrawOptions();
drawOpts.ImageFit = DrawOptions.ImageFitType.AspectRatio;
drawOpts.HAlign = 0.5;
drawOpts.VAlign = 0.5;
drawOpts.PenSize = 2;
drawOpts.PenColor = new XColor(Color.DarkBlue);
drawOpts.ShapeDrawing = DrawOptions.ShapeDrawingType.Draw;
canvas.DrawImage(image, drawOpts);
canvas.DrawRect(new XRect(canvas.Width, canvas.Height), drawOpts);

[Visual Basic]Dim canvas As New Canvas()
Dim image As XImage = XImage.FromFile(Server.MapPath("rez/main.jpg"))
canvas.Width = image.BoundingBox.Width + 4
canvas.Height = image.BoundingBox.Height + 4
Dim drawOpts As New DrawOptions()
drawOpts.ImageFit = DrawOptions.ImageFitType.AspectRatio
drawOpts.HAlign = 0.5
drawOpts.VAlign = 0.5
drawOpts.PenSize = 2
drawOpts.PenColor = New XColor(Color.DarkBlue)
drawOpts.ShapeDrawing = DrawOptions.ShapeDrawingType.Draw
canvas.DrawImage(image, drawOpts)
canvas.DrawRect(New XRect(canvas.Width, canvas.Height), drawOpts)