繁体   English   中英

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

[英]Convert .doc file into image and save in photo album

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

UIImageWriteToSavedPhotosAlbum(myUIImage, nil, nil, nil);

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

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

要打开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);
- (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;
}

暂无
暂无

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

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