1

フォト アルバムから画像を選択し、それを呼び出された imageView に配置し、入力のソースとしてUIImageView使用して画像の上にテキストを追加し、テキストを表示するために uiimageview の上に追加しました。UITextViewUILabel

ここまでは順調ですね。

今、ラベルとイメージビューをマージして他のことをしようとしていますが、うまくいきません。同様の質問に対していくつかの解決策を試しましたが、うまくいきませんでした。

私はこれを試しました

UIGraphicsBeginImageContextWithOptions(_imageView.bounds.size, NO, 0.0); //retina res
[self.imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
[_displaylabel.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

Received タイプは「CAlayerたとえば、メッセージは前方宣言です」とわかります。

他の提案はありますか?

4

2 に答える 2

0
 UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
 UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, imgView.frame.size.width, imgView.frame.size.height)];
    [tempView addSubview:imgView];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(tempView.frame.size.width/2, 0, 200, tempView.frame.size.height/2)];
[label setText:@"Hello... You there"];
[label setTextColor:[UIColor blackColor]];
[label setTextAlignment:NSTextAlignmentLeft];
[label setBackgroundColor:[UIColor clearColor]];
[tempView addSubview:label];


 UIGraphicsBeginImageContext(tempView.bounds.size);
    [tempView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
于 2014-12-15T07:45:00.143 に答える
0

これを試して:

UIGraphicsBeginImageContextWithOptions(_imageView.bounds.size, NO, 0.0); //retina res
[self.imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UILabel が UIImageView のサブビューであることを確認して、レイヤーのレンダリングにすべてのサブレイヤー (UILabel を含む) が含まれるようにします。UIGraphicsEndImageContext(); を含めるのを忘れたようです。あまりにも、それが問題だったかもしれません

于 2013-04-16T07:05:18.067 に答える