我在使用下面的代码创建的应用程序上捕获了图像。它完美地捕捉和存储图像,我可以完美地将其发布到 Facebook 和 Twitter。但是,它不会让我将其发布到 Instagram,因为图像尺寸至少不是 612 像素 x 612 像素。有什么办法可以增加图像的像素大小?它只需要稍微增加,因为它已经是 568px x 570px。任何建议都会很棒!谢谢!
获取捕获图像的代码:
CGSize newImageSize = CGSizeMake(self.mainImage.frame.size.width, self.mainImage.frame.size.height);
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, 0.0);
[self.imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage*theImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData*theImageData=UIImageJPEGRepresentation(theImage, 1.0 ); //you can use PNG too
UIImage * imagePNG = [UIImage imageWithData:theImageData]; // wrap UIImage around PNG representation
UIGraphicsEndImageContext();
return imagePNG;
发布到 Instagram 的代码:
//Instagram Image
if (_testImage.image.size.width < 612 || _testImage.image.size.height <612) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Information" message:@"The image you are trying to post to Instagram is too small. Image must be at least 612px x 612px" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
NSLog(@"image size: %@", NSStringFromCGSize(_testImage.image.size));
[alert show];
}else{
NSString* imagePath = [NSString stringWithFormat:@"%@/image.igo", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]];
[[NSFileManager defaultManager] removeItemAtPath:imagePath error:nil];
[UIImageJPEGRepresentation(_testImage.image, 0.2) writeToFile:imagePath atomically:YES];
NSLog(@"image size: %@", NSStringFromCGSize(_testImage.image.size));
_docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:imagePath]];
_docController.delegate=self;
_docController.UTI = @"com.instagram.exclusivegram";
[_docController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];
}