tmytのらくがき

個人の日記レベルです

ひさびさDelphi

procedure TForm1.Button1Click(Sender: TObject);
var
  bmp: TBitmap;
  i,j,n,k: Integer;
  s: String;
begin
  if OpenDialog1.Execute then
  begin
    bmp := TBitmap.Create;
    bmp.LoadFromFile(OpenDialog1.FileName);
    for k := 0 to (bmp.Height div 8) - 1 do
    begin
      s := 'unsigned char name[] = {';
      for j := k * 8 + 0 to k * 8 + 7 do
      begin
        n := 0;
        for i := 0 to 4 do
        begin
          if (bmp.Canvas.Pixels[i, j] = 0) then
            n := n + (1 shl (4 - i));
        end;
        s := s + '0x' + IntToHex(n, 2) + ', ';
      end;
      s := Copy(s, 0, Length(s) - 1) + '};';
      Memo1.Lines.Add(s);
    end;
    bmp.Free;
  end;
end;