Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is a way to perform "select all" on the cropView? #10

Open
Idomo opened this issue Jan 16, 2019 · 1 comment
Open

There is a way to perform "select all" on the cropView? #10

Idomo opened this issue Jan 16, 2019 · 1 comment

Comments

@Idomo
Copy link
Contributor

Idomo commented Jan 16, 2019

Hi,
I did found a way to perform "select all" on the cropView, but it's working only with images from the library or ones that taken from the camera, but not from image that created from PDF for example.

This is my solution:

guard let frame = image?.size else { return }
cropView.setCorners(newCorners: [.zero,
    CGPoint(x: frame.width, y: 0),
    CGPoint(x: frame.width, y: frame.height),
    CGPoint(x: 0, y: frame.height)])

From some reason, when I'm running this on an image that created from PDF file, it's returns a very small size, I could say it looks like the thumbnail that you can see in the UIDocumentPickerViewController, but when I'm setting the image as the image of the imageView I can see it all over the screen and very sharp, it doesn't looks like the imageView resized it or something.

So in the bottom line - I wanted to ask if there is some built-in way in the library to perform "select all" or if you have any better idea that will work also with PDF converted to image it will be great.

BTW, the code that I'm using to convert the PDF to UIImage is:

func drawPDFfrom(url: URL) -> UIImage? {
    guard let document = CGPDFDocument(url as CFURL) else { return nil }
    guard let page = document.page(at: 1) else { return nil }

    let pageRect = page.getBoxRect(.mediaBox)
    let renderer = UIGraphicsImageRenderer(size: pageRect.size)
    let img = renderer.image { ctx in
        UIColor.white.set()
        ctx.fill(pageRect)

        ctx.cgContext.translateBy(x: 0.0, y: pageRect.size.height)
        ctx.cgContext.scaleBy(x: 1.0, y: -1.0)

        ctx.cgContext.drawPDFPage(page)
    }

    return img
}

Thanks,
Ido.

@Idomo
Copy link
Contributor Author

Idomo commented Jan 23, 2019

Looks like all of the images that created from PDF files are 3 times smaller than the cropView, so all I had to do is to multiply the points of the cropView's corners by 3.
I solved this with this code:

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
  guard var corners = self.cropView.cornerLocations else { return }
    for i in 0 ..< corners.count {
      corners[i].x *= 3
      corners[i].y *= 3
    }
    self.cropView.setCorners(newCorners: corners)
}

Yet, it still was nice to have some built-in function for "Select All", sure many of users would like to select all of the screen when they are taking documents from the documents library (e.g. as PDF).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant