Insert image from a copy and paste

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
alexandreq
Posts: 184
Joined: Wed Jan 18, 2012 6:22 pm

Insert image from a copy and paste

Post 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
Sergey Tkachenko
Site Admin
Posts: 17553
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Insert image from a copy and paste

Post 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;
Post Reply