Giter Site home page Giter Site logo

Comments (7)

zhangao0086 avatar zhangao0086 commented on September 27, 2024

Use fetchFullScreenImageWithCompleteBlock... like this:

assets.first?.fetchFullScreenImageWithCompleteBlock({ image, info in
    let object = CustomObject()
    object.image = image
})

from dkimagepickercontroller.

aldolazuardi avatar aldolazuardi commented on September 27, 2024

and how to make all photos in DKAsset to new class?

from dkimagepickercontroller.

zhangao0086 avatar zhangao0086 commented on September 27, 2024

Maybe I should provide a sync method to fetch an image..

from dkimagepickercontroller.

aldolazuardi avatar aldolazuardi commented on September 27, 2024

yeah that would be great, anyway im using this code

    for asset in photos{
        asset.fetchFullScreenImageWithCompleteBlock({ image, info in
           let images = image
            let data1 = dataImage(userId: "1", value: 1.0, photo: images)
            self.datas += [data1]
            print("*")
        })
    }
    print("datas: \(datas.count)")

i have 6 'image' in photos(DKAsset) and '*' print 6 times, but datas.count is 0, do you have any guess what did i missed?

from dkimagepickercontroller.

zhangao0086 avatar zhangao0086 commented on September 27, 2024

Try this:

let options = PHImageRequestOptions()
options.deliveryMode = .HighQualityFormat
options.resizeMode = .Exact;
options.synchronous = true

for asset in photos {
    asset.fetchImageWithSize(UIScreen.mainScreen().bounds.size.toPixel(), options: options,
        completeBlock: { image, info in
            let images = image
            let data1 = dataImage(userId: "1", value: 1.0, photo: images)
            self.datas += [data1]
            print("*")
    })
}
print("datas: \(datas.count)")

from dkimagepickercontroller.

aldolazuardi avatar aldolazuardi commented on September 27, 2024

I just found the answer of this problem, turns out it prints 0 because loop finishes very quickly, while all 6 asset fetches occur in the background. http://stackoverflow.com/questions/34890905/failed-to-input-data-to-class-model-swift/34891231#34891231.

Anyway thank you for the great lib and fast answers bro!

from dkimagepickercontroller.

zhangao0086 avatar zhangao0086 commented on September 27, 2024

Yes, the fetches method executed in the background. So you can specific the synchronous of the PHImageRequestOptions to true like my above answer :)
And I've added two functions to sync fetch images in 3.0.6:

/**
Fetch an image with the current screen size.

- parameter sync:          If true, the method blocks the calling thread until image is ready or an error occurs.
- parameter completeBlock: The block is executed when the image download is complete.
*/
public func fetchFullScreenImage(sync: Bool, completeBlock: (image: UIImage?, info: [NSObject : AnyObject]?) -> Void)

/**
Fetch an image with the original size.

- parameter sync:          If true, the method blocks the calling thread until image is ready or an error occurs.
- parameter completeBlock: The block is executed when the image download is complete.
*/
public func fetchOriginalImage(sync: Bool, completeBlock: (image: UIImage?, info: [NSObject : AnyObject]?) -> Void)

Anyway please let me know if you have any questions :)

from dkimagepickercontroller.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.