Author Topic: Picture viewer  (Read 3600 times)

0 Members and 1 Guest are viewing this topic.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Picture viewer
« on: March 10, 2020, 08:20:53 pm »
In the not-so distant past a picture viewer was an essential thing
everyone had to download.  Look how EASY it is with QB64!  37 lines!

Change the directory to where your picture files are, and "q" to how
many rows per page.

I wanted to post this over in Sample - 2D Graphics, but I can't post there.

Code: QB64: [Select]
  1. _TITLE "Pix" '                              Display all the picture files in a directory
  2. DEFINT A-Z
  3. DIM f$(2000): xm = 1280: ym = 800: p$ = "\pix\cars\": d$ = "temp.dir": c$ = "dir " + p$ + " > \qb64\" + d$
  4.     LINE INPUT #1, t$: t$ = LCASE$(t$)
  5.     IF (LEN(t$) > 4) AND (INSTR("jpg gif png bmp", RIGHT$(t$, 3))) THEN
  6.         nf = nf + 1
  7.         f$(nf) = RIGHT$(t$, LEN(t$) - 39)
  8.     END IF
  9. begin: m& = _NEWIMAGE(xm, ym, 32): _DELAY .3: IF m& >= -1 THEN GOTO begin
  10. q = 10: q = ym \ q: x1 = (xm / q - INT(xm / q)) * q / 2: x = x1: y = 0
  11.     DO
  12.         nextfile: n = n + 1: IF n > nf THEN n = 1
  13.         f$ = p$ + f$(n): t = 0
  14.         tryagain:
  15.         IF LEN(INKEY$) THEN SYSTEM
  16.         t = t + 1: i& = _LOADIMAGE(f$)
  17.         IF (i& >= -1) AND (t < 3) THEN GOTO tryagain
  18.         IF (i& >= -1) THEN GOTO nextfile
  19.         _PUTIMAGE (x, y)-(x + q, y + q), i&, 0
  20.         _FREEIMAGE i&
  21.         _PRINTSTRING (x, y), LTRIM$(STR$(n))
  22.         x = x + q
  23.         IF (x + q) > xm THEN
  24.             x = x1: y = y + q
  25.             IF (y + q) > ym THEN EXIT DO
  26.         END IF
  27.     LOOP
  28.     DO: _LIMIT 10: i$ = INKEY$: IF i$ = CHR$(27) THEN SYSTEM
  29.     LOOP UNTIL LEN(i$): x = x1: y = 0: CLS
  30.  
It works better if you plug it in.