gpt4 book ai didi

ios - 自动检测 PDF 中的图像

转载 作者:行者123 更新时间:2023-11-29 03:24:42 25 4
gpt4 key购买 nike

我使用适用于 iOS 的 PSPDFKit。

在符合 PSPDFViewControllerDelegatePSPDFViewController 中,我覆盖 -(BOOL)pdfViewController didTapOnPageView: atPoint:(CGPoint)viewPoint,并且我需要检查是否点击了该页面中的任何图像 [pageView.textParser.images]

如何将我的点 [viewPoint] 的坐标与图像的坐标相匹配?

简而言之,我想实现pdf中图像的自动检测。

最佳答案

更新:我在 PSPDFKIT 示例中找到了答案,

- (void)pdfViewController:(PSPDFViewController *)pdfController didLoadPageView:(PSPDFPageView *)pageView {
// Iterate over all images and add button overlays on top.
// Accessing the text parser will block the thread, so it'll be better to access the in a background thread and than use the result on the main thread (but then you'll have to check if the pageView still points at the same page which would add too much complexity for this simple example.)
for (PSPDFImageInfo *imageInfo in [pageView.document textParserForPage:pageView.page].images) {
// Create the view
PSCAutoResizeButton *resizeButton = [PSCAutoResizeButton new];
resizeButton.targetPDFRect = [imageInfo boundingBox];
resizeButton.imageInfo = imageInfo;
resizeButton.showsTouchWhenHighlighted = NO;
resizeButton.layer.borderColor = [UIColor redColor].CGColor;
resizeButton.layer.borderWidth = 0.f;
resizeButton.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.2f];
[resizeButton addTarget:self action:@selector(imageButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
// Add to container view. Only here views will get notified on changes via PSPDFAnnotationViewProtocol.
// The container view will be purged when the page is prepared for reusage.
[pageView.annotationContainerView addSubview:resizeButton];
} }

私有(private)

- (void)imageButtonPressed:(PSCAutoResizeButton *)button {
NSParameterAssert([button isKindOfClass:PSCAutoResizeButton.class]);

PSPDFImageInfo *imageInfo = button.imageInfo;
UIImage *image = [imageInfo imageWithError:NULL];

// Show view controller
if (image) {
UIViewController *imagePreviewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
imagePreviewController.title = imageInfo.imageID;
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.backgroundColor = UIColor.blackColor;
imagePreviewController.view = imageView;
[self presentModalOrInPopover:imagePreviewController embeddedInNavigationController:YES withCloseButton:YES animated:YES sender:button options:@{PSPDFPresentOptionAlwaysModal : @YES, PSPDFPresentOptionModalPresentationStyle : @(UIModalPresentationFormSheet)}];
} }

关于ios - 自动检测 PDF 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20608738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com