将.doc文件转换为图像并保存在相册中

时间:2016-12-14 11:39:12

标签: ios iphone

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

UIImageWriteToSavedPhotosAlbum(myUIImage, nil, nil, nil);

我有.doc个文件,但如何使用上述代码将其保存在相册中? 有人可以帮我吗?

修改 我现在已经解决了上述问题。现在我唯一需要的是从filepath获取文件,然后将其转换为图像并将该图像保存到相册中。

2 个答案:

答案 0 :(得分:0)

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

传递您想要捕获的具有doc的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);

答案 1 :(得分:0)

- (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;
}
相关问题