Table of contents
Swift
Objective-C

Get Original Image

Features on this page are only available for the Foundational APIs.

Keep your current result output logic unchanged. Use originalImageHashId from DecodedBarcodesResult to fetch the original image only when needed.

  • Objective-C
  • Swift
  1. - (void)onDecodedBarcodesReceived:(DSDecodedBarcodesResult *)result {
       DSImageData *originalImage = [[self.cvr getIntermediateResultManager] getOriginalImage:result.originalImageHashId];
    }
    
  2. func onDecodedBarcodesReceived(_ result: DecodedBarcodesResult) {
       let originalImage = cvr.getIntermediateResultManager().getOriginalImage(result.originalImageHashId)
    }
    

Include Original Image in Results

Enable original image output in settings so each capture result can directly contain the original image item. This is convenient for downstream processing, but usually adds more data to each result.

  • Objective-C
  • Swift
  1. NSError *error = nil;
    DSSimplifiedCaptureVisionSettings *settings = [self.cvr getSimplifiedSettings:DSPresetTemplateReadBarcodes error:&error];
    // Set outputOriginalImage to YES so the original image will be included in DSCapturedResultReceiver.
    settings.outputOriginalImage = YES;
    [self.cvr updateSettings:DSPresetTemplateReadBarcodes settings:settings error:&error];
    [self.cvr addResultReceiver:self];
    - (void)onCapturedResultReceived:(DSCapturedResult *)result {
       if (result.items.count > 1) {
          for (DSCapturedResultItem *item in result.items) {
             if (item.type == DSCapturedResultItemTypeBarcode) {
                // Use barcode result
             } else if (item.type == DSCapturedResultItemTypeOriginalImage) {
                // Use original image
             }
          }
       }
    }
    
  2. do {
       let settings = try cvr.getSimplifiedSettings(PresetTemplate.readBarcodes.rawValue)
       // Set outputOriginalImage to true so the original image will be included in CapturedResultReceiver.
       settings.outputOriginalImage = true
       try cvr.updateSettings(PresetTemplate.readBarcodes.rawValue, settings: settings)
    } catch {
    }
    cvr.addResultReceiver(self)
    func onCapturedResultReceived(_ result: CapturedResult) {
       if let items = result.items, items.count > 1
       {
          for item in items {
             if item.type == .barcode {
                // Use barcode result
             } else if item.type == .originalImage {
                // Use original image
             }
          }
       }
    }
    

This page is compatible for: