zoukankan      html  css  js  c++  java
  • Delphi编程分割图片的方法

    Delphi切割图片,Delphi图片分割
    这个例子是把一张图片平均分成了 4 份, 顺序是: 左、右、上、下; 没使用循环操作, 显得有点笨, 但容易理解.
    unit Unit1;

    interface

    uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;

    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
    const
      path = 'c:\temp\test.bmp';
      { 先准备好测试图片 } var
      bit: TBitmap;
      bits: array [0 .. 3] of TBitmap;
      { 假如分成 4 份 } i, w, h: Integer;
    begin
      bit := TBitmap.Create;
      bit.LoadFromFile(path);
      w := bit.Width div 2;
      h := bit.Height div 2;
      for i := 0 to 3 do
      begin
        bits[i] := TBitmap.Create;
        bits[i].SetSize(w, h);
      end;
      BitBlt(bits[0].Canvas.Handle, 0, 0, w, h, bit.Canvas.Handle, 0, 0, SRCCOPY);
      BitBlt(bits[1].Canvas.Handle, 0, 0, w, h, bit.Canvas.Handle, w, 0, SRCCOPY);
      BitBlt(bits[2].Canvas.Handle, 0, 0, w, h, bit.Canvas.Handle, 0, h, SRCCOPY);
      BitBlt(bits[3].Canvas.Handle, 0, 0, w, h, bit.Canvas.Handle, w, h, SRCCOPY);
      for i := 0 to 3 do
      begin
        bits[i].SaveToFile(ChangeFileExt(path, Format('.%.3d.bmp', [i + 1])));
        bits[i].Free;
      end;
      bit.Free;
    end;

    end.

    [本文来自: 学Delphi网(http://www.xuedelphi.com/) ]详细出处参考:http://www.xuedelphi.cn/article/html2010/2010102722310213.html

  • 相关阅读:
    进程
    交换分区
    linux命令
    Linux进程
    开会
    今天的学习情况
    CentOS7.6 yum方式安装redis最新版
    Centos7 yum安装postgresql 9.5
    GitLab CI runner can't connect to tcp://localhost:2375 in kubernetes
    Server 2008 R2远程桌面授权,解决120天过期问题
  • 原文地址:https://www.cnblogs.com/hssbsw/p/2540882.html
Copyright © 2011-2022 走看看