⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 udrawscreen.pas

📁 安徽省货物销售统一发票管理系统 操作说明 1、开票 F7或双击可 查询
💻 PAS
字号:
unit uDrawScreen;

interface

uses
  SysUtils, Graphics;

type
  TDrawScreen = class
  private
    FBitmap: TBitmap;
    FWidth: Integer;
    FHeight: Integer;
    FLines: array of PByteArray;
    procedure SetHeight(const Value: Integer);
    procedure SetWidth(const Value: Integer);
    procedure ResetPixels;

  public
    constructor Create; overload;
    constructor Create(AWidth, AHeight: Integer); overload;
    destructor Destroy; override;

    procedure init; overload;
    procedure init(AWidth, AHeight: Integer); overload;
    procedure SetPixel(X, Y: Integer; AColor: Cardinal);
    function GetPixel(X, Y: Integer): Cardinal;
    property Bitmap: TBitmap read FBitmap;
    property Width: Integer read FWidth write SetWidth;
    property Height: Integer read FHeight write SetHeight;
  end;

implementation

{ TDrawScreen }

procedure TDrawScreen.ResetPixels;
var
  I, J: Integer;
begin
  FBitmap.Width := FWidth;
  FBitmap.Height := FHeight;
  SetLength(FLines, FHeight);

  for I := 0 to FHeight - 1 do
  begin
    FLines[I] := FBitmap.ScanLine[I];
    for J := 0 to FWidth - 1 do PInteger(@FLines[I][J shl 2])^ := 0;
  end;
end;

constructor TDrawScreen.Create(AWidth, AHeight: Integer);
begin
  init(AWidth, AHeight);
end;

destructor TDrawScreen.Destroy;
begin
  SetLength(FLines, 0);
  FBitmap.Free;
  inherited;
end;

procedure TDrawScreen.SetHeight(const Value: Integer);
begin
  FHeight := Value;
  ResetPixels;
end;

procedure TDrawScreen.SetPixel(X, Y: Integer; AColor: Cardinal);
begin
  PInteger(@FLines[Y][X shl 2])^ := AColor;
end;

procedure TDrawScreen.SetWidth(const Value: Integer);
begin
  FWidth := Value;
  ResetPixels;
end;

function TDrawScreen.GetPixel(X, Y: Integer): Cardinal;
begin
  Result := PInteger(@FLines[Y][X shl 2])^;
end;

procedure TDrawScreen.init(AWidth, AHeight: Integer);
begin
  FWidth := AWidth;
  FHeight := AHeight;

  init;
end;

constructor TDrawScreen.Create;
begin
  init(300, 200);
end;

procedure TDrawScreen.init;
begin
  if FBitmap <> nil then FreeAndNil(FBitmap);

  FBitmap := TBitmap.Create;
  FBitmap.Width := FWidth;
  FBitmap.Height := FHeight;
  FBitmap.PixelFormat := pf32Bit;

  ResetPixels;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -