Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#8

AW: Alternative für String Assign

  Alt 23. Mär 2017, 11:01
Hier mal mein Code
Ich versuche die PNG Datei Binär zu lesen.

Delphi-Quellcode:
function TAnimatePng.FLof(hFile: THandle): DWORD;
var
  dwFileSize: DWORD;
begin
  dwFileSize := 0;

  if hFile <> 0 then
  begin
    if GetFileType(hFile) = FILE_TYPE_DISK then
    begin
      dwFileSize := GetFileSize(hFile, nil);
      if dwFileSize = INVALID_FILE_SIZE then
        dwFileSize := 0;
    end;
  end;
  result := dwFileSize;
end;
Delphi-Quellcode:
function TAnimatePng.FSeek(hFile: THandle; PosByte: DWord): LongInt;
var
  li: integer;
begin

  li := PosByte;
  Result := 0;
  if SetFilePointer(hFile, li, nil, FILE_BEGIN) < 0 then
    Result := GetLastError();
end;
Delphi-Quellcode:
function TAnimatePng.FGet(hFile: THandle; var sBuffer: string): LongInt;
var
  ByttesReaded: DWORD;
  LenBuf: DWORD;
begin

  Result := 0;
  if hFile <> 0 then
  begin
    ByttesReaded := 0;
    LenBuf := Length(sBuffer);
    if LenBuf <> 0 then
    begin
      if ReadFile(hFile, sBuffer, LenBuf, ByttesReaded, 0) = false then
        Result := GetLastError();
    end;
  end;
end;
Delphi-Quellcode:
function TAnimatePng.FGetAt(hFile: THandle; PosByte: DWORD; var sBuffer: string): LongInt;
var
  ErrCode: LongInt;
begin

  ErrCode := 0;

  ErrCode := FSeek(hFile, PosByte);
  if ErrCode = 0 then
    ErrCode := FGet(hFile, sBuffer);
  result := ErrCode;
end;
Delphi-Quellcode:
BufferSize := FLof(hFileIn) - anih.offset - sizeof(anih) + 1;
SetLength(sBuffer, BufferSize); // ########### Der Anfang
if FGetAt(hFileIn, anih.offset - 1, sBuffer) = S_OK then
begin
  // sBuffer 2 laden
  Global := GlobalAlloc(GMEM_MOVEABLE or GMEM_NODISCARD, BufferSize);
  if Global <> 0 then
  begin
    pGlobalBuffer := GlobalLock(Global);
    if Assigned(pGlobalBuffer) then
    begin
      MoveMemory(pGlobalBuffer, @sBuffer, BufferSize);
      if CreateStreamOnHGlobal(Global, False, pImageStream) = S_OK then
      begin
        if GDIP_CreateBitmapFromStream(pImageStream, hImage) = S_OK then
        begin
          GDIP_DrawImageRectI(Graphics, hImage, anih.Width, 0,
            anih.Width * anih.Frame - anih.Width, anih.Height);
          GDIP_DisposeImage(cardinal(hImage));
        end;
        pImageStream := nil;
      end;
      GlobalUnlock(Cardinal(pGlobalBuffer));
    end;
    GlobalFree(Global);
  end;
end;
gruss
  Mit Zitat antworten Zitat