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

Der obige Code ist, was ich verwende, um meine 'DrawingView' in eine PNG-Datei zu speichern. Ich habe mehrere Fragen und Antworten gefunden, also habe ich sie angewendet. Ich habe den Opaque meiner "drawingView" und drawingView.layer als NO gesetzt und die Hintergrundfarbe meiner 'drawingView' als [UIColor clearColor] gesetzt. Ich denke, ich habe alle Antworten von Stackoverflow übernommen. Es hat sich jedoch nichts verändert. Der Hintergrund von png fil ist immer noch schwarz. Ich brauche transparenten Hintergrund, nicht schwarz !!UIView als PNG-Datei mit transparentem Hintergrund speichern

Ich habe versucht, ob es irgendein Problem mit UIImage * image1. Ich habe image1 auf dem Bildschirm angezeigt, dann konnte ich einen schwarzen Hintergrund von diesem Bild1 finden. Ich könnte also vermuten, dass beim Erstellen von image1 ein Problem auftritt.

Das ist alles, was ich gefunden habe. Gibt es eine mögliche Lösung, um mein PNG-Bild mit transparentem Hintergrundbild zu speichern? Danke im Voraus!!

Antwort

8

Oh Gott! Ich habe es gemacht!! Ich habe [[UIColor clearColor] eingestellt]; . Das ist alles.

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(); 
Verwandte Themen