Page 1 of 1
How to paste GIF from clipboard?
Posted: Wed Jul 26, 2006 9:13 am
by huafeifei
First copy a GIF file from some webpage in IE/Firefox browser, then paste into tRichViewEdit.
tRichViewEdit recognize the GIF file as bitmap, and no animation! RVGifAnimate unit is included, but doesn't work.
How can I display GIF when paste a GIF file from clipboard? And show it animated and transparent?
How to recognize picture format in clipboard is GIF, JPEG or BMP?
Pls give me example.
Thanks...........................
Posted: Wed Jul 26, 2006 9:42 am
by huafeifei
Try with code belowing, can paste image, but no animation.
try
pic := TPicture.Create;
try
// pic.LoadFromFile(OpenDialog1.FileName);
pic.Bitmap.Assign(Clipboard);
pic.SaveToFile('c:\a.gif');//debug information
gr := RV_CreateGraphics(TGraphicClass(pic.Graphic.ClassType));
gr.Assign(pic);
finally
pic.Free;
end;
if TextAsName and Clipboard.HasFormat(CF_TEXT) then
s := Clipboard.AsText
else
s := '';
if gr<>nil then
InsertPicture(s,gr,rvvaBaseLine);
except
Application.MessageBox(PChar('Cannot read picture from clipboard'), 'Error',
MB_OK or MB_ICONSTOP);
end;
//Here is original codes of PasteBitmap
// bmp := TBitmap.Create;
// bmp.Assign(Clipboard);
// if TextAsName and Clipboard.HasFormat(CF_TEXT) then
// s := Clipboard.AsText
// else
// s := '';
// InsertPicture(s,bmp,rvvaBaseline);
Posted: Wed Jul 26, 2006 2:47 pm
by Sergey Tkachenko
As far as I know, there are no standard Clipboard formats for Gifs or Jpegs.
Browsers copy them to the Clipboard as bitmaps.
Posted: Thu Jul 27, 2006 1:31 am
by huafeifei
Thanks for your reply.
Some popular software can paste gif image from clipboard, like acdsee, outlook.
Is there any tips to solve this problem?
I will try with htmlimporter.
Posted: Thu Jul 27, 2006 3:27 am
by huafeifei
Problem solved! Share tip code here.
Acctually, clipboard copy image(jpeg/gif/bmp) operation from browser or harddisk will save file as bitmap(CF_BITMAP), at the same time, save file to hard disk and filename to CF_HDROP. Use Clipboard.HasFormat(CF_HDROP) and DragQueryFile to get filename in harddisk. Then you can load image file from harddisk according filename.
I modified the PasteBitmap, and it can work well with GIF image/JPEG image/GITMAP.
procedure TCustomRichViewEdit.PasteBitmap(TextAsName: Boolean);
var gr: TGraphic;
pic: TPicture;
GIFImage: TGifImage;
s: String;
i: integer;
drophandle :Thandle;
Filescount :integer;
FileName :array[0..MAX_PATH] of Char;
begin
{$IFNDEF RVDONOTUSEINPLACE}
if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
TCustomRichViewEdit(InplaceEditor).PasteBitmap(TextAsName);
exit;
end;
{$ENDIF}
if not BeforeChange(False) then exit;
if not Clipboard.HasFormat(CF_BITMAP) then exit;
if Clipboard.HasFormat(CF_HDROP) then begin
DropHandle:=Clipboard.GetAsHandle(CF_HDROP);
FilesCount:=DragQueryFile(DropHandle, $FFFFFFFF, Filename, MAX_PATH); //get file count
for i:=0 to FilesCount-1 do begin
FillChar(FileName, SizeOf(FileName), 0);
if DragQueryFile(DropHandle, i, FileName, MAX_PATH)>0 then begin
try
pic := TPicture.Create;
try
pic.LoadFromFile(StrPas(@FileName));
gr := RV_CreateGraphics(TGraphicClass(pic.Graphic.ClassType));
gr.Assign(pic.Graphic);
finally
pic.Free;
end;
if TextAsName and Clipboard.HasFormat(CF_TEXT) then
s := Clipboard.AsText
else
s := '';
if gr<>nil then InsertPicture(s,gr,rvvaBaseLine);
except
Application.MessageBox(PChar('Cannot read picture from Clipboard'), 'Error', MB_OK or MB_ICONSTOP);
end;
StrPas(@FileName)
end;
end;
end;
Posted: Sat Jul 29, 2006 1:19 pm
by Sergey Tkachenko
Thank you!
Something like this will be included in the next update of TRichView.
Posted: Mon Jul 31, 2006 7:58 am
by huafeifei
You do great job in developing the components.
Hope them to be more simply to use.
Posted: Mon Oct 06, 2014 4:20 pm
by Darken
Hello Sergey!
I'm using TRichViewEdit with image, bmp, jpeg - good copy and paste from clipboard. But if copy gif or png image, paste doesn't work. (used TGIFImage, TPNGObject and Delphi 7).
rve.CopyDef - for copy
rve.Paste - for paste
Can you have decision?
Thank you Sergey!
Posted: Mon Oct 06, 2014 5:33 pm
by Sergey Tkachenko
When you copy-paste in TRichViewEdit, data are pasted in RVF format.
You need to register graphic classes for insertion from RVF. Without registering, you should have the same problem when loading RVF files containing images.
In Dephi 7, TGIFImage and TPNGObject are not standard formats.
PNG:
Call (one time, before the first RVF loading):
RegisterClass([TPNGObject]);
Also, I recommend calling:
Code: Select all
uses RVGrHandler;
RVGraphicHandler.RegisterHTMLGraphicFormat(TPNGObject);
RVGraphicHandler.RegisterPngGraphic(TPNGObject);
GIF:
Include RVGifAnimate in your project. This unit includes registrations for TGifImage.
Posted: Tue Oct 07, 2014 1:24 pm
by Darken
I'm so sorry Sergey, but doesn't work...
I'm prepare test project with GIF and PNG library. Image insert in RVF document good, but if paste from clibpoard RichViewEdit do nothing.
http://softprostudio.com/Test_ClipboardIMAGE.7z
Code: Select all
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtDlgs, StdCtrls, RVScroll, RichView, RVEdit, RVFuncs,
GIFImage, Jpeg, pngimage, RVGifAnimate, RVStyle, ExtCtrls
;
type
TForm1 = class(TForm)
rve: TRichViewEdit;
OpPictDialinsert: TOpenPictureDialog;
Panel1: TPanel;
btnOpenImage: TButton;
btnCopy: TButton;
btnCut: TButton;
btnPaste: TButton;
RVS: TRVStyle;
procedure btnOpenImageClick(Sender: TObject);
procedure btnCopyClick(Sender: TObject);
procedure btnCutClick(Sender: TObject);
procedure btnPasteClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnOpenImageClick(Sender: TObject);
var
gr: TGraphic;
begin
if OpPictDialinsert.Execute then begin
gr := RVGraphicHandler.LoadFromFile(OpPictDialinsert.FileName);
if gr <> nil then begin
try
rve.BeginUpdate;
RVE.InsertPicture(ExtractFileName(OpPictDialinsert.FileName), gr, rvvaBaseLine);
finally
rve.EndUpdate;
end;
end else
Application.MessageBox(PChar('Can''t open file ' + OpPictDialinsert.FileName), 'Error',
MB_OK or MB_ICONSTOP);
end;
end;
procedure TForm1.btnCopyClick(Sender: TObject);
begin
rve.CopyDef;
end;
procedure TForm1.btnCutClick(Sender: TObject);
begin
rve.CutDef;
end;
procedure TForm1.btnPasteClick(Sender: TObject);
begin
rve.Paste;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RVGraphicHandler.RegisterHTMLGraphicFormat(TPNGObject);
RVGraphicHandler.RegisterPngGraphic(TPNGObject);
end;
end.
Thank You!
Posted: Tue Oct 07, 2014 6:56 pm
by Sergey Tkachenko
As for PNG, call RegisterClass(TPNGObject) in FormCreate.
As for GIF, it looks like you use not the newest version of TRichView (in the newest version, GraphicHandler is defined in RVGrHandler unit, but it is not included in "uses" in your test application). Older versions of TRichView did not register TGifImage in RvGifAnimate unit.
So, either upgrade to the newest version of TRichView, or add in FormCreate:
Code: Select all
RegisterClass(TGifImage);
RVGraphicHandler.RegisterHTMLGraphicFormat(TGifImage);
Posted: Fri Oct 10, 2014 8:18 am
by Darken
Thank you Sergey, thats is work!