这个自定义函数执行到setlength(hImgData,ImgSize);时出错,请各位帮忙一下
function LoadBmpFile(BmpFile:string):boolean;
var
HimgData: array of array of int64;
hf:file;
bf:bitmapfileheader;
bi:bitmapinfoheader;
widthbytes:integer;
Nullcount:integer;
ImgSize:integer;
LineBytes:integer;
numcolors:integer;
begin
AssignFile(hf,BmpFile);
Reset(hf,1);//RecSize is an optional expression, which can be specified only if F is an untyped file. If F is an untyped file, RecSize specifies the record size to be used in data transfers. If RecSize is omitted, a default record size of 128 bytes is assumed.
Blockread(hf,bf,Sizeof(Bitmapfileheader));//BlockRead reads Count or fewer records from the file F into memory, starting at the first byte occupied by Buf. The actual number of complete records read (less than or equal to Count) is returned in AmtTransferred.
widthbytes:=trunc(((8-(bi.biWidth*bi.biBitCount mod 8)) mod 8 + bi.biBitCount*bi.biWidth)/8);
LineBytes:=(4-(widthbytes mod 4)) mod 4 +widthbytes;
Nullcount := LineBytes-WidthBytes;
ImgSize:= LineBytes*bi.biHeight;
if bi.biClrUsed<>0 then
NumColors:=bi.biClrUsed
else
begin
if bi.bibitcount=1 then
NumColors:=2
else if bi.biBItCount=4 then
NumColors:=16
else if bi.biBitCount=8 then
NumColors:=256
else if bi.biBitCount=24 then
NumColors:=0
else
begin
showMessage(invalid color number!);
Closefile(hf);
result:=False;
Exit;
end;
end;
if bf.bfOffBits <> NumColors * SizeOf(RGBQUAD) + SizeOf(BitMapFileHeader)
+ SizeOf (BitMapInfoHeader) then
begin
ShowMessage(Invalid color numbers!);
CloseFile(hf);
Result := False;
Exit;
end;
setlength(hImgData,ImgSize);
Blockread(hf,hImgData,SizeOf(hImgData),ImgSize);
CloseFile(hf);
Result:=True;
end;
长度上加1