D
darnis
Unregistered / Unconfirmed
GUEST, unregistred user!
函数目的: 把指定的字符串,转换成点阵,
AText: 要转换的串。
AFontPixel : 要转换的点阵值。
问题回答之后,我一定另外开贴送分。。
type
TFontPixel = (fp16, fp24, fp32, fpOther);
function Text2Bit(AText: WideString;
const AFontPixel: TFontPixel = fp16): PChar;
var
lblTmp: TLabel;
i, j, DZ, absPos, len, FCol, FRow, iTmp, w: integer;
strTmp: string;
bm1: TBitMap;
dynTmp: array of array of byte;
function FontPixelToV(AFP: TFontPixel): Byte;
begin
case AFP of
fp16: Result := 16;
fp24: Result := 24;
fp32: Result := 32;
else
Result := 16;
end;
end;
begin
lblTmp := TLabel.Create(nil);
bm1 := TBitMap.Create;
//lblTmp.Parent := nil;
strTmp := '';
try
DZ := FontPixelToV(AFontPixel);
lblTmp.Color := clBlack;
lblTmp.Font.Color := clRed;
case AFontPixel of
fp16: lblTmp.Font.Size := 11;
fp24: lblTmp.Font.Size := 16;
fp32: lblTmp.Font.Size := 22;
else
lblTmp.Font.Size := 11;
end;
// 取入参的字长。
lblTmp.Caption := AText;
lblTmp.AutoSize := true;
lblTmp.Height := DZ;
bm1.Width := lblTmp.Width;
bm1.Height := lblTmp.Height;
bm1.Canvas.Brush.Color := clBlack;
bm1.Canvas.FillRect(Rect(0, 0, bm1.Width, bm1.Height));
bm1.Canvas.Font := lblTmp.Font;
bm1.Canvas.TextRect(Rect(0, 0, bm1.Width, bm1.Height), 0, 0, AText);
absPos := 0;
FCol := floor(bm1.Width / 8 + 0.5);
FRow := bm1.Height;
SetLength(dynTmp, FRow); // 第一维是行值。
for i := 0 to FRow - 1 do
begin[red]
SetLength(dynTmp, FCol); // 第二维是列值。
{
这儿老出错,当 I 到 3 时,出错,,扯拐,,是啥原因哦?
我实在是搞不懂了,请教请教,。。
}[/red]
for j := 0 to bm1.Width - 1 do
begin
if bm1.Canvas.Pixels[j, i] = clBlack then
begin
dynTmp[i, i * j + j div 8] := dynTmp[i, i * j + j div 8]
and (not ($80 shr (j - (j div 8) * 8)));
end
else
begin
dynTmp[i, i * j + j div 8] := dynTmp[i, i * j + j div 8]
or ($80 shr (j - (j div 8) * 8));
end;
inc(absPos);
end;
end;
//////////
// 把已经得到的位信息数据拷贝到 Result 中。
GetMem(Result, FRow * FCol);
for i := 0 to FRow - 1 do
for j := 0 to FCol - 1 do
Result[i * j + j] := Char(dynTmp[i, j]);
finally
lblTmp.Free;
bm1.Free;
end;
end;
AText: 要转换的串。
AFontPixel : 要转换的点阵值。
问题回答之后,我一定另外开贴送分。。
type
TFontPixel = (fp16, fp24, fp32, fpOther);
function Text2Bit(AText: WideString;
const AFontPixel: TFontPixel = fp16): PChar;
var
lblTmp: TLabel;
i, j, DZ, absPos, len, FCol, FRow, iTmp, w: integer;
strTmp: string;
bm1: TBitMap;
dynTmp: array of array of byte;
function FontPixelToV(AFP: TFontPixel): Byte;
begin
case AFP of
fp16: Result := 16;
fp24: Result := 24;
fp32: Result := 32;
else
Result := 16;
end;
end;
begin
lblTmp := TLabel.Create(nil);
bm1 := TBitMap.Create;
//lblTmp.Parent := nil;
strTmp := '';
try
DZ := FontPixelToV(AFontPixel);
lblTmp.Color := clBlack;
lblTmp.Font.Color := clRed;
case AFontPixel of
fp16: lblTmp.Font.Size := 11;
fp24: lblTmp.Font.Size := 16;
fp32: lblTmp.Font.Size := 22;
else
lblTmp.Font.Size := 11;
end;
// 取入参的字长。
lblTmp.Caption := AText;
lblTmp.AutoSize := true;
lblTmp.Height := DZ;
bm1.Width := lblTmp.Width;
bm1.Height := lblTmp.Height;
bm1.Canvas.Brush.Color := clBlack;
bm1.Canvas.FillRect(Rect(0, 0, bm1.Width, bm1.Height));
bm1.Canvas.Font := lblTmp.Font;
bm1.Canvas.TextRect(Rect(0, 0, bm1.Width, bm1.Height), 0, 0, AText);
absPos := 0;
FCol := floor(bm1.Width / 8 + 0.5);
FRow := bm1.Height;
SetLength(dynTmp, FRow); // 第一维是行值。
for i := 0 to FRow - 1 do
begin[red]
SetLength(dynTmp, FCol); // 第二维是列值。
{
这儿老出错,当 I 到 3 时,出错,,扯拐,,是啥原因哦?
我实在是搞不懂了,请教请教,。。
}[/red]
for j := 0 to bm1.Width - 1 do
begin
if bm1.Canvas.Pixels[j, i] = clBlack then
begin
dynTmp[i, i * j + j div 8] := dynTmp[i, i * j + j div 8]
and (not ($80 shr (j - (j div 8) * 8)));
end
else
begin
dynTmp[i, i * j + j div 8] := dynTmp[i, i * j + j div 8]
or ($80 shr (j - (j div 8) * 8));
end;
inc(absPos);
end;
end;
//////////
// 把已经得到的位信息数据拷贝到 Result 中。
GetMem(Result, FRow * FCol);
for i := 0 to FRow - 1 do
for j := 0 to FCol - 1 do
Result[i * j + j] := Char(dynTmp[i, j]);
finally
lblTmp.Free;
bm1.Free;
end;
end;