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.
Dgby714
08-28-2011, 08:51 AM
This can show how to load images and whatnot. You could prob make a form with buttons and crap...
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.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.