png

Posted onlyou13

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了png相关的知识,希望对你有一定的参考价值。

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:UsersAdministratorDesktop1.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:	est.png, fmCreate) do
  begin
    write(@xDataB2[0], Length(xDataB2));
    Free;
  end;

end;

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

end.

 

以上是关于png的主要内容,如果未能解决你的问题,请参考以下文章

EasyClick 运行代码片段出Null

我可以将.png数据转换为Swift中的Int吗?

Javascript 从音轨中选择片段

Android - 加载drawables而不跳帧

合并两个位图的问题

微信小程序代码片段