Skip to content

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

@Idomo

Description

@Idomo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions