为Instagram剪裁自己的图像

时间:2014-07-03 21:45:17

标签: ios image uiimage instagram social

我正在创建一个允许用户将图片发布到Instagram的应用。

使用相机拍摄照片或从相机角色中选择时,可以使用.allowEditing将图像裁剪为正方形。但我已经将图像加载到UIImageView中,并希望用户能够在发布到Instagram之前手动裁剪图像。

目前,图像将在Instagram中自动裁剪和打开,而我希望用户选择他们想要的图像部分" Instagram"。我该怎么做?我对iOS开发还很陌生,所以你知道。

到目前为止,我的代码如下:

            //Instagram Image
            if (_imageView.image.size.width < 612 || _imageView.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];
                [alert show];
            }else{
                NSString* imagePath = [NSString stringWithFormat:@"%@/image.igo", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]];
                [[NSFileManager defaultManager] removeItemAtPath:imagePath error:nil];
                [UIImageJPEGRepresentation(_imageView.image, 0.2) writeToFile:imagePath atomically:YES];
                NSLog(@"image size: %@", NSStringFromCGSize(_imageView.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];
            }

任何建议/帮助/教程/答案将不胜感激!谢谢你们!

0 个答案:

没有答案