Page 1 of 1

Insert image from a copy and paste

Posted: Tue Jun 25, 2019 6:34 pm
by alexandreq
Hello

If I copy a bmp image and paste it into my Trichview, is it pasted as bmp or jpge?

If it is pasted as bmp, is there any way to paste it as jpge?

Regards

Re: Insert image from a copy and paste

Posted: Wed Jun 26, 2019 5:18 pm
by Sergey Tkachenko
There is no standard Clipboard format for Jpegs, so the copied image will be inserted as a bitmap.
The only way to paste JPEG to RichViewEdit is copying a JPEG file (for example, from Explorer).


Here is a function that pastes bitmap as JPEG:

Code: Select all

function PasteBitmapAsJpeg(rve: TCustomRichViewEdit): Boolean;
var
  bmp: TBitmap;
  jpg: TJPEGImage;
begin
  Result := Clipboard.HasFormat(Windows.CF_BITMAP);
  bmp := TBitmap.Create;
  try
    bmp.Assign(Clipboard);
    jpg := TJPEGImage.Create;
    jpg.Assign(bmp);
  finally
    bmp.Free;
  end;
  rve.InsertPicture('', jpg, rvvaBaseline)
end;
I think it's not a very good idea to paste all bitmap images as JPEGs. JPEGs are good for photos, but not good for screenshots, because they use lossy compression. However, if you want it, you can implement OnPaste event:

Code: Select all

procedure TForm3.SRichViewEdit1Paste(Sender: TCustomRichViewEdit;
  var DoDefault: Boolean);
begin
  DoDefault := not PasteBitmapAsJpeg(Sender);
end;