Saving images into folders based on their barcode
This example shows how to sort image files and save them as TIFF files in different folders based on the barcode type detected within the image.
//We assume that GdPicture has been correctly installed and unlocked.GdPictureImaging oGdPictureImaging = new GdPictureImaging();String filePath = "Pictures\\barcodes";String distPath = "Pictures\\barcodeTypes\\";String[] allImages = Directory.GetFiles(filePath);int bcfound = 0;int m_Image = 0;GdPictureStatus status = GdPictureStatus.OK;foreach (string imagePath in allImages){ bcfound = 0; m_Image = oGdPictureImaging.CreateGdPictureImageFromFile(imagePath); if (oGdPictureImaging.GetStat() != GdPictureStatus.OK) { MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } status = oGdPictureImaging.Barcode1DReaderDoScan(m_Image, Barcode1DReaderScanMode.BestSpeed); if (status != GdPictureStatus.OK) { MessageBox.Show("Error: " + status.ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error); oGdPictureImaging.ReleaseGdPictureImage(m_Image); break; } bcfound = oGdPictureImaging.Barcode1DReaderGetBarcodeCount(); if (bcfound > 0) { for (int i = 1; i <= bcfound; i++) { String barcodeType = oGdPictureImaging.Barcode1DReaderGetBarcodeType(i).ToString(); String folderName = String.Concat(barcodeType, "\\"); String imageName = String.Concat(i.ToString(), ".tif"); String completePath = String.Concat(Path.Combine(distPath, folderName), imageName); status = oGdPictureImaging.SaveAsTIFF(m_Image, completePath, TiffCompression.TiffCompressionAUTO); if (status != GdPictureStatus.OK) { MessageBox.Show("Error: " + status.ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } } oGdPictureImaging.ReleaseGdPictureImage(m_Image); if (status != GdPictureStatus.OK) break;}oGdPictureImaging.Dispose();
This code sample is an example that illustrates how to use our SDK. Please adapt it to your specific use case.