以下のコードを使用して、作成中のアプリで画像をキャプチャしました。画像を完全にキャプチャして保存し、Facebook と Twitter に完全に投稿できます。ただし、画像サイズが 612px x 612px 以上ではないため、Instagram に投稿できません。画像のピクセル サイズを大きくする方法はありますか? すでに 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];
}