2012-05-31 12 views
11

Sto cercando di creare un jpeg progressivo da un oggetto UIImage, questo è il codice che stoCreazione jpeg progressivo su iOS con ImageIO produce risultati a blocchi su dispositivo

NSMutableData *data = [NSMutableData data]; 

NSString *path = [NSHomeDirectory() stringByAppendingPathComponent: @"Library/Caches/test.jpg"]; 

CFURLRef url = CFURLCreateWithString(NULL, (CFStringRef)[NSString stringWithFormat:@"file://%@", path], NULL); 
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypeJPEG, 1, NULL); 
CFRelease(url); 

NSDictionary *jfifProperties = [NSDictionary dictionaryWithObjectsAndKeys: 
           (__bridge id)kCFBooleanTrue, kCGImagePropertyJFIFIsProgressive, 
           nil]; 

NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys: 
          [NSNumber numberWithFloat:.7], kCGImageDestinationLossyCompressionQuality, 
          jfifProperties, kCGImagePropertyJFIFDictionary, 
          nil]; 

CGImageDestinationAddImage(destination, ((UIImage*)object).CGImage, (__bridge CFDictionaryRef)properties); 
CGImageDestinationFinalize(destination); 
CFRelease(destination); 

Questa grande opera durante l'esecuzione in simulatore , ma purtroppo produce risultati grosso/a blocchi sul dispositivo:

chunky/blocky result.

tutte le idee su quello che sta succedendo? tornerei a utilizzare UIImageJPEGRepresentation come ultima risorsa, ho davvero bisogno di JPEG progressivi.

+0

qual è la versione iOS? – Raptor

+0

@ShivanRaptor è stato testato con iOS 5.0 - 5.1.1 –

+0

Sto provando a testare i codici con il mio telefono. Puoi condividere anche il 'test.jpg' che stai utilizzando? – Raptor

risposta

0

Buone notizie: Ho appena testato questo su un iPhone 4 e l'immagine sembra grande:

NSDictionary *jfifProperties = [NSDictionary dictionaryWithObjectsAndKeys: 
@72, kCGImagePropertyJFIFXDensity, 
@72, kCGImagePropertyJFIFYDensity, 
@1, kCGImagePropertyJFIFDensityUnit, 
nil]; 

(utilizzando la nuova sintassi letterale).

Un buon JFIF reference per ciò che significano queste opzioni di densità.

0

Su simulatore iOS è ok come citato da voi.

Ma avete testato su simulatore IOS con display Retina. Per fare ciò, procedere come segue: 1. Avviare il simulatore 2. Passare a "Hardware" -> "Dispositivo" 3. Selezionare un simulatore con display retina e ricontrollarlo.

Se si verifica il problema con il simulatore di ios retina, si ottiene il problema.

Provare a utilizzare un'immagine di risoluzione molto piccola e quindi verificarla sul dispositivo.

Ci sono pochi problemi per mostrare un'immagine ad altissima risoluzione in UIImageView. Si prega di verificare il link indicato di seguito: - High Resolution Image in UIImageView

Problemi correlati