Ios 如何增加UIImage像素以发布到Instagram

Ios 如何增加UIImage像素以发布到Instagram,ios,uiimage,instagram,uigraphicscontext,cgsize,Ios,Uiimage,Instagram,Uigraphicscontext,Cgsize,我用下面的代码在我正在创建的一个应用程序上捕获了一个图像。它完美地捕捉和存储了图像,我可以将其发布到Facebook和Twitter上。但是,它不允许我将其发布到Instagram,因为图像大小至少不是612px 612px。有什么方法可以增加图像的像素大小吗?它将只需要稍微增加,因为它已经在568px 570px。任何建议都很好!谢谢 获取捕获图像的代码: CGSize newImageSize = CGSizeMake(self.mainImage.frame.size.width, sel

我用下面的代码在我正在创建的一个应用程序上捕获了一个图像。它完美地捕捉和存储了图像,我可以将其发布到Facebook和Twitter上。但是,它不允许我将其发布到Instagram,因为图像大小至少不是612px 612px。有什么方法可以增加图像的像素大小吗?它将只需要稍微增加,因为它已经在568px 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];
}

您可以缩放它,但这会使图像质量更差。 比例法:


非常感谢,这回答了我的问题。你是对的,这让我的形象更糟,所以我改变了我的方法。这是我问题的正确答案,再次感谢!
- (UIImage*)scaleImage:(UIImage*)image withScale:(CGFloat)scale
{
    CGSize newSize = CGSizeMake(image.size.width*scale, image.size.height*scale);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}