onlyou13

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
function GetNumberBuffer(cZi: string; cwidth, cheight: Integer; FontName: string; bold, italic: Boolean): TDataBytes;
var
  col, row: Integer;
  cw, ch, cleft, ctop: Integer;
  style: TFontStyle;
begin
  with TBitmap.Create do
  try
    SetSize(cwidth, cheight);
    PixelFormat := pf32bit;
    cw := Canvas.TextWidth(cZi);
    ch := Canvas.TextHeight('01234567890.');
    cleft := (cwidth - cw) div 2;
    ctop := (cheight - ch) div 2;
    if bold then Canvas.Font.Style := Canvas.Font.Style + [fsBold];
    if italic then Canvas.Font.Style := Canvas.Font.Style + [fsItalic];
    Canvas.TextOut(cleft, ctop, cZi);

    SetLength(Result, Width, Height);
    for col := 0 to Width - 1 do
      for row := 0 to Height - 1 do
        if Canvas.Pixels[col, row] = 0 then
          Result[col, row] := 1
        else Result[col, row] := 0;
  finally
    Free;
  end;
end;

 

posted on 2019-09-02 15:33  onlyou13  阅读(185)  评论(0编辑  收藏  举报