I only get the thumbnail from a DNG/TIFF file

I am able to read the DNG-file as a PHAssetResource and getting the NSData through PHAssetResourceManager.requestDataForAssetResource.

The NSData holds the same amount of bytes as the filesize indicates.


However, when I do UIImage(data:myLoadedData) only a very low rez thumb is loaded.

I have tried the following :

- using CGImageSourceCreateWithData and converting it back into an UIImage via CGImageSourceCreateImageAtIndex

- the CGImageSourceGetCount( imageSource) returns 1 so there is only one image in there, not counting the thumb

- saving the NSData to the documents folderand reading it witn NSImage(contentsOfFile) (the saved file is a valid DNG and TIFF when I download the app package to my mac through the Device Manager)


The PHAssetResource.uniformTypeIdentifier reports the file as "com.adobe.raw-image"

I get the same result with DNG-files from two different cameras, both the Leica M typ240, and the Leica Monochrom (first edition)

There is a difference in thumbnail size, but I am not able to view the full resolution image.

Loading large jpeg's or PNGs works fine.


The "app" is running on an iPad Pro iOS 9.3


What am I missing here?

Any tips would be greatly appreciated.


Below is the code, from the UIImagePickerController returns with a selected image URL


    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
      
        dismissViewControllerAnimated(true, completion: nil)
      
        let url = info[UIImagePickerControllerReferenceURL] as! NSURL
        getUIImagefromAsseturl(url)
      
    }
  
  
    func getUIImagefromAsseturl (url: NSURL) {
      
        let resourceManager = PHAssetResourceManager.defaultManager()
      
        let asset = PHAsset.fetchAssetsWithALAssetURLs([url], options: nil)[0]
      
        let assetResource = PHAssetResource.assetResourcesForAsset(asset as! PHAsset)[0]
      
      
        let totalData = NSMutableData()
      
        resourceManager.requestDataForAssetResource(assetResource, options: nil, dataReceivedHandler:
            { (data) in
              
                totalData.appendData( data )
                print( "data.length \(data.length) \(totalData.length)" )
              
            }, completionHandler: { (error) in
                if error != nil {
                    print( "error: \(error)" )
                }
                else {
                  
                    /* totalData contains the entire byte buffer from the file */
                    let image = UIImage(data: totalData)
                    /* image contains puny thumbnail */
                  
                    dispatch_async(dispatch_get_main_queue(), {
                        self.imageView.contentMode = .ScaleAspectFit
                        self.imageView.image = image
                    })
                }
        })
      
      
    }
Answered by sandymc in 127437022

Andreas,


Hi.


iOS, unlike OS X, doesn't decode raw images at all, so I'm afraid that there is no way to get a full res image via any iOS function. PhotoRaw (and other apps that read raw images at full res) have their own internal raw converters. What you're getting from the UIImage is the thumbnail that's embedded in the DNG, which is the best that iOS can do.


Regards,


Sandy

Accepted Answer

Andreas,


Hi.


iOS, unlike OS X, doesn't decode raw images at all, so I'm afraid that there is no way to get a full res image via any iOS function. PhotoRaw (and other apps that read raw images at full res) have their own internal raw converters. What you're getting from the UIImage is the thumbnail that's embedded in the DNG, which is the best that iOS can do.


Regards,


Sandy

So everyone writes their own raw convertertes to support all those different cameras?

Sure sounds like a lot of work.


Sandy, can I have the code for your PhotoRaw-app? 😉


Andreas Øverland

Andreas,


For a small fee anything is possible....😉


You could look at something like LibRaw, although I'm not sure that it will run very well in smaller memory spaces. PhotoRaw's raw conversion code is heaviliy optimised for low memory situations, and has virtual memory, etc.


Regards,


Sandy

I only get the thumbnail from a DNG/TIFF file
 
 
Q