January 26, 2021, 06:27:18 AM

Author Topic: [bb] Seq2Stripv1.0 by Russell [ 1+ years ago ]  (Read 646 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Seq2Stripv1.0 by Russell [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Seq2Stripv1.0
Author : Russell
Posted : 1+ years ago

Description : If you create an animation in, say, a 3D program that saves as individual files, this will assemble them all into one file to be used with LoadAnimImage().

It's very simple, but effective. Hope you find it useful!
Russell


Code :
Code: BlitzBasic
  1. Graphics 640,480,16,2
  2. .Beginning
  3. Cls
  4. sImageSeq$ = Input$("Image sequence, minus index and extension. (ex: Pic NOT Pic000.bmp)")
  5.  
  6. .GetExt
  7. sImageExt$ = Lower$(Input$("Input file type ( bmp, jpeg/jpg, or png ONLY)"))
  8. If sImageExt$ <> "bmp" And sImageExt$ <> "jpg" And sImageExt$ <> "jpeg" And sImageExt$ <> "png" Then Goto GetExt
  9.        
  10. .GetDigits
  11. iNumDigits = Input$("Number of digits (1-3 ONLY ex: 3 for Pic000, etc)")
  12. If iNumDigits > 3 Then Goto GetDigits
  13.  
  14. .GetFrames
  15. iTotFrames = Input$("Number of frames in sequence (1-" + 10^iNumDigits + ")")
  16. If iTotFrames > (10^iNumDigits) Then Goto GetFrames
  17. Print "Ready to process? Press any key to process..."
  18. WaitKey()
  19. sFileName$ = sImageSeq$ + String$("0",iNumDigits) + "." + sImageExt$
  20. If FileType(sFileName$) = 0 Then
  21.         Cls
  22.         Print "File not found! Press any key..."
  23.         WaitKey()
  24.         Goto Beginning
  25. EndIf
  26.  
  27. imgFirst = LoadImage(sFileName$)
  28. testvalid = ImageWidth(imgFirst) * iTotFrames
  29. If testvalid > 32000 Then
  30.         Cls
  31.         Print "Resulting image would be too big! (" + testvalid + " pixels wide" + ")"
  32.         Print "Press any key..."
  33.         WaitKey()
  34.         Goto Beginning
  35. EndIf
  36.        
  37. testvalid = ImageHeight(imgFirst)
  38. If testvalid > 32000 Then
  39.         Cls
  40.         Print "Resulting image would be too big! (" + testvalid + " pixels wide" + ")"
  41.         Print "Press any key..."
  42.         WaitKey()
  43.         Goto Beginning
  44. EndIf
  45.  
  46. tmpBuffer = CreateImage( ImageWidth(imgFirst) * iTotFrames, ImageHeight(imgFirst) )
  47. If Not tmpBuffer Then RuntimeError "Couldn't create buffer for image!"
  48. Cls
  49. Print "I will use " + sImageSeq$ + String$("0",iNumDigits) + "." + sImageExt$ + " as the first frame. Anykey..."
  50. WaitKey()
  51. SetBuffer ImageBuffer(tmpBuffer)
  52. For i = 0 To (iTotFrames - 1)
  53.         index$ = Str i
  54.         index$ = RSet$(index$,iNumDigits)
  55.         index$ = Replace$(index$," ","0")
  56.        
  57.         tmpImage = LoadImage(sImageSeq$ + index$ + "." + sImageExt$)
  58.         DrawBlock tmpImage, x, 0
  59.         x = x + ImageWidth(imgFirst)
  60.         FreeImage tmpImage
  61. Next
  62.  
  63. SaveImage(tmpBuffer, sImageSeq$ + ".bmp")
  64. Cls
  65. Print "Done! Saved as '" + sImageSeq$ + ".bmp'. Press any key for anim demo! (escape to quit)"
  66. Print "Use up and down to speed up or slow down the frame rate"
  67. WaitKey()
  68.  
  69. FreeImage tmpBuffer
  70. AnimSequence = LoadAnimImage(sImageSeq$ + ".bmp", ImageWidth(imgFirst),ImageHeight(imgFirst),0,iTotFrames-1)
  71. FreeImage imgFirst
  72.  
  73. While Not KeyDown(1)
  74.         SetBuffer BackBuffer()
  75.         Cls
  76.         DrawImage AnimSequence, MouseX(), MouseY(), frame
  77.         frame = frame + 1
  78.         If frame = (iTotFrames - 1) Then frame = 0
  79.         Delay iDelay
  80.        
  81.         If KeyDown(200) Then
  82.                 iDelay = iDelay - 20
  83.                 If iDelay < 0 Then iDelay = 0
  84.         Else If KeyDown(208) Then
  85.                 iDelay = iDelay + 20
  86.         EndIf
  87.        
  88.         Flip
  89. Wend
  90. End


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal