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.ClickIf theImage Is Nothing ThenReturnEnd If' Create a UPC A barcodeDim data As New BarcodeData()data.Symbology = BarcodeSymbology.UPCAdata.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 barcodeDim options As New OneDBarcodeWriteOptions()options.EnableErrorCheck = Trueoptions.TextPosition = BarcodeOutputTextPosition.DefaultTry' Write the barcodebarcodeEngineInstance.Writer.WriteBarcode(theImage, data, options)' Save the imageDim 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 UsingMessageBox.Show(String.Format("The barcode has been written and saved to {0}", saveFileName))Catch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd Sub
private void writeBarcodeButton_Click(object sender, EventArgs e){if(theImage == null){return;}// Create a UPC A barcodeBarcodeData 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 barcodeOneDBarcodeWriteOptions options = new OneDBarcodeWriteOptions();options.EnableErrorCheck = true;options.TextPosition = BarcodeOutputTextPosition.Default;try{// Write the barcodebarcodeEngineInstance.Writer.WriteBarcode(theImage, data, options);// Save the imagestring 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
