Image Reference Entity (ImageRefEnt)
About 1 min
Image Reference Entity (ImageRefEnt)
ImageRefEnt represents a reference to an external image, inserting a raster image into the CAD drawing.
Overview
Image references allow inserting bitmap images (such as PNG, JPG, etc.) into vector drawings, commonly used for adding reference images, photos, logos, etc.
Constructor
import { ImageRefEnt, Point2D } from 'vjcad';
// Shorthand syntax (recommended)
const image1 = new ImageRefEnt([100, 100], 0, 1); // Insertion point, rotation angle, scale factor
image1.url = '/images/logo.png';
image1.setDefaults();
// Set properties step by step
const image2 = new ImageRefEnt();
image2.url = '/images/logo.png';
image2.insertionPoint = [100, 100]; // Supports array syntax
image2.setDefaults();Shorthand Syntax
Both the constructor and the insertionPoint property support [x, y] array-form coordinates.
Properties
| Property | Type | Description |
|---|---|---|
imagePath | string | Image file path |
insertPoint | Point2D | Insertion point (bottom-left corner) |
width | number | Display width |
height | number | Display height |
rotation | number | Rotation angle (radians) |
brightness | number | Brightness (0-100) |
contrast | number | Contrast (0-100) |
fade | number | Fade (0-100) |
Examples
Insert an Image
import { Engine, ImageRefEnt, Point2D } from 'vjcad';
const image = new ImageRefEnt();
image.imagePath = '/assets/reference.png';
image.insertPoint = new Point2D(0, 0);
image.width = 200;
image.height = 150;
image.setDefaults();
Engine.addEntities(image);Insert a Rotated Image
import { Engine, ImageRefEnt, Point2D } from 'vjcad';
const image = new ImageRefEnt();
image.imagePath = '/assets/photo.jpg';
image.insertPoint = new Point2D(100, 100);
image.width = 100;
image.height = 100;
image.rotation = Math.PI / 6; // 30 degrees
image.setDefaults();
Engine.addEntities(image);Adjust Image Display Effects
import { Engine, ImageRefEnt, Point2D } from 'vjcad';
const image = new ImageRefEnt();
image.imagePath = '/assets/background.png';
image.insertPoint = new Point2D(0, 0);
image.width = 500;
image.height = 400;
image.brightness = 50; // Default brightness
image.contrast = 50; // Default contrast
image.fade = 70; // Fade 70%
image.setDefaults();
Engine.addEntities(image);Notes
- Image path: Can be a relative or absolute path; ensure it is accessible at runtime.
- Image format: Supports common web image formats (PNG, JPG, GIF, WebP).
- Performance: Large images may affect rendering performance; optimize image size when possible.
- Print output: Images may differ between screen display and print output.