Einzelnen Beitrag anzeigen

Benutzerbild von Khabarakh
Khabarakh

Registriert seit: 18. Aug 2004
Ort: Brackenheim VS08 Pro
2.876 Beiträge
 
#5

Re: Mehrere Bilder in den RAM laden - Array, ImageList oder

  Alt 12. Jun 2005, 13:52
Nagut, hier noch der Rest: Ich verwende eine globale Variable, STOP, bitte nicht hauen, das ist auch die einzige in allen 10 Units und einfach schnell und unkompliziert .
Delphi-Quellcode:
type
  TBitmapCollection = class
  private
    FBitmapList: TObjectList;
    FNameList: TStringList;
    function GetBitmap(AName: string): TBitmap32;
    procedure LoadGraphicRessources;
  public
    constructor Create;
    destructor Destroy; override;

    procedure Add(ABit: TBitmap32; AName: string);
    function AddNew(AName: string): TBitmap32;

    property Bitmap[AName: string]: TBitmap32 read GetBitmap; default;
  end;

var
  BitmapCollection: TBitmapCollection;

implementation

{ TBitmapCollection }

function TBitmapCollection.GetBitmap(AName: string): TBitmap32;
begin
  Result := TBitmap32(FBitmapList.Items[FNameList.IndexOf(AName)]);
end;

procedure TBitmapCollection.Add(ABit: TBitmap32; AName: string);
begin
  FBitmapList.Add(ABit);
  FNameList.Add(AName);
end;

function TBitmapCollection.AddNew(AName: string): TBitmap32;
begin
  Result := TBitmap32.Create;
  Add(Result, AName);
end;

destructor TBitmapCollection.Destroy;
begin
  FBitmapList.Free;
  FNameList.Free;
  inherited;
end;

constructor TBitmapCollection.Create;
begin
  inherited;
  FBitmapList := TObjectList.Create;
  FNameList := TStringList.Create;
  LoadGraphicRessources;
end;

procedure TBitmapCollection.LoadGraphicRessources;
var
  Stream: TFileStream;
  Alpha: Boolean;
begin
  try
    Stream := TFileStream.Create('Graphics.prr', fmOpenRead);

    LoadPNGintoBitmap32(AddNew('Hugo'), Stream, Alpha);
    LoadPNGintoBitmap32(AddNew('Helmut'), Stream, Alpha);
    LoadPNGintoBitmap32(AddNew('Hannes'), Stream, Alpha);
    LoadPNGintoBitmap32(AddNew('Hannah'), Stream, Alpha);
  finally
    Stream.Free;
  end;
end;

initialization

  BitmapCollection := TBitmapCollection.Create;

finalization

  BitmapCollection.Free;
end.
Sebastian
Moderator in der EE
  Mit Zitat antworten Zitat