9
Ricevo questo errore scaricando un'immagine tramite HTTP. Ho visto lo answer here ma anche le immagini valide non restituiscono YES
dalla funzione.ImageIO: <ERROR> JPEG Dati JPEG danneggiati: fine prematura del segmento di dati iphone - come prendere questo?
Altre idee?
Il codice per ottenere l'immagine è abbastanza semplice. Questo succede in un thread in background.
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
UIImage *image = [UIImage imageWithData:data];
Questa è la funzione da quel filo:
- (BOOL)isJPEGValid:(NSData *)jpeg {
if ([jpeg length] < 4) return NO;
const char * bytes = (const char *)[jpeg bytes];
if (bytes[0] != 0xFF || bytes[1] != 0xD8) return NO;
if (bytes[[jpeg length] - 2] != 0xFF ||
bytes[[jpeg length] - 1] != 0xD9) return NO;
return YES;
}
+1 grazie, Sigi! – Jean
Sì, sembra funzionare. Grazie! – jmosesman
Viene ancora visualizzato l'errore:: ImageIO: JPEG Dati JPEG corrotti: fine prematura del segmento di dati. :( –