直接创建位图文件
1
{
2![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
函数名称: CreateBitmapFile
4![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
功能:创建位图文件
6![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
参数说明
8![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
FileName: 要生成的文件名
10
Width:位图宽度
11
Height:位图高度
12
ColorTableSize: 调色板数据长度
13
ColorBits:颜色位数
14
DataBits:位图数据存储区首地址
15
ColorTableData:调色板数据存储区首地址
16![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
返回值
18![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
创建成功返回 True,否则返回 False
20![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
}
22![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23
function CreateBitmapFile(FileName:string;Width,Height,ColorTableSize:Integer;
24
ColorBits:Byte;DataBits,ColorTableData:Pointer):Boolean;
25
var
26
fs: TFileStream;
27
bmpfh: TBitmapFileHeader;
28
bmpih: TBitmapInfoHeader;
29
i,remainder,bytesPerLine: integer;
30
align:DWORD;
31
begin
32
Result:=False;
33
bmpfh.bfType := $4D42;
34
bmpfh.bfSize := Width * Height * ColorBits + SizeOf(TBitmapFileHeader) + SizeOf(TBitmapInfoHeader) + ColorTableSize;
35
bmpfh.bfReserved1 := 0;
36
bmpfh.bfReserved2 := 0;
37
bmpfh.bfOffBits := SizeOf(TBitmapFileHeader) +
38
SizeOf(TBitmapInfoHeader) + ColorTableSize;
39
FillChar(bmpih, SizeOf(bmpih), 0);
40
with bmpih do
41
begin
42
biSize := SizeOf(TBitmapInfoHeader);
43
biWidth := Width;
44
biHeight := Height;
45
biPlanes := 1;
46
biBitCount := ColorBits;
47
biCompression := BI_RGB;
48
biSizeImage := Width * Height * ColorBits div 8;
49
end;
50
fs := TFileStream.Create(FileName,fmCreate,GENERIC_READ or GENERIC_WRITE);
51
try
52
fs.Write(bmpfh, SizeOf(TBitmapFileHeader));
53
fs.Write(bmpih, SizeOf(bmpih));
54
if ColorTableSize>0 then
55
fs.Write(ColorTableData^, 1024);
56
bytesPerLine:=(Width*ColorBits) div 8 + Ord(not (Width*ColorBits) mod 8=0);
57
remainder:=bytesPerLine mod 4;
58
align:=0;
59
//bitmap data is organized upward and rightward,and bytes of each row must be multiple of 4
60
for i:=Height-1 downto 0 do
61
begin
62
fs.Write(Pointer(Cardinal(DataBits)+i*bytesPerLine)^, bytesPerLine);
63
if remainder>0 then
64
fs.Write(align,4-remainder);
65
end;
66
Result:=True;
67
finally
68
fs.Free;
69
end;
70
end;
71![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
51
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
55
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
56
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
57
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
61
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
62
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
63
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
64
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
65
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
66
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
67
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
68
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
69
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
70
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
71
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)