Skip to content
On this page

Pictures

We can load an external image into the current context by calling the loadImage() method in the mxcad instantiation object, and then call the drawImage() method to draw the target image.

tap loadImage(), drawImage() view detailed properties and methods.

ts
import { MxCpp, MxCADUiPrPoint } from "mxcad"

// Drawing picture function
async function Mx_Test_DrawImage() {
    const getPoint = new MxCADUiPrPoint();
    getPoint.setMessage("\n specifies the insertion point :");
    let pt = await getPoint.go();
    if (! pt) return;

    let mxcad = MxCpp.getCurrentMxCAD();
    let imagUrl = "https://cdn.pixabay.com/photo/2022/11/15/12/23/winter-7593872_960_720.jpg";

    mxcad.loadImage(imagUrl,(image)=>{
    if(! image ){
      console.log("loadImage failed");
      return;
    }
    let width = mxcad.mxdraw.viewCoordLong2Cad(100);
    let height  = (image.height /  image.width) * width;
    mxcad.drawImage((pt as any).x,(pt as any).y,width,height,0,imagUrl);
    mxcad.updateDisplay();
    });
}