分享

delphi 获取剪贴板图像

 容心居 2021-05-28

unit Unit8;

interface

uses

Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;

type

TForm8 = class(TForm)

Button1: TButton;

CheckBox1: TCheckBox;

ScrollBox1: TScrollBox;

Image1: TImage;

procedure Button1Click(Sender: TObject);

procedure CheckBox1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form8: TForm8;

implementation

{$R *.dfm}

uses Clipbrd,jpeg;

procedure TForm8.Button1Click(Sender: TObject);

var

i:integer;

FIsBitmap:boolean;

begin

FIsBitmap:=false;

for   i:=0   to   clipboard.FormatCount   -1   do   //检测ClipBoard中是否有位图

if   Clipboard.Formats[i]=2   then

begin

FIsBitmap:=true;

break;

end;

if  FIsBitmap then

begin

if checkbox1.Checked then

begin

image1.AutoSize:= false;

image1.Width:= scrollbox1.ClientWidth-4;

end else image1.AutoSize:= true;

Image1.Picture.LoadFromClipBoardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);

if checkbox1.Checked then

image1.Height:= round(image1.Picture.Bitmap.Height * (image1.Width / image1.Picture.Bitmap.Width)); //自动设定高度

Image1.Top:= 2;

Image1.Left:= 2;

end else begin

Showmessage('剪贴板中没有图片!');

end;

end;

procedure TForm8.CheckBox1Click(Sender: TObject);

var k: integer;

begin

Image1.Top:= 2;

Image1.Left:= 2;

if checkbox1.Checked then

begin

image1.AutoSize:= false;

image1.Stretch:= false;

image1.Width:= scrollbox1.ClientWidth-4;

k:= image1.Picture.Bitmap.Width;

if k=0 then

k:= image1.Picture.Graphic.Width;

image1.Height:= round(image1.Height * (image1.Width / k)); //自动设定高度

image1.Stretch:= true;

end else image1.AutoSize:= true;

end;

end.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多