Page 1 of 1

Gif frames to new image?

Posted: Sat Jul 22, 2017 8:44 pm
by vwidmer
I am trying to load a gif from memory and create a new image.

Example:
GIFIMG1 has 200 frames
I want to create a new image GIFIMG2 with frames 20-30 from GIFIMG1

Right now I am just trying to even copy one but it is my first time working with images in PB maybe some one can help me and or point me in the right direction. Thanks

Code: Select all

UseGIFImageDecoder()

;- DataSection
DataSection
  GIFIMG1:
  IncludeBinary "a.gif"
EndDataSection

#imgRaw=1
#imgCut=2

Procedure Gif2NewIMG()
  
  CatchImage(#imgRaw, ?GIFIMG1)
  
  CreateImage(#imgCut,150, 150)
  StartDrawing(ImageOutput(#imgCut))
  SetImageFrame(#imgRaw, 100)
  AddImageFrame(#imgCut, ImageFrameCount(#imgCut)-1)
  SetImageFrame(#imgCut, ImageFrameCount(#imgCut)-1)
  CopyImage(#imgRaw, #imgCut)
  DrawImage(ImageID(#imgCut), 0,0)
  StopDrawing()
EndProcedure

OpenWindow(0, 100, 100, 400, 400, "")
 
  imgG = ImageGadget(#PB_Any, 0, 0, 150, 150,0)
  AddWindowTimer(0, 1, 150)
  
  Gif2NewIMG()
  Debug "Now there is " + Str(ImageFrameCount(#imgRaw)) + " frames"
    Debug "Now there is " + Str(ImageFrameCount(#imgCut)) + " frames"
 
 ;Frame=120
  Repeat
    Event = WaitWindowEvent()
   
    If Event = #PB_Event_Timer
      SetImageFrame(#imgCut, Frame)
      Frame+1
      If Frame >= ImageFrameCount(#imgCut)
       
      Frame = 0 : EndIf
     
     
      SetGadgetState(imgG,ImageID(#imgCut))
    EndIf
   
  Until Event = #PB_Event_CloseWindow

Re: Gif frames to new image?

Posted: Sat Jul 22, 2017 10:16 pm
by codeit
There is a website that you can upload your gif and it splits it up for you.
https://ezgif.com/split

hope this helps

Re: Gif frames to new image?

Posted: Sat Jul 22, 2017 10:23 pm
by vwidmer
Yes I found lots of sites that can do that. I was hoping to do it in PB
thanks

Re: Gif frames to new image?

Posted: Sat Jul 22, 2017 11:55 pm
by JHPJHP
Removed; post ignored.

Re: Gif frames to new image?

Posted: Sun Jul 23, 2017 1:00 am
by vwidmer
Well this is what I came up with.. Probably not the best but kinda sorta sometimes work :)

Code: Select all

UseGIFImageDecoder()

#imgRaw=1
#imgCut=2
#imgBuf=3

Procedure FrameSlicer(fsStart.i,fsEnd.i,fsX.i,fsY.i)
  LoadImage(#imgRaw, "a.gif")
  
  CreateImage(#imgCut, fsX, fsY)
  
  SetImageFrame(#imgRaw, fsStart)
  ResizeImage(#imgRaw,fsX,fsY)
  CopyImage(#imgRaw, #imgBuf)
  
  StartDrawing(ImageOutput(#imgCut))
  DrawImage( ImageID(#imgBuf), 0,0)
  StopDrawing()
  
  For i = (fsStart + 1) To fsEnd
  FreeImage(#imgRaw)
  LoadImage(#imgRaw, "a.gif")
  FreeImage(#imgBuf)
  SetImageFrame(#imgRaw, i)
  ResizeImage(#imgRaw,fsX,fsY)
  CopyImage(#imgRaw, #imgBuf)
  
  AddImageFrame(#imgCut)
  StartDrawing(ImageOutput(#imgCut))
  DrawImage( ImageID(#imgBuf), 0,0)
  StopDrawing()
  Next i
EndProcedure

;Select frames from 100 to 110 with image size of 150 x 150
FrameSlicer(100,110,150,150)