怎样复制图片(100)

  • 主题发起人 主题发起人 fhong
  • 开始时间 开始时间
F

fhong

Unregistered / Unconfirmed
GUEST, unregistred user!
有一张图片在文件夹中,怎样用delphi实现复制功能,可以把这张图片复制到剪贴板,用户随便到那一个文件夹都可以用window的粘贴功能把那张图片复制过来?就是用delphi只实现window的图片复制功能,粘贴的功能留给window。
 
uses ShlObj, ClipBrd; procedure CopyFilesToClipboard(FileList: string); var DropFiles: PDropFiles; hGlobal: THandle; iLen: Integer; begin iLen := Length(FileList) + 2; FileList := FileList + #0#0; hGlobal := GlobalAlloc(GMEM_SHARE or GMEM_MOVEABLE or GMEM_ZEROINIT, SizeOf(TDropFiles) + iLen); if (hGlobal = 0) then raise Exception.Create('Could not allocate memory.'); begin DropFiles := GlobalLock(hGlobal); DropFiles^.pFiles := SizeOf(TDropFiles); Move(FileList[1], (PChar(DropFiles) + SizeOf(TDropFiles))^, iLen); GlobalUnlock(hGlobal); Clipboard.SetAsHandle(CF_HDROP, hGlobal); end; end; // Example procedure TForm1.Button1Click(Sender: TObject); begin CopyFilesToClipboard('C:/temp/temp.bmp'); end;
 
如复制D:/1.jpgvar S: wideString;//注意要WideString; S1: String; i: Integer; Stream: TMemoryStream;begin Stream := TMemoryStream.Create; S := #$14#0#0#0#0#0#0#0#1#0+'D:/1.jpg'+#0#0; //SetLength(S1, Length(S)*2); for i := 1 to Length(S) do S1 := S1+S+#0; Stream.Write(Pointer(S1)^, Length(S1)); CopyStreamToClipboard(CF_HDROP, Stream); Stream.Free;end;procedure CopyStreamToClipboard(fmt: Cardinal; S: TStream);var hMem: THandle; pMem: Pointer; begin Assert(Assigned(S)); S.Position := 0; hMem := GlobalAlloc(GHND or GMEM_DDESHARE, S.Size); if hMem <> 0 then begin pMem := GlobalLock(hMem); if pMem <> nil then begin try S.Read(pMem^, S.Size); S.Position := 0; finally GlobalUnlock(hMem); end; Clipboard.Open; try Clipboard.SetAsHandle(fmt, hMem); finally Clipboard.Close; end; end { If } else begin GlobalFree(hMem); OutOfMemoryError; end; end { If } else OutOfMemoryError; end; { CopyStreamToClipboard } 以上方法对全英文或数字的有效,中文的微软有个转化, LZ自己研究下好了
 
如果你是想复制图片内容uses Clipbrdprocedure TForm1.btn3Click(Sender: TObject);begin Clipboard.Assign(img1.Picture);//粘贴板上面就是 img1的图片了,可以直接在画图或qq里面 ctrl+Vend;
 
后退
顶部