News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Create Picture collage

Started by kevin, January 01, 2006, 06:59:00 PM

Previous topic - Next topic

kevin

  This snippet loads some pictures from the current folder (assuming Jpgs,Png or Bmp) into memory and randomly makes collage out of them.  You can set the thumb scale sizes in the code.


  NOTE: You'll need a folder of pictures to test this..


PlayBASIC Code: [Select]
   ; updated version for PB1.63,   7th,Feb,2008 

#include "saveBitmap"


; A folder with a bunch of pictures to load
PicturePath$="D:\Play_Basic\ScreenShots\"

cd PicturePath$
ReadDir PicturePath$,"",false,true

Dim Pictures$(1)

Size=getDirsize()
For lp=0 to size -1
if getdirfiletype(lp)=1
f$=GetDirFile$(lp)
e$=lower$(GetFileext$(f$))
if e$="jpg" or e$="png" or e$="bmp"
inc Files
Redim Pictures$(files)
Pictures$(files)=f$
endif
endif
next


PIcsWide=5
PicsHigh=5

Width=128
Height=Width*0.75

CreateFXIMage 100,Width*PicsWide,Height*PicsHigh


; randomly select the pictures from the number of pics avail.

NumbOfAvailPictures =getArrayelements(pictures$(),1)
PicturesRemaining =NumbOfAvailPictures



Repeat
lp=rnd(NumbOfAvailPictures)
File$=Pictures$(lp)
if file$<>""
Pictures$(lp)=""
Cls 0
print "loading "+file$+" "+str$(PicturesLoaded)+" of "+str$(PicsWide*PicsHigh)
inc PicturesLoaded
dec PicturesRemaining

Img=GetFreeimage()
LoadFXIMAGE File$,img
ScaleImage img,Width,Height,1
RendertoIMage 100
DrawImage img,Xpos,Ypos,0
deleteimage Img

inc TileX
if TileX>(PicsWide-1)
TileX=0
Xpos=0
Ypos=yPOs+height
Inc TileY
if TileY=PIcsHigh then exit
else
Xpos=Xpos+width
endif
rendertoscreen
Sync
endif
until PicturesLoaded=>NumbOfAvailPictures or PicturesRemaining<1




file$=currentdir$()+"Collage.bmp"

SaveBitMap(File$,100)
rendertoscreen
cls 0
drawimage 100,0,0,0
print "Saved:"+file$
print "DONE"
sync
waitkey





Note: This code was updated for PB1.63 (7th,Feb,2008)  



kevin

Eg it creates this type of image

stef

Hi Kevin!

Looks interesting! Can need this.

Greetings
stef

PS.: Can you post the code of '3DRenderEngineDemo'?

thaaks

Hmmm, could also be used to create animation strips...

Thanks for the code!

Man, I can learn a lot these days  :D

Adaz

Does this example work at all?
Playbasic unfortunately doesn't support gif's, so this program will never load such file.
Furthermore it crashes with an error, because of the line "PrepareFXImage fx". It sould be "PrepareFXImage lp". Has anybody tried this example besides me?

Ádáz

Hungary

kevin


  Obviously running code from Jan,2006 (ie PB1.089 era) in modern editions of PB can be problematic.  In particular when there's errors in the code.  Anyway, i've done a quick rehash of the snippet.  It now randomly chooses the pictures from folder it's provided rather than just stepping through the list.