delphi 获取剪切板图像  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 获取剪切板图像





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.


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.036864042282104 seconds