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

I can't get data from assets in new version #53

Closed
Casporro opened this issue Dec 21, 2015 · 20 comments
Closed

I can't get data from assets in new version #53

Casporro opened this issue Dec 21, 2015 · 20 comments

Comments

@Casporro
Copy link

With the new version (3.0.0) I can't get NSData from assets... If I do this:

assets.first!.fetchImageWithSize(sender.view!.bounds.size, completeBlock: {
          (image: UIImage?) -> Void in

           if let imageToSave = image {
                   let data: NSData = UIImageJPEGRepresentation(imageToSave, 0.7) //data always nil
                    self.saveImage(data!)
        }
}

data is always nil an image never is nil... What is the problem?

@zhangao0086
Copy link
Owner

Could you try the fixed syntax:
let data: NSData? = UIImageJPEGRepresentation(imageToSave, 0.7)

In addition, if the imageToSave cannot obtain the jpeg image data, it will return nil. In this case, try to replace UIImageJPEGRepresentation with UIImagePNGRepresentation.

@Boli-CS
Copy link

Boli-CS commented Dec 22, 2015

I have another question, how could I get the NSURL of the photo choosed?

@zhangao0086
Copy link
Owner

Hi @Boli-CS
Why do you want to do this?

@Casporro
Copy link
Author

Why the fetchImageWithSize method return other size??

@Casporro
Copy link
Author

and how can I get NSData from AVURLAsset?

@zhangao0086
Copy link
Owner

Hi @Casporro
You can get NSData from AVURLAsset like this:

assets.first?.fetchAVAssetWithCompleteBlock({ (avAsset) -> Void in
    let data = NSData(contentsOfURL: avAsset!.URL)
    print(data)
})

@zhangao0086
Copy link
Owner

For the _Why the fetchImageWithSize method return other size??_

It's my fault! Fixed in 78d4e8c :)

@Casporro
Copy link
Author

Thank you @zhangao0086, nice library and nice work.
I will use exporter to export video to something compatible with iOS and Android.

@Casporro
Copy link
Author

Can you tell me how can I get a thumbnail from avAsset?

@zhangao0086
Copy link
Owner

@Casporro
Try using AVAssetImageGenerator.
See also:http://stackoverflow.com/questions/8906004/thumbnail-image-of-video

@melihkeskin
Copy link

hi zhangao0086,
Nice work..Thanks for sharing.

i want to ask some questions

How can i get images from assets ?
Can you write a little sample code ?

@zhangao0086
Copy link
Owner

Hi @melihkeskin
Try this:

assets.first?.fetchFullScreenImageWithCompleteBlock({ image in
    print(image)
})

@melihkeskin
Copy link

Hello again :),

thank you for your reply
is it only first image isnt it?

what can i do multiple picking ?

and last question :)

how can i get didFinishPickingMediaWithInfo

@zhangao0086
Copy link
Owner

@melihkeskin
You can do this:

var images: [UIImage] = []
for asset in assets {
    asset.fetchFullScreenImageWithCompleteBlock({ image in
        images.append(image!)

        if images.count == assets.count {
            print("done")
        }
    })
}

Why do you want to get didFinishPickingMediaWithInfo? It's a delegate method of UIImagePickerController, so it's never called in this library.

@melihkeskin
Copy link

Thank for help. I want to get metadata of the images.
I find many sample on the internet but generally they used in the didfinishpickingmediawithinfo. İf you can know other way please tell

@zhangao0086
Copy link
Owner

@melihkeskin
If you need to get the metadata of a DKAsset, just access the originalAsset like so:

if let originalAsset = asset.originalAsset {
    originalAsset.mediaType
    originalAsset.mediaSubtypes
    originalAsset.creationDate
    originalAsset.modificationDate
    // ...
}

See also: Reading Asset Metadata

@melihkeskin
Copy link

Hello zhangao0086,

i appreciate you. You are really good my friend.
Thanks for everything.
Nice work.

@zhangao0086
Copy link
Owner

@melihkeskin
I’m glad that helped you :)

@aldolazuardi
Copy link

hi zhangao0086,
im following ur answer to melihkeskin and it not works (pic below), why i got this error?
screen shot 2016-01-12 at 3 52 42 pm

@zhangao0086
Copy link
Owner

Hi @aldolazuardi

In 3.0.4, I've updated the fetchImage... interface:
the completeBlock: (image: UIImage?) -> Void was changed to completeBlock: (image: UIImage?, info: [NSObject : AnyObject]?) -> Void so you need to change:

asset.fetchImageWithSize(size, completeBlock: { image in
    // ...
})

to:

asset.fetchImageWithSize(size, completeBlock: { image, info in
    // ...
})

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

5 participants