Programming
/ Barcode Reading & Writing
/ Saving images into folders based on their barcode
In This Topic
Saving images into folders based on their barcode
In This Topic
This sample will show you how to sort image files and save them as TIFF files in different folders based on the barcode type that has been detected within the image.
'We assume that GdPicture has been correctly installed and unlocked.
Dim oGdPictureImaging AsNew GdPictureImaging()
Dim filePath As [String] = "Pictures\barcodes"Dim distPath As [String] = "Pictures\barcodeTypes\"Dim allImages As [String]() = Directory.GetFiles(filePath)
Dim bcfound AsInteger = 0
Dim m_Image AsInteger = 0
Dim status As GdPictureStatus = GdPictureStatus.OK
ForEach imagePath AsStringIn allImages
bcfound = 0
m_Image = oGdPictureImaging.CreateGdPictureImageFromFile(imagePath)
If oGdPictureImaging.GetStat() <> GdPictureStatus.OK Then
MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
ExitForEndIf
status = oGdPictureImaging.Barcode1DReaderDoScan(m_Image, Barcode1DReaderScanMode.BestSpeed)
If status <> GdPictureStatus.OK Then
MessageBox.Show("Error: " + status.ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
oGdPictureImaging.ReleaseGdPictureImage(m_Image)
ExitForEndIf
bcfound = oGdPictureImaging.Barcode1DReaderGetBarcodeCount()
If bcfound > 0 ThenFor i AsInteger = 1 To bcfound
Dim barcodeType As [String] = oGdPictureImaging.Barcode1DReaderGetBarcodeType(i).ToString()
Dim folderName As [String] = [String].Concat(barcodeType, "\")
Dim imageName As [String] = [String].Concat(i.ToString(), ".tif")
Dim completePath As [String] = [String].Concat(Path.Combine(distPath, folderName), imageName)
status = oGdPictureImaging.SaveAsTIFF(m_Image, completePath, TiffCompression.TiffCompressionAUTO)
If status <> GdPictureStatus.OK Then
MessageBox.Show("Error: " + status.ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
ExitForEndIfNextEndIf
oGdPictureImaging.ReleaseGdPictureImage(m_Image)
If status <> GdPictureStatus.OK ThenExitForEndIfNext
oGdPictureImaging.Dispose()
Copy Code
//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();