unit Unit6;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, DBGrids, ExtCtrls, DBCtrls, Mask, jpeg;

type
  TForm6 = class(TForm)
    Label1: TLabel;
    DBGrid1: TDBGrid;
    DBEdit1: TDBEdit;
    DBNavigator1: TDBNavigator;
    Image1: TImage;
    Button1: TButton;
    procedure DBGrid1DblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
function BitmapToRgn(Image: TBitmap): HRGN;
var
  Form6: TForm6;
  sPath:String[60];
  MaskBmp: TBitmap;
implementation

uses Unit2, Unit5, Unit8;

{$R *.dfm}

procedure TForm6.DBGrid1DblClick(Sender: TObject);
begin
if form6.Tag=1 then begin
form2.statusbar1.Panels[2].Text:=datamodule5.DataSource2.DataSet.fieldbyname('user').AsString;
form2.statusbar1.Panels[4].Text:=datamodule5.DataSource2.DataSet.fieldbyname('glava').AsString;
end
else begin
form8.statusbar1.Panels[2].Text:=datamodule5.DataSource2.DataSet.fieldbyname('user').AsString;
form8.statusbar1.Panels[4].Text:=datamodule5.DataSource2.DataSet.fieldbyname('glava').AsString;
end;
close;

end;

procedure TForm6.FormCreate(Sender: TObject);
var   MyJPG: TJPEGImage;
begin
  GetDir(0,sPath);
  MaskBmp := TBitmap.Create;
  MyJPG := TJPEGImage.Create;
  MyJPG.LoadFromStream(TResourceStream.CreateFromID(HInstance, 4, RT_RCDATA));
  image1.Picture.Assign(MyJPG);
    try
    MaskBmp.LoadFromResourceName(HInstance, 'DW3');
    Height := MaskBmp.Height;
    Width := MaskBmp.Width;
    SetWindowRgn(Self.Handle, BitmapToRgn(MaskBmp), True);
  finally
    MaskBmp.Free;
  end;
end;

function BitmapToRgn(Image: TBitmap): HRGN;
var
  TmpRgn: HRGN;
  x, y: integer;
  ConsecutivePixels: integer;
  CurrentPixel: TColor;
  CreatedRgns: integer;
  CurrentColor: TColor;
begin
  CreatedRgns := 0;
  Result := CreateRectRgn(0, 0, maskbmp.Width, maskbmp.Height);
  inc(CreatedRgns);

  if (maskbmp.Width = 0) or (maskbmp.Height = 0) then
    exit;

  for y := 0 to maskbmp.Height - 1 do
  begin
    CurrentColor := maskbmp.Canvas.Pixels[0,y];
    ConsecutivePixels := 1;
    for x := 0 to maskbmp.Width - 1 do
    begin
      CurrentPixel := maskbmp.Canvas.Pixels[x, y];

      if CurrentColor = CurrentPixel then
        inc(ConsecutivePixels)
      else
      begin
        if CurrentColor = clWhite then
        begin
          TmpRgn := CreateRectRgn(x - ConsecutivePixels, y, x, y + 1);
          CombineRgn(Result, Result, TmpRgn, RGN_DIFF);
          inc(CreatedRgns);
          DeleteObject(TmpRgn);
        end;
        CurrentColor := CurrentPixel;
        ConsecutivePixels := 1;
      end;
    end;

    if (CurrentColor = clWhite) and (ConsecutivePixels > 0) then
    begin
      TmpRgn := CreateRectRgn(x-ConsecutivePixels, y, x, y+1);
      CombineRgn(Result, Result, TmpRgn, RGN_DIFF);
      inc(CreatedRgns);
      DeleteObject(TmpRgn);
    end;
  end;
end;

procedure TForm6.Button1Click(Sender: TObject);
begin
close;
end;

end.
