Vcl.Graphics.TPicture.SaveToClipboardFormat

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure SaveToClipboardFormat(var AFormat: Word; var AData: THandle;
var APalette: HPALETTE);

C++

void __fastcall SaveToClipboardFormat(System::Word &AFormat, NativeUInt &AData, HPALETTE &APalette);

Properties

Type Visibility Source Unit Parent
procedure
function
public
Vcl.Graphics.pas
Vcl.Graphics.hpp
Vcl.Graphics TPicture

Description

Allocates a global handle and writes the picture in its native Clipboard format (CF_BITMAP for bitmaps, CF_METAFILE for metafiles, and so on).

Use SaveToClipboardFormat to copy the picture to a Clipboard format. The resulting values can then be copied to the Windows clipboard using the clipboard's SetAsHandle method.

The palette of the picture is returned in the APalette parameter, the format in the AFormat parameter, and a handle to the data in the AData parameter. Before the picture can be saved, an application must have registered the format using the RegisterClipboardFormat method.

The following code snippet shows how to save a bitmap to the clipboard.

Note: To load a bitmap from the clipboard, you can use the code snippet for the LoadFromClipboardFormat method.

Delphi:

uses
  Vcl.Clipbrd;
procedure TForm1.Button1Click(Sender: TObject);
var
  MyFormat : Word;
  Picture : TPicture;
  AData : THandle;
  APalette : HPALETTE;
begin
  Picture := TPicture.Create;
  try
    Picture.LoadFromFile('C:\Users\Public\Pictures\Sample Pictures\desert.bmp');
    Picture.SaveToClipBoardFormat(MyFormat, AData, APalette);
    ClipBoard.SetAsHandle(MyFormat,AData);
  finally
    Picture.Free;
  end;
end;

C++:

#include <Vcl.Clipbrd.hpp>
void __fastcall TForm1::Button1Click(TObject *Sender){
	TClipboard* cb = Clipboard();
	unsigned short MyFormat;
	TPicture* Picture;
	unsigned int AData;
	HPALETTE APalette;

	Picture = new TPicture();
	try{
		Picture->LoadFromFile("C:\\Users\\Public\\Pictures\\Sample Pictures\\desert.bmp");
		Picture->SaveToClipboardFormat(MyFormat, AData, APalette);
		cb->SetAsHandle(MyFormat, AData);
	}
	__finally{
		delete Picture;
	}
}

See Also