1

Xcode 4.3 でネイティブ アプリを作成し、iOS 5 をターゲットに展開しています。このアプリは、基本的にグリーティング カード クリエーターです。アプリ内から画面の一部を保存する方法がわかりません。

私がやりたいことはこれです:

「電子メール」というボタンをユーザーに提供しています。ボタンをクリックすると、アプリはカードを画像として「保存」し、それをメール本文に「貼り付け」ます。

これがこの Web サイトの他の回答と異なる理由は、保存したい領域が 4 つの「要素」で構成されているためです。傾斜したカードの背景である背景グラフィックがあります。次に、ユーザーがメッセージを入力できるテキスト フィールドがあり、その隣に、カードに配置する独自の画像を選択できる画像領域があります。

これが私が話していることの写真です: http://marklopezdesigns.com/mydownloadz!/screenshotCard3.png

これらの「複合」高解像度を保存するにはどうすればよいですか?

そして、どうすればそれを電子メールの本文メッセージに入れることができますか?

「保存」する方法を尋ねているのは、「カメラロールに保存」と「メッセージとして送信」という別のボタンをユーザーに提供できるようにしたいからです。この高解像度を変数に保存する方法を理解できれば、すぐに実行に移すことができます。

助けてくれてありがとう。

========

これが以下の解決策です

======== ...少しいじった後。最後に私が欲しかったものを手に入れました。「アルバムに保存」ボタンを押すと起動するメソッドのコードベースは次のとおりです。

- (IBAction)savePhoto{  

CGRect rect;  
rect = CGRectMake(11,50 ,305, 262);  
UIView *cardViewer = [[UIView alloc] initWithFrame:rect];  
UIGraphicsBeginImageContext(cardViewer.bounds.size);   
//make view background transparent  
cardViewer.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.0];  
cardViewer.opaque = NO;  

//stuff items into a subview for capturing  
[self.view addSubview:cardViewer];  
[cardViewer addSubview:self.tiltedCard];  
[cardViewer addSubview:self.bigCardView];  
[cardViewer addSubview:self.cardWords];  
[cardViewer addSubview:self.photoView];  

[cardViewer.layer renderInContext:UIGraphicsGetCurrentContext()];  
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();  
UIGraphicsEndImageContext();  
CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], rect);  
UIImage *img = [UIImage imageWithCGImage:imageRef];  
CGImageRelease(imageRef);  
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);  

//put everything back where it belongs  
[self.view addSubview:self.tiltedCard];  
[self.view addSubview:self.bigCardView];  
[self.view addSubview:self.cardWords];  
[self.view addSubview:self.photoView];  

[cardViewer removeFromSuperview];  

}

4

3 に答える 3

1

画面の領域だけをキャプチャするには、 を使用して境界を指定しますCGRectMake

CGRect rect = CGRectMake(50, 50, 100, 100);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

上記の例では、x:50px と y:50px で始まる 100px x 100px の領域をキャプチャしています。

于 2012-11-21T05:27:30.023 に答える
0

レイヤーコンテキストをレンダリングして画像を取得することで、レイヤーの画像を取得できます。これを使用して、派手なアニメーションを表示します

UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
于 2012-11-20T19:52:13.643 に答える
0

画面の領域だけをキャプチャするには、UIView または SubViewを使用し、CGRectMake を使用して境界を指定するだけです。

CGRect rect = CGRectMake(10, 10, 200, 200);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.YourView.layer renderInContext:context]; // Make sure here you are using the  greetingcardView rather than self.view
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

注: self.view は画面全体をキャプチャするため、単にビューをどこにでもレンダリングします。

于 2012-11-21T06:18:46.170 に答える