Vcl.Graphics.TBitmap.SaveToClipboardFormat

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure SaveToClipboardFormat(var Format: Word; var Data: THandle;  var APalette: HPALETTE); override;

C++

virtual void __fastcall SaveToClipboardFormat(System::Word &Format, NativeUInt &Data, HPALETTE &APalette);

Properties

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

Description

Creates a local copy of the bitmap in Clipboard format.

Use SaveToClipboardFormat to copy the bitmap to a Clipboard format. The bitmap's palette is returned in the APalette parameter, the format in the AFormat parameter, and a handle to the data in the AData parameter. Before the bitmap can be saved, an application must have registered the format with the TBitmap object 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;
  Bitmap : TBitMap;
  AData : THandle;
  APalette : HPALETTE;
begin
  Bitmap := TBitmap.Create;
  try
    Bitmap.LoadFromFile('C:\Users\Public\Pictures\Sample Pictures\desert.bmp');
    Bitmap.SaveToClipBoardFormat(MyFormat, AData, APalette);
    ClipBoard.SetAsHandle(MyFormat,AData);
  finally
    Bitmap.Free;
  end;
end;

C++:

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

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

See Also

Code Examples