How to paste GIF from clipboard?
How to paste GIF from clipboard?
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...........................
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...........................
Last edited by huafeifei on Wed Jul 26, 2006 10:40 am, edited 1 time in total.
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);
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);
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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;
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;
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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:
GIF:
Include RVGifAnimate in your project. This unit includes registrations for TGifImage.
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);
Include RVGifAnimate in your project. This unit includes registrations for TGifImage.
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
Thank You!
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.
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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:
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);