2012-03-07 15 views
6

Sto cercando di ottenere il numero di fotogrammi al secondo da un file gif, Sto convertendo il file gif in NSData e quindi da quel NSData prendo un array di frame usando questo codice: - (NSMutableArray *) getGifFrames: (NSData *) dati {come posso ottenere il numero di frame al secondo da un file GIF?

NSMutableArray *frames = nil; 
CGImageSourceRef src = CGImageSourceCreateWithData((CFDataRef)data, NULL); 
if (src) { 
    size_t l = CGImageSourceGetCount(src); 
    frames = [NSMutableArray arrayWithCapacity:l]; 
    for (size_t i = 0; i < l; i++) { 
     CGImageRef img = CGImageSourceCreateImageAtIndex(src, i, NULL); 
     if (img) { 
      [frames addObject:[UIImage imageWithCGImage:img]]; 
      CGImageRelease(img); 
     } 
    } 
    CFRelease(src); 
} 
return frames; 

}

c'è qualche cosa che posso ottenere l'FPS del gif? Grazie

risposta

10

Un file GIF non contiene un valore FPS, ma ogni frame contiene una durata.

Ogni frame contiene un'intestazione.

Numero byte esadecimale 324 contiene la durata del fotogramma in centesimi di secondo, ad esempio 09 00 sarebbe 0,09 secondi.

EDIT: riferimento http://en.wikipedia.org/wiki/Graphics_Interchange_Format#Animated_GIF

+2

vuol dire una GIF ha effettivamente un frame rate variabile? – rjstelling

+1

@rjstelling si esattamente – AnthonyBlake

+1

Grazie per la risposta! – Legnus

Problemi correlati