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

📄 getbitmapbitsu.pas

📁 DelphiWin32核心API参考光盘内容.是学习书籍中的源码,便于学习.
💻 PAS
字号:
unit GetBitmapBitsU;

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Image1: TImage;
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
type
  TBitmapBits = array[0..0] of Byte;
var
  BitmapBits: ^TBitmapBits;         // holds the bytes from the bitmap
  LoopRow, LoopCol: Integer;        // loop control variables
begin
  {set the string grid to the dimensions of the bitmap}
  StringGrid1.ColCount:=Image1.Picture.Bitmap.Width;
  StringGrid1.RowCount:=Image1.Picture.Bitmap.Height;

  {dynamically allocate the needed space for the bitmap color data}
  GetMem(BitmapBits,StringGrid1.RowCount*StringGrid1.ColCount);

  {retrieve the color data from the bitmap}
  GetBitmapBits(Image1.Picture.Bitmap.Handle, StringGrid1.RowCount*
                StringGrid1.ColCount, BitmapBits);

  {display the values that define the bitmap in the string grid. since this
   is a 256 color bitmap, these values represent indexes into the bitmap's
   color palette.}
  for LoopRow:=0 to Image1.Height-1 do
    for LoopCol:=0 to Image1.Width-1 do
      StringGrid1.Cells[LoopCol, LoopRow]:=IntToStr(BitmapBits[LoopRow*Image1.Width+LoopCol]);

  {free the allocated memory}
  FreeMem(BitmapBits);    
end;

end.

⌨️ 快捷键说明

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