Start Visual Studio.
Start with the project that you created in Reading Barcodes Tutorial
Drag and drop a new button in Form1. Change the following properties:
Property | Value |
---|---|
Name | writeBarcodeButton |
Text | Write barcode |
Add the following code to writeBarcodeButton click procedure:
Private Sub writeBarcodeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles writeBarcodeButton.Click
If theImage Is Nothing Then
Return
End If
' Create a UPC A barcode
Dim data As New BarcodeData()
data.Symbology = BarcodeSymbology.UPCA
data.Value = "01234567890"
data.Bounds = New LeadRect(10, 10, 600, 200)
' Setup the options to enable error checking and show the text on the bottom of the barcode
Dim options As New OneDBarcodeWriteOptions()
options.EnableErrorCheck = True
options.TextPosition = BarcodeOutputTextPosition.Default
Try
' Write the barcode
barcodeEngineInstance.Writer.WriteBarcode(theImage, data, options)
' Save the image
Dim dir As String = System.IO.Path.GetDirectoryName(imageFileName)
Dim name As String = System.IO.Path.GetFileNameWithoutExtension(imageFileName)
Dim saveFileName as String = System.IO.Path.Combine(dir, name + "_WriteBarcode.tif")
Using codecs As New RasterCodecs()
codecs.Save(theImage, saveFileName, RasterImageFormat.Tif, theImage.BitsPerPixel)
End Using
MessageBox.Show(String.Format("The barcode has been written and saved to {0}", saveFileName))
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
private void writeBarcodeButton_Click(object sender, EventArgs e)
{
if(theImage == null)
{
return;
}
// Create a UPC A barcode
BarcodeData data = new BarcodeData();
data.Symbology = BarcodeSymbology.UPCA;
data.Value = "01234567890";
data.Bounds = new LeadRect(10, 10, 600, 200);
// Setup the options to enable error checking and show the text on the bottom of the barcode
OneDBarcodeWriteOptions options = new OneDBarcodeWriteOptions();
options.EnableErrorCheck = true;
options.TextPosition = BarcodeOutputTextPosition.Default;
try
{
// Write the barcode
barcodeEngineInstance.Writer.WriteBarcode(theImage, data, options);
// Save the image
string dir = System.IO.Path.GetDirectoryName(imageFileName);
string name = System.IO.Path.GetFileNameWithoutExtension(imageFileName);
string saveFileName = System.IO.Path.Combine(dir, name + "_WriteBarcode.tif");
using(RasterCodecs codecs = new RasterCodecs())
{
codecs.Save(theImage, saveFileName, RasterImageFormat.Tif, theImage.BitsPerPixel);
}
MessageBox.Show(string.Format("The barcode has been written and saved to {0}", saveFileName));
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document