S
sundart
Unregistered / Unconfirmed
GUEST, unregistred user!
JohnsonGuo兄你好:150分我已经送上,我准备再追加200分给兄台,下面我还有几个问题请教。
(原问题:紧急求助:如何读出单色BMP图象的图象数据(不要控件),请大师给出原代码?)
单色图片是扫描的身份证号码。我必须将各数字分割开,并得到图象颜色编码。
下面是你给我的程序,我用了,挺不错的,能将我的数字正确分割,但是我想只取数字部分,其余空白
部分删除。不知兄台能否指点一番。另外PByteArray(Bmp.ScanLine)[Line]表示什么意思?
Bmp.PixelFormat := pf8Bit;为什么要设为8位,我取较低值(比如2位)分割的数字都不准确?
谢谢!!!
程序如下:
function IsEmpty(Bmp: TBitmap; Line: Integer): Boolean;
var
i: Integer;
begin
Result := True;
for i := 0 to Bmp.Height - 1 do
if PByteArray(Bmp.ScanLine)[Line] = 0 then begin
Result := False;
Exit;
end;
end;
procedure FindColumn(Bmp: TBitmap; var First, Last: Integer);
begin
while (First < Bmp.Width) and IsEmpty(Bmp, First) do
Inc(First);
Last := First;
while (Last < Bmp.Width) and not IsEmpty(Bmp, Last) do
Inc(Last);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Res, Bmp: TBitmap;
Count, First, Last: Integer;
begin
Bmp := TBitmap.Create;
Res := TBitmap.Create;
try
Bmp.LoadFromFile('e:/myfiles/12345.bmp');
Bmp.PixelFormat := pf8Bit;
Count := 1;
First := 0;
repeat
FindColumn(Bmp, First, Last);
if First = Last then Break
else begin
Res.Width := Last - First + 1;
Res.Height := Bmp.Height;
Res.Canvas.CopyRect(
Rect(0, 0, Res.Width, Res.Height),
Bmp.Canvas,
Rect(First, 0, Last + 1, Res.Height));
Res.SaveToFile('e:/myfiles/' + IntToStr(Count) + '.bmp');
Inc(Count);
First := Last + 1;
end;
until False;
finally
Bmp.Free;
Res.Free;
end;
end;
(原问题:紧急求助:如何读出单色BMP图象的图象数据(不要控件),请大师给出原代码?)
单色图片是扫描的身份证号码。我必须将各数字分割开,并得到图象颜色编码。
下面是你给我的程序,我用了,挺不错的,能将我的数字正确分割,但是我想只取数字部分,其余空白
部分删除。不知兄台能否指点一番。另外PByteArray(Bmp.ScanLine)[Line]表示什么意思?
Bmp.PixelFormat := pf8Bit;为什么要设为8位,我取较低值(比如2位)分割的数字都不准确?
谢谢!!!
程序如下:
function IsEmpty(Bmp: TBitmap; Line: Integer): Boolean;
var
i: Integer;
begin
Result := True;
for i := 0 to Bmp.Height - 1 do
if PByteArray(Bmp.ScanLine)[Line] = 0 then begin
Result := False;
Exit;
end;
end;
procedure FindColumn(Bmp: TBitmap; var First, Last: Integer);
begin
while (First < Bmp.Width) and IsEmpty(Bmp, First) do
Inc(First);
Last := First;
while (Last < Bmp.Width) and not IsEmpty(Bmp, Last) do
Inc(Last);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Res, Bmp: TBitmap;
Count, First, Last: Integer;
begin
Bmp := TBitmap.Create;
Res := TBitmap.Create;
try
Bmp.LoadFromFile('e:/myfiles/12345.bmp');
Bmp.PixelFormat := pf8Bit;
Count := 1;
First := 0;
repeat
FindColumn(Bmp, First, Last);
if First = Last then Break
else begin
Res.Width := Last - First + 1;
Res.Height := Bmp.Height;
Res.Canvas.CopyRect(
Rect(0, 0, Res.Width, Res.Height),
Bmp.Canvas,
Rect(First, 0, Last + 1, Res.Height));
Res.SaveToFile('e:/myfiles/' + IntToStr(Count) + '.bmp');
Inc(Count);
First := Last + 1;
end;
until False;
finally
Bmp.Free;
Res.Free;
end;
end;