Autodesk.Revit.DB.BackgroundImageFit class is used to specify how an image should be fitted to a specified region within a Revit view. It is defined in the Autodesk.Revit.DB namespace.
FitType
- This property is of type BackgroundImageFitType and gets or sets the type of fit to be applied to the image. The available options are:
OffsetX
- This property is of type double and gets or sets the horizontal offset of the image within the specified region. A positive value moves the image to the right, and a negative value moves it to the left.
OffsetY
- This property is of type double and gets or sets the vertical offset of the image within the specified region. A positive value moves the image downwards, and a negative value moves it upwards.
ScaleX
- This property is of type double and gets or sets the horizontal scale factor of the image. A value of 1.0 indicates no scaling. A value greater than 1.0 scales the image up, and a value less than 1.0 scales it down.
ScaleY
- This property is of type double and gets or sets the vertical scale factor of the image. A value of 1.0 indicates no scaling. A value greater than 1.0 scales the image up, and a value less than 1.0 scales it down.
The following code example demonstrates how to use BackgroundImageFit class to fit the specified image to a Revit view.
BackgroundImageFit fit = new BackgroundImageFit();
fit.FitType = BackgroundImageFitType.Fit;
fit.ScaleX = 2.0;
fit.ScaleY = 2.0;
fit.OffsetX = 10.0;
fit.OffsetY = -10.0;
View view = doc.ActiveView;
view.SetBackgroundImage(@"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg", fit);
In this example, we create a new BackgroundImageFit object and set its FitType to Fit. We then set the ScaleX and ScaleY properties to 2.0 to scale the image up, and the OffsetX and OffsetY properties to position the image within the view. Finally, we set the background image of the active view using the SetBackgroundImage method, passing the path to the image file and the BackgroundImageFit object as parameters.