Hi ,
I am trying to write Barcode into Jpeg image which is having white background.The vbbarcode demo seems to write and save it with white backround but my code is writing barcode with black background.
Can someone show me which property is really the problem.
I have submitted the code below..
Private Sub WriteBarCode()
Dim barEngine As BarcodeEngine
Dim Image As RasterImage
Dim FileName As String = ""
' Load an image
RasterCodecs.Startup()
Dim codecs As RasterCodecs = New RasterCodecs()
Select Case objRadiotype.ToString
Case "tif"
'tif
FileName = "C:\apps\vs8\2DBarcode\2Dbarcode\2Dbarcode\workaaa.TIF"
Case "pdf"
'pdf
FileName = "C:\apps\vs8\2DBarcode\2Dbarcode\2Dbarcode\2DTEMPLATE.pdf"
Case "jpg"
FileName = "C:\apps\vs8\2DBarcode\2Dbarcode\2Dbarcode\2Dbarcode.JPG"
codecs.Options.Jpeg.Load.DisableMmx = False
codecs.Options.Jpeg.Load.DisableP3 = False
codecs.Options.Jpeg.Load.ForceCieLab = True
codecs.Options.Jpeg.Load.ForceRgbFile = False
codecs.Options.Jpeg.Load.UseBadJpegPredictor = False
End Select
' Get all Information about the file that you want to load.
Dim imageInfo As CodecsImageInfo = codecs.GetInformation(FileName, True)
codecs.ThrowExceptionsOnInvalidImages = True
Try
Image = codecs.Load(FileName)
' Unlock linear barcode support.
' Note that this is a sample key, which will not work in your toolkit
RasterSupport.Unlock(RasterSupportType.Barcodes1D, "")
' Initialize linear barcodes
BarcodeEngine.Startup(BarcodeMajorTypeFlags.Barcodes1d)
barEngine = New BarcodeEngine()
Dim data As BarcodeData = New BarcodeData()
Dim rc As Rectangle = New Rectangle(150, 150, 0, 0)
data.Unit = BarcodeUnit.ScanlinesPerPixels
data.Location = rc
data.SearchType = BarcodeSearchTypeFlags.Pdf417
Dim barcodeText As String()
barcodeText = New String(0) {}
barcodeText(0) = TextBox1.Text
data.Data = BarcodeData.ConvertFromStringArray(barcodeText)
Dim barColor As BarcodeColor = New BarcodeColor()
barColor.BarColor = Color.Black
barColor.SpaceColor = Color.White
Dim bar1d As Barcode1d = New Barcode1d()
Dim barPDF As BarcodeWritePdf = New BarcodeWritePdf()
Dim barDM As BarcodeWriteDatamatrix = New BarcodeWriteDatamatrix()
Dim barQR As BarcodeWriteQr = New BarcodeWriteQr()
Dim BarcodeWriteFlags As BarcodeWriteFlags
BarcodeWriteFlags = BarcodeWriteFlags.None
bar1d.Direction = BarcodeDirectionFlags.Horizontal
barPDF.Justify = BarcodeJustifyFlags.None
barPDF.Columns = 0
barPDF.Rows = 0
barPDF.AspectHeight = 0
barPDF.AspectWidth = 0
barPDF.ModAspectRatio = 0
barPDF.Module = 0
barPDF.EccLevel = Leadtools.Barcode.BarcodePdf417EccLevelFlags.Level0
barPDF.EccPercentage = 0
barDM.Justify = BarcodeJustifyFlags.None
barDM.FileIdHigh = 0
barDM.FileIdLow = 0
barDM.GroupNumber = 0
barDM.GroupTotal = 0
barDM.XModule = 30
barQR.XModule = 30
barEngine.Write(Image, data, barColor, BarcodeWriteFlags.UseColors, bar1d, barPDF, barDM, barQR, Rectangle.Empty)
BarcodeEngine.Shutdown()
'Leadtools.RasterImageFormat.RasPdfJpeg411
Select Case objRadiotype.ToString
Case "tif"
'tif
'for Tif
codecs.Save(Image, "C:\apps\vs8\2DBarcode\2Dbarcode\2Dbarcode\aaawithbarcode.TIF", RasterImageFormat.Tif, Image.BitsPerPixel, 1, Image.PageCount, 1, CodecsSavePageMode.Overwrite)
Case "pdf"
'for pdf
codecs.Save(Image, "C:\apps\vs8\2DBarcode\2Dbarcode\2Dbarcode\2DTEMPLATEwithbarcode.pdf", Leadtools.RasterImageFormat.RasPdf, 0, Image.Page, Image.Page, 1, CodecsSavePageMode.Overwrite)
Case "jpg"
'for jpg
'and assumption is this do not contain any timestamp and lossless Jpeg for image quality
If imageInfo.Jpeg.IsLossless Then
Console.WriteLine("This is a lossless Jpeg Image")
Else
Console.WriteLine("This is not a lossless Jpeg Image")
End If
If imageInfo.Jpeg.IsProgressive Then
codecs.Options.Jpeg.Save.Passes = 0
End If
'codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.MaximumQuality
codecs.Options.Jpeg.Save.DisableMmx = False
codecs.Options.Jpeg.Save.DisableP3 = False
'2 to 255, where 2 is the highest quality and 255 is the most compression and 0 for lossless quality
codecs.Options.Jpeg.Save.QualityFactor = 2
codecs.Options.Jpeg.Save.SaveOldJtif = False
codecs.Save(Image, "C:\apps\vs8\2DBarcode\2Dbarcode\2Dbarcode\2Dbarcodewithbarcode.JPG", RasterImageFormat.Jpeg, Image.BitsPerPixel, 1, Image.PageCount, 1, CodecsSavePageMode.Overwrite)
End Select
Image.Dispose()
MessageBox.Show("Created Document Successfully")
Catch ex As BarcodeException
MessageBox.Show(ex.Message)
Catch ex As RasterException
MessageBox.Show(ex.ToString)
End Try
RasterCodecs.Shutdown()
End Sub
Thanks & regards.