Question

I am developing an iOS application which takes images from the iPhone camera using AVCaptureDevice.

The images captured seem to have a pixel density(ppi) of 72ppi.

1. I need to send these images for further processing to a backend cloud server which expects the images to have a minimum pixel density of 300ppi.

2. I also see that the images taken from the native iPhone 5 camera also have a pixel density of 72 ppi.

3. I need to know if there are any settings in the AVCapture foundation to set the pixel density of the images taken or if there are ways to increase the pixel density of the images taken from 72 to 300 ppi.

Any help would be appreciated.

Was it helpful?

Solution 2

As @Codo has pointed out, the pixel density is irrelevant until the image is being output (to a display, a printer a RIP, or whatever). It's metadata, not image data. However, if you're dealing with a third-party service that doesn't have the wit to understand this, you need to edit the image metadata after you have captured the image and before you save it.

This is how:

captureStillImageAsynchronouslyFromConnection:stillImageConnection
    completionHandler:^(CMSampleBufferRef imageDataSampleBuffer 
    NSError *error) {
  CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(kCFAllocatorDefault,
      imageDataSampleBuffer,
      kCMAttachmentMode_ShouldPropagate);
  NSMutableDictionary *metadata = [[NSMutableDictionary alloc]
      initWithDictionary:(__bridge NSDictionary*)metadataDict];
  CFRelease(metadataDict);
  NSMutableDictionary *tiffMetadata = [[NSMutableDictionary alloc] init];
  [tiffMetadata setObject:[NSNumber numberWithInt:300]
      forKey(NSString*)kCGImagePropertyTIFFXResolution];
  [tiffMetadata setObject:[NSNumber numberWithInt:300] forKey:
      (NSString*)kCGImagePropertyTIFFYResolution];
  [metadata setObject:tiffMetadata forKey:(NSString*)kCGImagePropertyTIFFDictionary];
  .
  .
  .
}];

Then feed metadata into writeImageToSavedPhotosAlbum:metadata:completionBlock, writeImageDataToSavedPhotosAlbum:metadata:completionBlock or a save into your private app folder, depending on your requirements.

OTHER TIPS

What's the difference between a 3264 by 2448 pixel image at 72ppi and a 3264 by 2448 pixel image at 300ppi? There's hardly any except some minor difference in the meta data. And I don't understand why your backend service insists on a minimum pixel density.

The pixel density (or ppi) becomes relevant when you print or display an image at a specific size or place it in a document using a specific size.

Anyway, there is no good reason to set a specific ppi at capture time. That's probably the reason why Apple uses the default density of 72ppi. And I don't know of any means to change it at capture time.

However, you can change it at a later time by modifying the EXIF data of a JPEG file, e.g. using libexif.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top