简体   繁体   English

为什么从iOS在instagram上共享时图像会变大?

[英]Why the image become zoom while sharing on instagram from iOS?

I want to share image on instagram from my app its working quite well but the problem comes when i share the same image second time the image become zoom in and some part of the image become messed up here is my code for sharing. 我想通过我的应用程序在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;
    }

Updates always cause problems. 更新总是会引起问题。 The following will work for you (given you declare documentInteractionController in the interface): 以下内容将为您工作(假设您在接口中声明documentInteractionController):

 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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM