• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unable to extract JPEG from PHAsset
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unable to extract JPEG from PHAsset


  • Subject: Re: Unable to extract JPEG from PHAsset
  • From: David Duncan <email@hidden>
  • Date: Sat, 17 Jun 2017 22:29:11 -0700

> On Jun 16, 2017, at 7:31 AM, Glen Huang <email@hidden> wrote:
>
> Hi,
>
> I'm trying to extract the JPEG data from a PHAsset. I did it like this:
>
>            let fetchOptions = PHFetchOptions()
>            fetchOptions.sortDescriptors = [NSSortDescriptor(key:
> "creationDate", ascending: true)]
>            let assets = PHAsset.fetchAssets(with: fetchOptions)
>            jpg(for: assets[0])
>
> where jpg(for:) is
>
>    func jpg(for asset: PHAsset) {
>        let size = CGSize(width: 100, height: 100)
>        PHImageManager.default().requestImage(for: asset, targetSize: size,
> contentMode: .aspectFit, options: nil) { image, info in
>            if let image = image {
>                let jpg = UIImageJPEGRepresentation(image, 0.8)!
>            }
>        }
>    }
>
> It works in the simulator running iOS 11, but fails on iPhone 5S every time
> with
>
> fatal error: unexpectedly found nil while unwrapping an Optional value
>
> And the thing caused that error was the bang after the
> UIImageJPEGRepresentation function.
>
> I'm using Xcode 9 beta, Swift 4, new build system, and the phone runs iOS
> 10.3.2
>
> Any idea why that happens and how I can extract the JPEG data from PHAsset?

There is no obvious reason why this should fail, but the usual debugging things
apply – what are the quality of image? (image.CGImage can still be nil, even if
image is not). Does UIImageJPEGRepresentation() fail in any other situations?
Can you reproduce this without using PHAsset?

>
> Thank you.
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

--
David Duncan

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Unable to extract JPEG from PHAsset
      • From: Glen Huang <email@hidden>
References: 
 >Unable to extract JPEG from PHAsset (From: Glen Huang <email@hidden>)

  • Prev by Date: Re: Release mode bindings crash and release pools
  • Next by Date: Re: Unable to extract JPEG from PHAsset
  • Previous by thread: Unable to extract JPEG from PHAsset
  • Next by thread: Re: Unable to extract JPEG from PHAsset
  • Index(es):
    • Date
    • Thread