uses Clipbrd, winres, bitmap;

var
  Bmp: PBitmap;

function GetBitmapFromClip: PBitmap;
var
  size, bit, lead: LongInt;
  p, Buf: pointer;
  Bmp: PBitmap;
Begin
  GetBitmapFromClip := nil;
  size := GetClipboardDataSize(cf_Bitmap);
  If size = 0 then Exit;
  GetMem(Buf, size);
  GetClipboardData(cf_Bitmap, Buf^);
  New(Bmp);
  GetBitmapFromClip := Bmp;
  Move(Buf^, Bmp^, SizeOf(TBitmap));
  asm mov bx, 0 end;			{ for a *very* silly reason }
  with Bmp^ do Begin
    bmPalette := nil;
    lead := PChar(bmBits) - PChar(Buf); 	{ leading bytes }
    FreeMemAlign(Buf, lead, false, false);
    bit := bmHeight*bmWidthBytes;
    If size > lead + bit then Begin
      p := PChar(bmBits) + bit;
      FreeMemAlign(p, size - lead - bit, true, true)
    End
  End
End;

begin
  openclipboard;
  Bmp := GetBitmapFromClip;
  closeclipboard;
  DeleteBitmap(Bmp)
end.
