WPCubed Product Support

Problem Inserting an Image into a Table Cell

Inside the TableCellCallBack function I would like to create an image

  • I use the following code - however it DOESN'T work????
fBMP := Graphics.TBitmap.Create;
try
    fBMP.LoadFromFile('C:\myImage.bmp);  
    wpobj := nil;
    try
      wpobj := TWPOImage.CreateImage(par.RTFData.DataCollection, fBMP);
      obj := TWPTextObj.Create;
      par.Insert(0, obj);
      obj.ObjRef := wpobj;
      obj.ObjType := wpobjImage;
      obj.Width := 200;
      obj.Height := 20;
    except
      FreeAndNil(wpobj);
    end;
  finally
    FreeAndNil(fBmp);
  end;
#1 ♥ 0
2.8k Views 2 users read 1 min
support

Hi,

Width and Height are twips values. The height '20' will be hardly one pixel, please use this formula to convert standard pixels to twips.
Height := MulDiv( 20, 1440, 96 )

Instead of '96' you can use WPScreenPixelsPerInch but that will give you different sizes on different machines.

You can also simplify the code using the function par.AppendNewObject and LoadObjFromFile.

obj := par.AppendNewObject(wpobjImage, false, false, 0);
   obj.LoadObjFromFile(c:\testimg.bmp');
   obj.Width := WPCentimeterToTwips(4);
   obj.Height := WPCentimeterToTwips(4);

Julian

#2 ♥ 0
This category is archived. No new posts are possible.