Einzelnen Beitrag anzeigen

Benutzerbild von olee
olee

Registriert seit: 16. Feb 2008
Ort: Boppard
540 Beiträge
 
Turbo Delphi für Win32
 
#61

Re: [GAME] Bloggy [ALPHA Version 0.6] (Multiplayer.?.)

  Alt 4. Mär 2008, 22:15
@3_of_8 : Also bei mir lädt der das Bild nur in einen Pointer oder so. Hab keine ahnung, in welchem Format der das in dem Pointer speichert.

Delphi-Quellcode:
var
  FileHeader: TBITMAPFILEHEADER; // was FileHeader: BITMAPFILEHEADER; undeclared identifier
  InfoHeader: TBITMAPINFOHEADER; // was InfoHeader: BITMAPINFOHEADER; undeclared identifier
  Palette: array [byte] of TRGBQUAD; // Palette: array of RGBQUAD; declaration of array not supported by D2 and undeclared identifier RGBQUAD
  BitmapFile: THandle;
  BitmapLength: Integer; // changed from variant
  PaletteLength: Integer; // '' '' ''
  ReadBytes: Integer; // changed for incompatibility whith declaration of Win function Readfile
  Front: ^Byte;
  Back: ^Byte;
  Temp: Byte;
  I : Integer;
  Width, Height : Integer;
  pData : Pointer;

  // used for loading from resource
  ResStream : TResourceStream;
begin

[.....................]
    BitmapFile := CreateFile(PChar(Filename), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);
    if (BitmapFile = INVALID_HANDLE_VALUE) then begin
      MessageBox(0, PChar('Error opening ' + Filename), PChar('BMP Unit'), MB_OK);
      Exit;
    end;

    // Get header information
    ReadFile(BitmapFile, FileHeader, SizeOf(FileHeader), ReadBytes, nil);
    ReadFile(BitmapFile, InfoHeader, SizeOf(InfoHeader), ReadBytes, nil);

    // Get palette
    PaletteLength := InfoHeader.biClrUsed;
    //SetLength(Palette, PaletteLength); commented by fabrizio ( i don't know how to solve !!)
    ReadFile(BitmapFile, Palette, PaletteLength, ReadBytes, nil);
    if (ReadBytes <> PaletteLength) then begin
      MessageBox(0, PChar('Error reading palette'), PChar('BMP Unit'), MB_OK);
      Exit;
    end;

    Width := InfoHeader.biWidth;
    Height := InfoHeader.biHeight;
    BitmapLength := InfoHeader.biSizeImage;
    if BitmapLength = 0 then
      BitmapLength := Width * Height * InfoHeader.biBitCount Div 8;

    // Get the actual pixel data
    GetMem(pData, BitmapLength);
    ReadFile(BitmapFile, pData^, BitmapLength, ReadBytes, nil);
    if (ReadBytes <> BitmapLength) then begin
      MessageBox(0, PChar('Error reading bitmap data'), PChar('BMP Unit'), MB_OK);
      Exit;
    end;
    CloseHandle(BitmapFile);
  end;

  // Bitmaps are stored BGR and not RGB, so swap the R and B bytes.
  for I :=0 to Width * Height - 1 do
  begin
    Front := Pointer(Integer(pData) + I*3);
    Back := Pointer(Integer(pData) + I*3 + 2);
    Temp := Front^;
    Front^ := Back^;
    Back^ := Temp;
  end;
Hier mal der relevante Code der laden-funktion.
Björn Zeutzheim
Codename: Performancepumpe
  Mit Zitat antworten Zitat