trichview.com

trichview.support




Re: Auto-Convert Bitmap to JPG-Image


Return to index


Author

Message

Sergey Tkachenko

Posted: 08/09/2002 15:13:37


> which doesn't get sized correctly when pasted - the picture's height get

> smaller, while the frame of the picture remains correct.


It's strange, I do not know why it happens. When I assigned bmp to jpeg, it

was always converted correctly.


>

> Assuming that we could get this right,  how could I make it work for all

> pictures contained in the document that paste, i.e. if I select a word

> document in Word, and paste it into RichView, it would automatically

convert

> all pictures to JPEG (or GIF for that matter)?


I'v posted an example how to convert matafiles imported from RTF to bmp.

It's not difficult to change it to jpegs (one note: as far as I remember, in

the latest version procedure for OnCustomImageItem has one additional

parameter):


Create the following function:


uses RVItem;


procedure TForm1.DoOnRTFImage(RVData: TCustomRVData; Graphic: TGraphic;

  Hypertext: Boolean; var item: TCustomRVItemInfo;

  var FreeGraphic: Boolean);

var bmp: TBitmap;

begin

  if Graphic is TMetafile then begin

    bmp := TBitmap.Create;

    bmp.Width := Graphic.Width;

    bmp.Height := Graphic.Height;

    bmp.Canvas.Draw(0,0,Graphic);

    Graphic := bmp;

    FreeGraphic := True;

  end;

  if Graphic=nil then begin

    bmp := TBitmap.Create;

    bmp.Width := 32;

    bmp.Height := 32;

    bmp.Canvas.Brush.Color := clBtnFace;

    bmp.Canvas.FillRect(Rect(0,0,32,32));

    Graphic := bmp;

  end;


  if Hypertext then

    item := TRVHotGraphicItemInfo.CreateEx(RVData, Graphic, rvvaBaseline)

  else

    item := TRVGraphicItemInfo.CreateEx(RVData, Graphic,  rvvaBaseline);

end;


Assign at the beggining of your program (for example in Form1.FormCreate)


  RichViewEdit1.RTFReadProperties.OnCustomImageItem := DoOnRTFImage;


Note: newly created bitmap has color resolution of the screen. Use

bmp.PixelFormat to set a number of colors in bitmap.








Powered by ABC Amber Outlook Express Converter