Start Visual Studio .NET.
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 LogicalRectangle(10, 10, 600, 200, LogicalUnit.Pixel)
' 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 = OneDBarcodeTextPosition.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 LogicalRectangle(10, 10, 600, 200, LogicalUnit.Pixel);
// 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 = OneDBarcodeTextPosition.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);
}
}
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.