Code sample Home

Create raster image (set pixels)
void DemoImage2 (HANDLE hLcWnd)
{
  int    ImgW, ImgH, PixX, PixY, R, G, B;
  double x0, y0, x1, y1, W, H, Htxt, Gap;
  HANDLE hDrw, hBlock, hImage, hImgRef;
  WCHAR* szImageName = L"Sample image";

  // 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){
    // image size, pixels
    ImgW = 500;
    ImgH = 500;
    // create image
    hImage = lcDrwAddImage2( hDrw, szImageName, ImgW, ImgH, 24, NULL, false );
    // set color of the image pixels
    for (PixX=0; PixX<ImgW; ++PixX){
      R = (255 * PixX) / ImgW;
      for (PixY=0; PixY<ImgH; ++PixY){
        G = (255 * PixY) / ImgH;
        B = 255 - abs(R-G);
        lcImageSetPixelRGB( hImage, PixX, PixY, R, G, B );
      }
    }
  }
  // add image reference
  x0 = 10.0;
  y0 = 20.0;
  W = 50.0;
  H = 50.0;
  Htxt = 5.0;
  Gap = Htxt * 0.3;
  lcBlockAddImageRef( hBlock, hImage, x0, y0, W, H, false );

  // add more graphic objects
  x0 = x0 - Gap;
  y0 = y0 - Gap;
  W = W + Gap + Gap;
  H = H + Gap + Gap;
  lcBlockAddRect2( hBlock, x0, y0, W, H, 0, false );
  x1 = x0 + W + Gap;
  y1 = y0 + H + Gap;
  x0 = x0 - Gap;
  y0 = y0 - Gap;
  lcBlockAddText2( hBlock, L"RED", x1, y0, LC_TA_LEFTOP, Htxt, 1, 0, false );
  lcBlockAddText2( hBlock, L"GREEN", x0, y1, LC_TA_RIGBOT, Htxt, 1, 0, false );
  lcBlockAddText2( hBlock, L"BLUE", x0, y0, LC_TA_RIGTOP, Htxt, 1, 0, false );
  lcBlockAddText2( hBlock, L"WHITE", x1, y1, LC_TA_LEFBOT, Htxt, 1, 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 (from a memory)
Scale raster image
Resample raster image