Code sample Home

Create raster image (from a memory buffer)
void DemoImage3 (HANDLE hLcWnd)
{
  double x0, y0, W, H, Gap;
  HANDLE hDrw, hBlock, hImage, hImgRef;
  WCHAR* szImageName = L"Sample image";
  bool   bTopDown = true;
  BYTE   Dots[8*8*3] = {  // 8 x 8 x (Blue, Green, Red)
    40,0,0,      70,0,0,      100,0,0,     130,0,0,     160,0,0,     190,0,0,     220,0,0,     250,0,0,
    0,40,0,      0,70,0,      0,100,0,     0,130,0,     0,160,0,     0,190,0,     0,220,0,     0,250,0,
    0,0,40,      0,0,70,      0,0,100,     0,0,130,     0,0,160,     0,0,190,     0,0,220,     0,0,250,
    255,255,255, 219,219,219, 182,182,182, 146,146,146, 110,110,110, 73,73,73,    36,36,36,    0,0,0, 
    57,57,57,    77,77,77,    97,97,97,    117,117,117, 137,137,137, 157,157,157, 177,177,177, 197,197,197, 
    0,0,0,       255,0,0,     0,255,0,     0,0,255,     255,255,0,   255,0,255,   0,255,255,   255,255,255,
    50,0,100,    0,60,200,    150,90,0,    250,30,120,  0,150,250,   180,180,0,   0,210,210,   70,240,90,
    220,0,30,    255,30,60,   0,100,90,    120,0,250,   250,0,150,   0,100,180,   70,70,210,   0,90,240
  };
  
  // get drawing and block, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );

  // get image by name 
  hImage = lcDrwGetObjectByName( hDrw, LC_OBJ_IMAGE, szImageName );
  if (hImage == NULL){
    // not exist, we will create it.
    hImage = lcDrwAddImage2( hDrw, szImageName, 8, 8, 24, Dots, bTopDown );
  }
  // add image reference
  x0 = 0.0;
  y0 = 0.0;
  W = 50.0;
  H = 50.0;
  lcBlockAddImageRef( hBlock, hImage, x0, y0, W, H, false );

  // add a rectangle around the image
  Gap = 1.0;
  x0 = x0 - Gap;
  y0 = y0 - Gap;
  W = W + Gap + Gap;
  H = H + Gap + Gap;
  lcBlockAddRect2( hBlock, x0, y0, W, H, 0, false );

  // display
  lcBlockUpdate( hBlock, true, 0 );
  lcWndExeCommand( hLcWnd, LC_CMD_ZOOM_EXT, 0 );
}

This will create the following drawing:



See Also:

Create raster image (from a file)
Create raster image (set pixels)
Scale raster image
Resample raster image