1

を持っているのでUITableView、その表示部分をキャプチャして、に入れたいと思いUIImageます。これを行う方法はありますか?

編集

以下の自己回答

4

4 に答える 4

6

返信ありがとうございます。すべての回答はUIViewで機能しますが、UITableViewでは機能しません。少なくともテーブルがスクロールしたときは機能しません。スクロールすると、キャプチャされた画像は黒または透明に表示されます。私は以前に以下のものと同様の解決策を試しました。人々は答えが明白であると思っていたと思います、そしてそれが私が反対票を投じた理由です-そのような明白な質問をするのに十分いたずらだったからです。

とにかく、本当の解決策は、テーブルのcontentOffsetを使用する必要があるということです。

- (UIImage *) imageWithTableView:(UITableView *)tableView
{
    UIView *renderedView = tableView;
    CGPoint tableContentOffset = tableView.contentOffset;
    UIGraphicsBeginImageContextWithOptions(renderedView.bounds.size, renderedView.opaque, 0.0);
    CGContextRef contextRef = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(contextRef, 0, -tableContentOffset.y);
    [tableView.layer renderInContext:contextRef];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
于 2012-10-18T16:30:08.723 に答える
3
UIGraphicsBeginImageContext(someView.bounds.size);
[someView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

この質問から引用。

于 2012-10-18T12:42:42.220 に答える
1
- (UIImage *)captureView {

//hide controls if needed
CGRect rect = [yourTableView bounds];

    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [yourTableview.layer renderInContext:context];   
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;

}
于 2012-10-18T12:43:19.170 に答える
1
UIGraphicsBeginImageContext(tableView.bounds.size);
[tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

たぶん、それらの投稿は、UIViewをその子と一緒にレンダリングするのに役立つでしょう

内部の画像の実際のサイズでiOS4にUIViewコンテンツを保存する(つまり、保存のためにコンテンツを拡大する)

UIVIewをバックグラウンドスレッドの画像にレンダリングする安全な方法は?

于 2012-10-18T12:44:17.703 に答える