大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> 根据位图做出漂亮的不规则FORM

根据位图做出漂亮的不规则FORM

时间: 2021-07-31 作者:daque

unit unit1;  interface  uses    windows, messages, sysutils, classes, graphics, controls, forms, dialogs,    extctrls, stdctrls, buttons;  type    tform1 = class(tform)      image1: timage;      button1: tbutton;      procedure formcreate(sender: tobject);      procedure button1click(sender: tobject);      procedure image1mousedown(sender: tobject; button: tmousebutton;        shift: tshiftstate; x, y: integer);    private      function createregion(wmask: tbitmap; wcolor: tcolor;        hcontrol: thandle): hrgn;      { private declarations }    public      { public declarations }    end;  var    form1: tform1;  implementation  {$r *.dfm}  function tform1.createregion(wmask:tbitmap;wcolor:tcolor;hcontrol:thandle): hrgn;  var    dc, dc_c: hdc;    rgn: hrgn;    x, y: integer;    coord: tpoint;    line: boolean;    color: tcolor;  begin    dc := getwindowdc(hcontrol);    dc_c := createcompatibledc(dc);    selectobject(dc_c, wmask.handle);    beginpath(dc);    for x:=0 to wmask.width-1 do    begin      line := false;      for y:=0 to wmask.height-1 do      begin        color := getpixel(dc_c, x, y);        if not (color = wcolor) then        begin          if not line then          begin            line := true;            coord.x := x;            coord.y := y;          end;        end;        if (color = wcolor) or (y=wmask.height-1) then        begin          if line then          begin            line := false;            movetoex(dc, coord.x, coord.y, nil);            lineto(dc, coord.x, y);            lineto(dc, coord.x + 1, y);            lineto(dc, coord.x + 1, coord.y);            closefigure(dc);          end;        end;      end;    end;    endpath(dc);    rgn := pathtoregion(dc);    releasedc(hcontrol, dc);    result := rgn;  end;  procedure tform1.formcreate(sender: tobject);  var    w1:tbitmap;    w2:tcolor;    rgn: hrgn;  begin    w1:=tbitmap.create;    w1.assign(image1.picture.bitmap);    w2:=w1.canvas.pixels[0,0];    rgn := createregion(w1,w2,handle);    if rgn<>0 then    begin       setwindowrgn(handle, rgn, true);    end;    w1.free;  end;  procedure tform1.button1click(sender: tobject);  begin    close;  end;  procedure tform1.image1mousedown(sender: tobject; button: tmousebutton;    shift: tshiftstate; x, y: integer);  begin    releasecapture;    sendmessage(handle, wm_syscommand, $f012, 0);  end;  end.

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.