or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

data-structures.mdimage-processing.mdindex.mdqrcode-support.mdreading-decoding.mdresult-processing.mdwriting-encoding.md

result-processing.mddocs/

0

# Result Processing

1

2

Comprehensive result handling system with metadata extraction, structured data parsing, and extensible content interpretation for different barcode data types.

3

4

## Capabilities

5

6

### Result Class

7

8

Core result object containing decoded barcode data and associated metadata.

9

10

```java { .api }

11

/**

12

* Encapsulates the result of decoding a barcode within an image

13

* Contains text content, raw data, detection points, and metadata

14

*/

15

public final class Result {

16

/**

17

* Constructor with basic result data

18

* @param text Decoded text content

19

* @param rawBytes Raw byte data (may be null)

20

* @param resultPoints Detection points in the image

21

* @param format Barcode format that was decoded

22

*/

23

public Result(String text, byte[] rawBytes, ResultPoint[] resultPoints, BarcodeFormat format);

24

25

/**

26

* Constructor with timestamp

27

* @param text Decoded text content

28

* @param rawBytes Raw byte data (may be null)

29

* @param resultPoints Detection points in the image

30

* @param format Barcode format that was decoded

31

* @param timestamp When the barcode was decoded

32

*/

33

public Result(String text, byte[] rawBytes, ResultPoint[] resultPoints,

34

BarcodeFormat format, long timestamp);

35

36

/**

37

* Constructor with bit count specification

38

* @param text Decoded text content

39

* @param rawBytes Raw byte data (may be null)

40

* @param numBits Number of valid bits in rawBytes

41

* @param resultPoints Detection points in the image

42

* @param format Barcode format that was decoded

43

* @param timestamp When the barcode was decoded

44

*/

45

public Result(String text, byte[] rawBytes, int numBits, ResultPoint[] resultPoints,

46

BarcodeFormat format, long timestamp);

47

48

/**

49

* Get the decoded text content

50

* @return Text content encoded in the barcode

51

*/

52

public String getText();

53

54

/**

55

* Get raw byte data if available

56

* @return Raw bytes from barcode, or null if not available

57

*/

58

public byte[] getRawBytes();

59

60

/**

61

* Get number of valid bits in raw byte data

62

* @return Number of valid bits (typically 8 * rawBytes.length)

63

*/

64

public int getNumBits();

65

66

/**

67

* Get detection points in the image

68

* @return Array of points identifying barcode location

69

*/

70

public ResultPoint[] getResultPoints();

71

72

/**

73

* Get the barcode format

74

* @return Format of the decoded barcode

75

*/

76

public BarcodeFormat getBarcodeFormat();

77

78

/**

79

* Get result metadata

80

* @return Map of metadata, may be null

81

*/

82

public Map<ResultMetadataType,Object> getResultMetadata();

83

84

/**

85

* Get decode timestamp

86

* @return Timestamp when barcode was decoded

87

*/

88

public long getTimestamp();

89

90

/**

91

* Add metadata entry

92

* @param type Metadata type

93

* @param value Metadata value

94

*/

95

public void putMetadata(ResultMetadataType type, Object value);

96

97

/**

98

* Add multiple metadata entries

99

* @param metadata Map of metadata to add

100

*/

101

public void putAllMetadata(Map<ResultMetadataType,Object> metadata);

102

103

/**

104

* Add additional result points

105

* @param newPoints Additional points to add

106

*/

107

public void addResultPoints(ResultPoint[] newPoints);

108

}

109

```

110

111

**Usage Examples:**

112

113

```java

114

import com.google.zxing.*;

115

116

// Basic result processing

117

MultiFormatReader reader = new MultiFormatReader();

118

Result result = reader.decode(binaryBitmap);

119

120

String content = result.getText();

121

BarcodeFormat format = result.getBarcodeFormat();

122

ResultPoint[] points = result.getResultPoints();

123

124

System.out.println("Decoded: " + content);

125

System.out.println("Format: " + format);

126

System.out.println("Found at " + points.length + " detection points");

127

128

// Access raw byte data if available

129

byte[] rawBytes = result.getRawBytes();

130

if (rawBytes != null) {

131

System.out.println("Raw data: " + rawBytes.length + " bytes");

132

System.out.println("Valid bits: " + result.getNumBits());

133

}

134

135

// Check for metadata

136

Map<ResultMetadataType, Object> metadata = result.getResultMetadata();

137

if (metadata != null) {

138

for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {

139

System.out.println(entry.getKey() + ": " + entry.getValue());

140

}

141

}

142

```

143

144

### Result Point

145

146

Represents a point in the image related to barcode detection (corners, finder patterns, etc.).

147

148

```java { .api }

149

/**

150

* Represents a point of interest in barcode detection

151

* Typically corners or finder pattern centers

152

*/

153

public class ResultPoint {

154

/**

155

* Constructor for result point

156

* @param x X coordinate in pixels

157

* @param y Y coordinate in pixels

158

*/

159

public ResultPoint(float x, float y);

160

161

/**

162

* Get X coordinate

163

* @return X position in pixels

164

*/

165

public final float getX();

166

167

/**

168

* Get Y coordinate

169

* @return Y position in pixels

170

*/

171

public final float getY();

172

173

/**

174

* Calculate Euclidean distance to another point

175

* @param other Other point

176

* @return Distance in pixels

177

*/

178

public final float distance(ResultPoint other);

179

180

/**

181

* Calculate squared distance (faster than distance)

182

* @param other Other point

183

* @return Squared distance

184

*/

185

public final float distanceSquared(ResultPoint other);

186

}

187

```

188

189

### Result Metadata Types

190

191

Enumeration of metadata that can be associated with decoding results.

192

193

```java { .api }

194

/**

195

* Types of metadata that can be associated with barcode results

196

*/

197

public enum ResultMetadataType {

198

/**

199

* Orientation of the barcode in the image

200

* Value: Integer (degrees)

201

*/

202

ORIENTATION,

203

204

/**

205

* Byte segments found in the barcode

206

* Value: List<byte[]>

207

*/

208

BYTE_SEGMENTS,

209

210

/**

211

* Error correction level used

212

* Value: String or error correction level object

213

*/

214

ERROR_CORRECTION_LEVEL,

215

216

/**

217

* Number of errors corrected during decoding

218

* Value: Integer

219

*/

220

ERRORS_CORRECTED,

221

222

/**

223

* Number of erasures corrected during decoding

224

* Value: Integer

225

*/

226

ERASURES_CORRECTED,

227

228

/**

229

* Issue number for certain magazine/periodical barcodes

230

* Value: Integer

231

*/

232

ISSUE_NUMBER,

233

234

/**

235

* Suggested retail price from barcode

236

* Value: String

237

*/

238

SUGGESTED_PRICE,

239

240

/**

241

* Possible country of origin

242

* Value: String (country code)

243

*/

244

POSSIBLE_COUNTRY,

245

246

/**

247

* UPC/EAN extension data

248

* Value: String

249

*/

250

UPC_EAN_EXTENSION,

251

252

/**

253

* PDF417-specific extra metadata

254

* Value: PDF417ResultMetadata object

255

*/

256

PDF417_EXTRA_METADATA,

257

258

/**

259

* Structured append sequence number

260

* Value: Integer

261

*/

262

STRUCTURED_APPEND_SEQUENCE,

263

264

/**

265

* Structured append parity data

266

* Value: Integer

267

*/

268

STRUCTURED_APPEND_PARITY,

269

270

/**

271

* Symbology identifier for the barcode

272

* Value: String

273

*/

274

SYMBOLOGY_IDENTIFIER

275

}

276

```

277

278

### Structured Result Parsing

279

280

Framework for parsing barcode content into structured data types (contacts, URLs, WiFi settings, etc.).

281

282

```java { .api }

283

/**

284

* Base class for parsing barcode results into structured data

285

*/

286

public abstract class ResultParser {

287

/**

288

* Main entry point for parsing barcode results

289

* Automatically detects content type and delegates to appropriate parser

290

* @param result Decoded barcode result

291

* @return Parsed structured data, or TextParsedResult if no specific parser matches

292

*/

293

public static ParsedResult parseResult(Result result);

294

295

/**

296

* Abstract method for format-specific parsing

297

* @param result Decoded barcode result

298

* @return Parsed result or null if this parser doesn't handle the content

299

*/

300

public abstract ParsedResult parse(Result result);

301

}

302

303

/**

304

* Base class for structured parsed results

305

*/

306

public abstract class ParsedResult {

307

/**

308

* Get the type of parsed result

309

* @return Type classification

310

*/

311

public abstract ParsedResultType getType();

312

313

/**

314

* Get display-friendly representation

315

* @return Human-readable display text

316

*/

317

public abstract String getDisplayResult();

318

}

319

```

320

321

### Parsed Result Types

322

323

Various structured data types that can be extracted from barcode content.

324

325

```java { .api }

326

/**

327

* Types of structured data that can be parsed from barcodes

328

*/

329

public enum ParsedResultType {

330

ADDRESSBOOK, // Contact information (vCard)

331

EMAIL_ADDRESS, // Email addresses

332

PRODUCT, // Product codes (UPC, EAN)

333

URI, // URLs and URIs

334

TEXT, // Plain text

335

GEO, // Geographic coordinates

336

TEL, // Telephone numbers

337

SMS, // SMS messages

338

CALENDAR, // Calendar events

339

WIFI, // WiFi network configuration

340

ISBN, // Book ISBN codes

341

VIN // Vehicle identification numbers

342

}

343

```

344

345

### Specific Parsed Result Classes

346

347

```java { .api }

348

/**

349

* Parsed URI/URL result

350

*/

351

public final class URIParsedResult extends ParsedResult {

352

public String getURI();

353

public String getTitle();

354

}

355

356

/**

357

* Parsed email address result

358

*/

359

public final class EmailAddressParsedResult extends ParsedResult {

360

public String[] getTos();

361

public String[] getCCs();

362

public String[] getBCCs();

363

public String getSubject();

364

public String getBody();

365

}

366

367

/**

368

* Parsed contact information result

369

*/

370

public final class AddressBookParsedResult extends ParsedResult {

371

public String[] getNames();

372

public String[] getPhoneNumbers();

373

public String[] getPhoneTypes();

374

public String[] getEmails();

375

public String[] getEmailTypes();

376

public String getInstantMessenger();

377

public String getNote();

378

public String[] getAddresses();

379

public String[] getAddressTypes();

380

public String getTitle();

381

public String getOrg();

382

public String[] getURLs();

383

public String getBirthday();

384

public String[] getGeo();

385

}

386

387

/**

388

* Parsed WiFi configuration result

389

*/

390

public final class WifiParsedResult extends ParsedResult {

391

public String getSsid();

392

public String getNetworkEncryption();

393

public String getPassword();

394

public boolean isHidden();

395

public String getIdentity();

396

public String getAnonymousIdentity();

397

public String getEapMethod();

398

public String getPhase2Method();

399

}

400

401

/**

402

* Parsed geographic coordinates result

403

*/

404

public final class GeoParsedResult extends ParsedResult {

405

public double getLatitude();

406

public double getLongitude();

407

public double getAltitude();

408

public String getQuery();

409

}

410

411

/**

412

* Parsed SMS message result

413

*/

414

public final class SMSParsedResult extends ParsedResult {

415

public String[] getNumbers();

416

public String[] getVias();

417

public String getSubject();

418

public String getBody();

419

}

420

421

/**

422

* Parsed telephone number result

423

*/

424

public final class TelParsedResult extends ParsedResult {

425

public String getNumber();

426

public String getTelURI();

427

public String getTitle();

428

}

429

430

/**

431

* Parsed calendar event result

432

*/

433

public final class CalendarParsedResult extends ParsedResult {

434

public String getSummary();

435

public Date getStart();

436

public boolean isStartAllDay();

437

public Date getEnd();

438

public boolean isEndAllDay();

439

public String getLocation();

440

public String getOrganizer();

441

public String[] getAttendees();

442

public String getDescription();

443

public double getLatitude();

444

public double getLongitude();

445

}

446

447

/**

448

* Parsed product code result

449

*/

450

public final class ProductParsedResult extends ParsedResult {

451

public String getProductID();

452

public String getNormalizedProductID();

453

}

454

455

/**

456

* Plain text result (fallback)

457

*/

458

public final class TextParsedResult extends ParsedResult {

459

public String getText();

460

public String getLanguage();

461

}

462

```

463

464

**Structured Parsing Examples:**

465

466

```java

467

import com.google.zxing.client.result.*;

468

469

// Parse any barcode result into structured data

470

Result rawResult = reader.decode(binaryBitmap);

471

ParsedResult parsed = ResultParser.parseResult(rawResult);

472

473

switch (parsed.getType()) {

474

case URI:

475

URIParsedResult uri = (URIParsedResult) parsed;

476

System.out.println("URL: " + uri.getURI());

477

break;

478

479

case EMAIL_ADDRESS:

480

EmailAddressParsedResult email = (EmailAddressParsedResult) parsed;

481

System.out.println("To: " + Arrays.toString(email.getTos()));

482

System.out.println("Subject: " + email.getSubject());

483

break;

484

485

case WIFI:

486

WifiParsedResult wifi = (WifiParsedResult) parsed;

487

System.out.println("SSID: " + wifi.getSsid());

488

System.out.println("Password: " + wifi.getPassword());

489

System.out.println("Security: " + wifi.getNetworkEncryption());

490

break;

491

492

case ADDRESSBOOK:

493

AddressBookParsedResult contact = (AddressBookParsedResult) parsed;

494

System.out.println("Name: " + Arrays.toString(contact.getNames()));

495

System.out.println("Phones: " + Arrays.toString(contact.getPhoneNumbers()));

496

System.out.println("Emails: " + Arrays.toString(contact.getEmails()));

497

break;

498

499

case GEO:

500

GeoParsedResult geo = (GeoParsedResult) parsed;

501

System.out.println("Location: " + geo.getLatitude() + ", " + geo.getLongitude());

502

break;

503

504

case TEXT:

505

default:

506

TextParsedResult text = (TextParsedResult) parsed;

507

System.out.println("Text: " + text.getText());

508

break;

509

}

510

```

511

512

### Multiple Barcode Processing

513

514

Support for detecting and processing multiple barcodes in a single image.

515

516

```java { .api }

517

/**

518

* Interface for readers that can detect multiple barcodes

519

*/

520

public interface MultipleBarcodeReader {

521

/**

522

* Decode multiple barcodes from an image

523

* @param image Binary bitmap containing barcodes

524

* @return Array of decoded results

525

* @throws NotFoundException if no barcodes found

526

*/

527

Result[] decodeMultiple(BinaryBitmap image) throws NotFoundException;

528

529

/**

530

* Decode multiple barcodes with hints

531

* @param image Binary bitmap containing barcodes

532

* @param hints Decoding configuration hints

533

* @return Array of decoded results

534

* @throws NotFoundException if no barcodes found

535

*/

536

Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException;

537

}

538

539

/**

540

* Generic implementation for multiple barcode detection

541

*/

542

public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader {

543

/**

544

* Create multiple barcode reader

545

* @param delegate Single barcode reader to use for each detection

546

*/

547

public GenericMultipleBarcodeReader(Reader delegate);

548

}

549

```

550

551

**Multiple Barcode Example:**

552

553

```java

554

// Decode multiple barcodes from one image

555

GenericMultipleBarcodeReader multiReader =

556

new GenericMultipleBarcodeReader(new MultiFormatReader());

557

558

try {

559

Result[] results = multiReader.decodeMultiple(binaryBitmap);

560

561

System.out.println("Found " + results.length + " barcodes:");

562

for (int i = 0; i < results.length; i++) {

563

Result result = results[i];

564

System.out.println((i + 1) + ". " + result.getText() +

565

" (" + result.getBarcodeFormat() + ")");

566

567

// Parse each result individually

568

ParsedResult parsed = ResultParser.parseResult(result);

569

System.out.println(" Type: " + parsed.getType());

570

}

571

} catch (NotFoundException e) {

572

System.out.println("No barcodes found in image");

573

}

574

```

575

576

## Advanced Result Processing

577

578

### Custom Result Parsers

579

580

You can create custom parsers for specialized barcode content formats:

581

582

```java

583

public class CustomResultParser extends ResultParser {

584

@Override

585

public ParsedResult parse(Result result) {

586

String text = result.getText();

587

588

// Check if this parser handles the content

589

if (!text.startsWith("CUSTOM:")) {

590

return null; // Not handled by this parser

591

}

592

593

// Parse custom format

594

return new CustomParsedResult(text);

595

}

596

}

597

598

// Register custom parser (implementation-dependent)

599

```

600

601

### Metadata Analysis

602

603

Extract detailed information from barcode metadata:

604

605

```java

606

public void analyzeResult(Result result) {

607

Map<ResultMetadataType, Object> metadata = result.getResultMetadata();

608

if (metadata == null) return;

609

610

// Check error correction info

611

Object errorCorrection = metadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);

612

if (errorCorrection != null) {

613

System.out.println("Error correction: " + errorCorrection);

614

}

615

616

// Check if errors were corrected

617

Integer errorscorrected = (Integer) metadata.get(ResultMetadataType.ERRORS_CORRECTED);

618

if (errorsCorreected != null && errorsCorreected > 0) {

619

System.out.println("Corrected " + errorsCorreected + " errors");

620

}

621

622

// Check orientation

623

Integer orientation = (Integer) metadata.get(ResultMetadataType.ORIENTATION);

624

if (orientation != null) {

625

System.out.println("Barcode orientation: " + orientation + " degrees");

626

}

627

}

628

```