1

はい、タイトルにあるように、アプリのスナップショットを切り抜く必要があります。

スクリーンショットの上部を少し切りたい(%20)スナップショットを撮ってFacebookに送信するために使用したコードがすでにありますが、画面全体の写真を撮っているので、コードをどのように伝えることができますか画面の%20%を無視します。多分、高さと幅についても、スタックオーバーフローでいくつかの質問を見て、スクリーンショットをスライドさせて、上部の不要な部分を取り除きましたが、今回は下部の巨大な白い領域を削除しました。表示されたので、問題は解決しませんでした。

これが私のスナップショットコードです

UIGraphicsBeginImageContext(self.ekran.bounds.size);
    [self.ekran.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
4

1 に答える 1

0

画像をトリミングするための任意のフレームを受け入れる、画像をトリミングするメソッド

- (UIImage *)cropImage:(UIImage *)imageToCrop toRect:(CGRect)rect
    {    
        CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
        UIImage *cropped = [UIImage imageWithCGImage:imageRef];
        CGImageRelease(imageRef);

        return cropped;
    }

次のように使用します。

UIGraphicsBeginImageContext(self.ekran.bounds.size);
[self.ekran.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

CGFloat imgHight = resultingImage.size.height;

// Create a frame that crops the top 20% of the image
CGRect* imageFrame = CGRectMake(0, imgHight -  (imgHight*0.8), width, imgHight*0.8);

resultingImage = [self cropImage:resultingImage toRect:imageFrame];
于 2013-02-02T21:24:58.570 に答える