2012-07-07 20 views
5
[[[globalSingleton paintingView] drawingView] setOpaque:NO]; 
[[[[globalSingleton paintingView] drawingView] layer] setOpaque:NO];  
[[[globalSingleton paintingView] drawingView] setBackgroundColor:[UIColor clearColor]]; 
[[[[globalSingleton paintingView] drawingView] layer] setBackgroundColor:[UIColor clearColor].CGColor]; 

[[[[globalSingleton paintingView] drawingView] layer] renderInContext:ctx]; 

UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext(); 

Il codice sopra è quello che sto usando per salvare il mio 'drawingView' in un file png. Ho trovato diverse domande e risposte, quindi le ho applicate. Ho impostato l'opaco del mio 'drawingView' e drawingView.layer come NO e ho impostato il colore di sfondo del mio 'drawingView' come [UIColor clearColor]. Penso di aver applicato tutte le risposte da StackOverflow. Tuttavia, non è cambiato nulla. Lo sfondo di png fil è ancora nero. Ho bisogno di uno sfondo trasparente, non nero !!salva UIView come file png con sfondo trasparente

Ho provato se c'è qualche problema con UIImage * image1. Ho usato image1 per mostrare sullo schermo, quindi ho potuto trovare lo sfondo nero da quella immagine1. Quindi posso immaginare che ci sia qualche problema durante la creazione di image1.

Questo è tutto ciò che ho trovato. C'è qualche soluzione possibile per salvare la mia immagine png con un'immagine di sfondo trasparente? Grazie in anticipo!!

risposta

8

Oh, dio! L'ho fatto!! Ho aggiunto [[UIColor clearColor] set]; . È tutto.

UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, [[UIScreen mainScreen] scale]); 

CGContextRef ctx = UIGraphicsGetCurrentContext(); 
[[UIColor clearColor] set]; 
CGContextFillRect(ctx, screenRect); 

[[[globalSingleton paintingView] drawingView] setOpaque:NO]; 
[[[[globalSingleton paintingView] drawingView] layer] setOpaque:NO];  
[[[globalSingleton paintingView] drawingView] setBackgroundColor:[UIColor clearColor]]; 
[[[[globalSingleton paintingView] drawingView] layer] setBackgroundColor:[UIColor clearColor].CGColor]; 

[[[[globalSingleton paintingView] drawingView] layer] renderInContext:ctx]; 

UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext(); 
Problemi correlati