zoukankan      html  css  js  c++  java
  • delphi根据不同图片生成不规则窗口的实现(仅限于BMP格式)

    unit CreateImageForm;

    interface
    uses
    Windows, SysUtils, Variants, Classes, Graphics;

    procedure CreatRgnForm( Bmap: TBitMap; WColor: TColor; hand:THandle);

    implementation

    procedure CreatRgnForm( Bmap: TBitMap; WColor: TColor; hand:THandle);
    var
    rgn: HRgn;
    dc, cdc: HDC;
    x, y: integer;
    p: Tpoint;
    line: boolean;
    color: Tcolor;
    begin
    dc := GetWindowDc(hand);
    cdc := CreateCompatibleDc( dc );
    SelectObject( cdc, Bmap.Handle );
    //WColor := Img.Picture.Bitmap.Canvas.Pixels[0, 0];
    //WColor := GetPixel( cdc, 0, 0 );
    BeginPath( dc );
    for x := 0 to Bmap.Width - 1 do
    begin
    line := false;
    for y := 0 to Bmap.Height - 1 do
    begin
    color := GetPixel( cdc, x, y );
    if not( color=WColor) then
    begin
    if not line then
    begin
    line := true;
    p.X := x;
    p.Y := y;
    end;
    end;

    if ( color=WColor)or( y=Bmap.Height - 1 ) then
    begin
    if line then
    begin
    line := false;
    MoveToEx( dc, p.X, p.Y, nil );
    LineTo(dc, p.X, y );
    LineTo(dc, p.X + 1, y );
    LineTo(dc, p.X + 1, p.Y );
    CloseFigure( dc );
    end;
    end;
    end;
    end;
    EndPath( dc );
    Rgn := PathToRegion( dc );
    ReleaseDc( hand, dc );
    SetWindowRgn( hand , rgn, true );
    end;

    end.


    如此调用就可以了
    procedure TForm1.FormCreate(Sender: TObject);
    var
    color: TColor;
    w1: TBitMap;
    begin
    w1 := TBitMap.Create;
    w1.Assign( Image1.Picture.Bitmap );
    color := w1.Canvas.Pixels[0, 0];
    CreatRgnForm( w1, color, handle);
    end.

  • 相关阅读:
    问题汇总
    Spring boot开发过程遇到的一些小问题
    Java 7 新特性
    I2C总线协议详解
    画布分割算法
    nordic __noinit__变量使用
    RTOS事件组使用流程
    RTOS软件定时器的使用
    RTOS互斥信号量的使用流程
    RTOS优先级翻转
  • 原文地址:https://www.cnblogs.com/blogpro/p/11446618.html
Copyright © 2011-2022 走看看