码迷,mamicode.com
首页 > 其他好文 > 详细

png

时间:2020-03-25 23:23:36      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:procedure   logs   split   data   private   desktop   mfile   ext   with   

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Types;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function HexToInt(hex: string): integer;
var
  i: integer;
  function Ncf(num, f: integer): integer;
  var
    i: integer;
  begin
    Result := 1;
    if f = 0 then
      exit;
    for i := 1 to f do
      result := result * num;
  end;

  function HexCharToInt(HexToken: char): integer;
  begin
    if HexToken > #97 then
      HexToken := Chr(Ord(HexToken) - 32);
    Result := 0;
    if (HexToken > #47) and (HexToken < #58) then { chars 0....9 }
      Result := Ord(HexToken) - 48
    else if (HexToken > #64) and (HexToken < #71) then { chars A....F }
      Result := Ord(HexToken) - 65 + 10;
  end;

begin
  result := 0;
  hex := ansiuppercase(trim(hex));
  if hex = ‘‘ then
    exit;
  for i := 1 to length(hex) do
    result := result + HexCharToInt(hex[i]) * ncf(16, length(hex) - i);
end;

procedure ReadFile;
var
  filestr: string;
  xDataS: TArray<string>;
  xDataB: TArray<Byte>;
  xDataB2: TArray<Byte>;
  I, j: Integer;
  found: Boolean;
const
  arrchar: array[0..0] of Char = (,);
begin
  filestr := C:\Users\Administrator\Desktop\1.txt;

  with TStringList.Create do
  begin
    LoadFromFile(filestr);
    filestr := Text;
  end;

  xDataS := filestr.Split(arrchar);
  SetLength(xDataB, Length(xDataS));
  SetLength(xDataB2, Length(xDataS));
  for I := Low(xDataS) to High(xDataS) do
  begin
    xDataB[I] := HexToInt(xDataS[I]); //strtoint(‘$‘ + xDataS[I]);
  end;

  found := False;
  j := 0;
  for I := Low(xDataB) to High(xDataB) do
  begin
    if (xDataB[I] = $89) and (xDataB[I + 1] = $50) then
    begin
      xDataB2[j] := xDataB[I];
      Inc(j);
      found := True;
      Continue;
    end;

    if not found then
      Continue;
    xDataB2[j] := xDataB[I];
    Inc(j);

    if found and (xDataB[I] = $60) and (xDataB[I + 1] = $82) then
    begin
      xDataB2[j + 1] := xDataB[I + 1];
      Break;
    end;
  end;

  with TFileStream.Create(d:\test.png, fmCreate) do
  begin
    write(@xDataB2[0], Length(xDataB2));
    Free;
  end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ReadFile;
end;

end.

 

png

标签:procedure   logs   split   data   private   desktop   mfile   ext   with   

原文地址:https://www.cnblogs.com/onlyou13/p/12571205.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!