在iOS上从Instagram共享时,为什么图像会变焦?

时间:2013-08-05 07:20:39

标签: ios objective-c instagram

我想在我的应用程序上分享Instagram上的图像它工作得很好,但问题出现的时候我第二次分享相同的图像时图像变焦,图像的某些部分变得混乱,这是我的共享代码。

-(void)shareImageToInstagram

    {
        myview.hidden = NO;
        shareImage.image = [self ChangeViewToImage:myview];

        NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];


            CGRect cropRect=CGRectMake(0,0,306,306);
            NSString *savePath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"];
            CGImageRef imageRef = CGImageCreateWithImageInRect([shareImage.image CGImage], cropRect);
            UIImage *img = [[UIImage alloc] initWithCGImage:imageRef];
            CGImageRelease(imageRef);
            [UIImageJPEGRepresentation(img, 1.0) writeToFile:savePath atomically:YES];
            NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@",savePath]];
            self.dic.UTI = @"com.instagram.photo";
            self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
            self.dic.annotation = [NSDictionary dictionaryWithObject:kCheckOut forKey:@"InstagramCaption"];
        if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
        {
            [self.dic presentOpenInMenuFromRect: CGRectZero  inView: self.view animated: YES ];
             myview.hidden = YES;
        }
        else
        {
            ALERT_VIEW(@"Instagram not installed in this device!\nTo share image please install instagram.");
             myview.hidden = YES;
        }
    }

    - (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {

        UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
        interactionController.delegate = interactionDelegate;
         myview.hidden = YES;
        return interactionController;
    }

1 个答案:

答案 0 :(得分:1)

更新总是会导致问题。以下内容适合您(假设您在界面中声明了uidocumentInteractionController):

 NSURL *instagramURL = [NSURL URLWithString:@"instagram://yourApp"];

 if ([[UIApplication sharedApplication] canOpenURL:instagramURL]){
 NSString *jpgPath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.igo"];
        [UIImageJPEGRepresentation(yourImage, 1.0) writeToFile:jpgPath atomically:YES];

        NSURL *fileURL = [NSURL fileURLWithPath:jpgPath];
        documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
        documentInteractionController.UTI = @"com.instagram.exclusivegram";
        documentInteractionController.delegate = self;

            documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"Your App" forKey:@"InstagramCaption"];
        [documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];