Setting PHAssetMediaSubtypePhotoDepthEffect on depth data save

When saving depth data, how do I set the PHAssetMediaSubtypePhotoDepthEffect property? I'm able to save a jpg with depth data but it doesn't show up in the Depth Effect folder or have the deptheffect media subtype.


Here is the depth saving code taken from the wwdc2017 508 session.


  // first add image
  CGImageDestinationAddImage(cgImageDestination, renderedCGImage, attachments)
  // Use AVDepthData to get auxiliary data dictionary
  var auxDataType :NSString?
  let auxData = depthData.dictionaryRepresentation(forAuxiliaryDataType: &auxDataType)
  // Add auxiliary data to image destination
  CGImageDestinationAddAuxiliaryDataInfo(cgImageDestination, auxDataType!, auxData! as CFDictionary)
  if CGImageDestinationFinalize(cgImageDestination) {
     return data as Data
  }


Any help would be appreciated!

James

Accepted Reply

The code you've included shows how to transfer the depth map and its associated metadata from a source to a destination image. If an image has a depth map present, it is eligible to have Apple's Portrait or "Depth" (shallow depth of field) effect applied, but these are not the same thing. There's no way to set PHAssetMediaSubtypePhotoDepthEffect. You'd need to go into Photos, select Edit on the photo, and then tap the button to apply the Depth (shallow depth of field) effect. This button will not even be offered if there's no depth map/metadata present in the image.


Hope that helps.

Replies

The code you've included shows how to transfer the depth map and its associated metadata from a source to a destination image. If an image has a depth map present, it is eligible to have Apple's Portrait or "Depth" (shallow depth of field) effect applied, but these are not the same thing. There's no way to set PHAssetMediaSubtypePhotoDepthEffect. You'd need to go into Photos, select Edit on the photo, and then tap the button to apply the Depth (shallow depth of field) effect. This button will not even be offered if there's no depth map/metadata present in the image.


Hope that helps.

Thanks for the explanation! I thought the deptheffect subtype indicated the presence of depth data, but instead indicates that the depth effect has been applied for a lens blur. I am able to detect if depth data is present in a photo which is exactly what I need here.


Thanks!

James

We have the very same problem!

We'd like to know which image contains Depth without having to look inside the full-resolution meta-data (expensive!)

I also have the same problem. After I added the blurred effect to image, and merged the image, depth data and metadata into NSData, I can't save them as a portrait photo as the system's camera works. Is there any demo to merge them into one portrait photo and let Photos app to edit it as portrait mode?


Thank you.

Are you creating the depth data manually with a custom depth or are you using the one obtained by a dual camera phone?