2012-07-07 5 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(); 

Le code ci-dessus est ce que j'utilise pour enregistrer mon 'drawingView' dans un fichier png. J'ai trouvé plusieurs questions et réponses, donc je les ai appliquées. J'ai mis l'opaque de mon 'drawingView' et drawingView.layer comme NON, et définir la couleur de fond de mon 'drawingView' comme [UIColor clearColor]. Je pense que j'ai appliqué toutes les réponses de stackoverflow. Cependant, il n'y a rien de changé. L'arrière-plan de png fil est toujours noir. J'ai besoin d'un fond transparent, pas noir !!enregistrer UIView en tant que fichier png avec fond transparent

J'ai essayé s'il y avait un problème avec UIImage * image1. J'ai utilisé image1 pour montrer sur l'écran, alors je pourrais trouver le fond noir de cette image1. Donc, je pourrais deviner qu'il y a un problème lors de la création de image1.

C'est tout ce que j'ai trouvé. Y at-il une solution possible pour enregistrer mon image png avec une image de fond transparente? Merci d'avance!!

Répondre

8

Oh, mon dieu! Je l'ai fait!! J'ai ajouté [[UIColor clearColor] set]; . C'est tout.

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(); 
Questions connexes