Results 1 to 2 of 2

Thread: Can i view jpg or bmp with simba?

  1. #1
    Join Date
    Sep 2007
    Location
    British Columbia, Canada
    Posts
    4,047
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default Can i view jpg or bmp with simba?

    I just wanna make a random picture opener with simba (I is really bored).
    I got like 900 + pictures named with increasing integer (some of them are continous art, others are pure random), and I'd like to be able to make a random picture viewer hopefully in debug window or something.
    Last edited by Main; 08-28-2011 at 06:48 AM.
    Oh Hai Dar

  2. #2
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    This can show how to load images and whatnot. You could prob make a form with buttons and crap...

    Simba Code:
    program new;

    const
      Dir = 'C:\Users\Dgby714\Pictures\';

    function AppendArray(Prefix: string; Arr: TStringArray; Suffix: string): TStringArray;
    var
      P, I: integer;
    begin
      SetLength(Result, Length(Arr));
      P := High(Arr);
      for I := 0 to P do
        Result[I] := Prefix + Arr[I] + Suffix;
    end;

    function GetFilesR(Dir, Ext: string): TStringArray;
    var
      TempArr: TStringArray;
      P, I: integer;
    begin
      if (not (Dir[Length(Dir)] = '\')) then
        Dir := Dir + '\';

      if (not (DirectoryExists(Dir))) then
        Exit;

      Result := Result + AppendArray(Dir, GetFiles(Dir, Ext), '');

      TempArr := AppendArray(Dir, GetDirectories(Dir), '\');
      P := High(TempArr);

      for I := 0 to P do
        Result := GetFilesR(TempArr[I], Ext);
    end;

    procedure RemoveArrIndex(Index: integer; var Arr: TStringArray);
    var
      I, P: integer;
    begin
      if (not (InRange(Index, Low(Arr), High(Arr)))) then
        Exit;
      P := High(Arr);
      for I := Index + 1 to P do
        Arr[I - 1] := Arr[I];
      SetArrayLength(Arr, Length(Arr) - 1);
    end;

    function GetImages(): TStringArray;
    var
      ImageExts: TStringArray;
      Found: Boolean;
      H, I, J, K, C: LongInt;
    begin
      Result := GetFilesR(Dir, '*');

      ImageExts := ['bmp', 'jpg', 'png'];
      H := High(Result);
      for I := H downto 0 do
      begin
        Found := False;
        J := High(ImageExts);
        for K := 0 to J do
        begin
          C := Length(ImageExts[K]);
          if (Copy(Result[I], Length(Result[I]) - C, C + 1) = '.' + ImageExts[K]) then
          begin
            Found := True;
            Break;
          end;
        end;

        if (Found) then
          Continue;

        RemoveArrIndex(I, Result);
      end;
    end;

    var
      CurPath: string;
      CurBmp, W, H, L: LongInt;
      Images: TStringArray;

    begin
      Images := GetImages();
      L := Length(Images);
      WriteLn('Loaded ' + IntToStr(L) + ' Images!');
      if (L = 0) then
        Exit;

      repeat
        CurPath := Images[Random(L)];
        WriteLn('Showing ' + CurPath + '!');
        CurBmp := LoadBitmap(CurPath);
        GetBitmapSize(CurBmp, W, H);
        DisplayDebugImgWindow(W, H);
        DrawBitmapDebugImg(CurBmp);
        FreeBitmap(CurBmp);
        Wait(1000);
        while (not IsKeyDown(VK_SPACE)) do
          Wait(100);
      until(False);
    end.
    Last edited by Dgby714; 08-28-2011 at 09:16 AM.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •