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

上記のコードは、私の 'drawingView'をpngファイルに保存するために使用しています。私はいくつかの質問と回答を見つけたので、それらを適用しました。私は私の 'drawingView'とdrawingView.layerの不透明度をNOに設定し、私の 'drawingView'の背景色を[UIColor clearColor]に設定しました。私はすべての答えをstackoverflowから適用したと思う。ただし、変更はありません。 pngファイルの背景はまだ黒です。私は黒ではなく、透明な背景が必要です!透明な背景を持つpngファイルとしてUIViewを保存します。

UIImage * image1に問題があるかどうか試しました。私は画面に表示するためにimage1を使用し、その画像から黒い背景を見つけることができました1。だから私はimage1を作成するときに何か問題があると推測することができます。

これはすべて私が見つけたものです。 png画像を透明な背景画像で保存する方法はありますか?前もって感謝します!!

答えて

8

ああ、神!やったよ!!私は[[UIColor clearColor] set]を追加しました。 。それで全部です。

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(); 
関連する問題