【问题标题】:Convert .doc file into image and save in photo album将 .doc 文件转换为图像并保存在相册中
【发布时间】:2016-12-14 11:39:11
【问题描述】:

我已经在Objective-c 的文档目录中下载了.doc 文件。但是我想把图片保存在iPhone的相册里。 经过一番谷歌搜索,我发现了这个:-

UIImageWriteToSavedPhotosAlbum(myUIImage, nil, nil, nil);

我有.doc 文件,但是如何使用上面的代码将它保存在相册中? 任何人都可以帮助我吗?

编辑: 我现在已经解决了我上面的问题。现在我只需要从文件路径获取文件,然后将其转换为图像并将该图像保存到相册中。

【问题讨论】:

  • 我不想展示。我有文件路径,/Users/pksingh/Library/Developer/CoreSimulator/Devices/77C016C0-4A89-44C2-8616-4F32D1C2159C/data/Containers/Data/Application/62B48275-5D96-42FD-884A-25C309B75993/Documents/KG Classes PTM 24-May-2016.doc 现在我唯一需要的是从路径获取文件->转换为图像->并保存到相册中..

标签: ios iphone


【解决方案1】:

要打开 pdf,您可以使用 UIWebview。

通过您的 webview 来获取您想要捕获的文档。 uiview 可以获取 uiwebview 对象。

-(UIImage*)captureScreen:(UIView*) viewToCapture
{
    UIGraphicsBeginImageContext(viewToCapture.bounds.size);
    [viewToCapture.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return viewImage;
}

通过使用它,您将获得一张图像并进行保存,例如,

 UIImageWriteToSavedPhotosAlbum([image from method] ,nil, nil, nil);

【讨论】:

    【解决方案2】:
    - (void) loadDocFile {
        UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 568.0f)];
    
        webView.delegate = self;
    
        NSURL *targetURL = [[NSBundle mainBundle] URLForResource:@"MyDoc" withExtension:@"doc"];
        NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
        [webView loadRequest:request];
    }
    
    #pragma mark - UIWebViewDelegate methods
    - (void)webViewDidFinishLoad:(UIWebView *)aWebView {
        CGRect originFrame = aWebView.frame;
        CGRect frame = aWebView.frame;
        frame.size.height = 1;
        aWebView.frame = frame;
        CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero];
        frame.size = fittingSize;
        aWebView.frame = frame;
    
        UIImage *docImage = [self snapShot:aWebView];
        UIImageWriteToSavedPhotosAlbum(docImage, nil, nil, nil);
        aWebView.frame = originFrame;
    }
    
    // snapShot
    - (UIImage*)snapShot:(UIView*)myView {
        UIGraphicsBeginImageContext(myView.frame.size);
        [myView.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return viewImage;
    }
    

    【讨论】:

    • 我有实现但不能工作,实际上我不需要在 webview 上加载,我只需要在 iPhone 相册的下载按钮上保存 doc 文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 2015-01-30
    • 2015-11-03
    相关资源
    最近更新 更多