image 图片

4/22/2022

We can create an image in MxDraw by instantiating a Mx.MxDbImage() object.

Click Mx.MxDbImage API (opens new window) to view the detailed implementation specifications.

import Mx from "mxdraw"

 // Instantiate a point object
const getPoint = new Mx.MrxDbgUiPrPoint();

// Mouse click for the first time
getPoint.go((status) => {
    if (status !== Mx.MrxDbgUiPrBaseReturn.kOk) {
        return
    }

    // Current mouse position
    const pt1 = getPoint.value()
    // Instantiate the rectangle object rect
    const image = new Mx.MxDbImage();

    // 60,40 are the width and height of the image, in screen pixels.
    const w = Mx.MxFun.screenCoordLong2Doc(60);
    const h = Mx.MxFun.screenCoordLong2Doc(40);

    
    // Set the location of the points
    image.setPoint1(pt1);
    const pt2 = new THREE.Vector3(pt1.x + w, pt1.y + h, pt1.z);
    image.setPoint2(pt2);

    // Set the image path
    image.setImagePath("../../img/dlyx_icon.png");

    // Get the control object and add the image object to the canvas
    Mx.MxFun.getCurrentDraw().addMxEntity(image);
    
})

Note:

Effect:

  • Click on the canvas to draw an image