UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on January 01, 2006, 06:59:00 PM

Title: Create Picture collage
Post by: kevin on January 01, 2006, 06:59:00 PM
  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..


[pbcode]
   ; 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

[/pbcode]


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


Title: Create Picture collage + SaveImage
Post by: kevin on January 01, 2006, 07:02:31 PM
Eg it creates this type of image
Title: Create Picture collage + SaveImage
Post by: stef on January 02, 2006, 10:34:54 AM
Hi Kevin!

Looks interesting! Can need this.

Greetings
stef

PS.: Can you post the code of '3DRenderEngineDemo'?
Title: Create Picture collage + SaveImage
Post by: thaaks on January 02, 2006, 03:09:24 PM
Hmmm, could also be used to create animation strips...

Thanks for the code!

Man, I can learn a lot these days  :D
Title: Re: Create Picture collage + SaveImage
Post by: Adaz on February 06, 2008, 02:39:47 AM
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?
Title: Re: Create Picture collage
Post by: kevin on February 06, 2008, 09:49:49 AM

  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.