0

现在我在 facebook 上发布屏幕截图。但我正在尝试定义屏幕截图高度。

    UIGraphicsBeginImageContext(self.view.bounds.size);
   [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
  UIImage *imgPicture = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();
   if ([SLComposeViewController isAvailableForServiceType: SLServiceTypeFacebook]) {
    SLComposeViewController *controller = [SLComposeViewController        composeViewControllerForServiceType:SLServiceTypeFacebook];
    [controller setInitialText :@"post from my iphone"];
    [controller addURL:[NSURL URLWithString:@"https://www.facebook.com/birjesh.sharma.921"]];
    //[controller addImage:[UIImage imageNamed:imgPicture]];
   [controller addImage:imgPicture];
    [self presentViewController: controller animated:YES completion:nil];
}
4

1 回答 1

0

尝试这个

UIGraphicsBeginImageContext(self.view.bounds.size);
// retrieve the current graphics context
CGContextRef context = UIGraphicsGetCurrentContext();
// render view into context
[self.view.layer renderInContext:context];
// create image from context
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
image=[self cropImage:image];
UIGraphicsEndImageContext();


- (UIImage *)cropImage:(UIImage *)oldImage {
    CGSize imageSize = oldImage.size;
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageSize.width,imageSize.height-10),NO,0.); //you can set your height and width
    [oldImage drawAtPoint:CGPointMake( 0, -40) blendMode:kCGBlendModeCopy alpha:1.];//you can set your own value X and Y
    UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return croppedImage;
}
于 2013-07-02T10:28:09.547 回答