Welcome Guest! To enable all features, please Login or Register.



Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, July 19, 2007 5:54:05 PM(UTC)


Groups: Registered
Posts: 8

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
Dim codecs As RasterCodecs = New RasterCodecs()
Select Case objRadiotype.ToString
Case "tif"
FileName = "C:\apps\vs8\2DBarcode\2Dbarcode\2Dbarcode\workaaa.TIF"
Case "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

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
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)

Select Case objRadiotype.ToString
Case "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")
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
MessageBox.Show("Created Document Successfully")
Catch ex As BarcodeException
Catch ex As RasterException
End Try
End Sub

Thanks & regards.

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Sunday, July 22, 2007 11:35:42 PM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)


I checked your code and found that the problem is related to the codecs.Options.Jpeg.Load.ForceCieLab property in your code.
To resolve the problem, try to set this property to false in your code and retry the same issue.

Please let me know if this helps.

Maen Badwan
LEADTOOLS Technical Support
#3 Posted : Monday, July 23, 2007 2:19:39 PM(UTC)


Groups: Registered
Posts: 8

Cool Guys..It works fine now..

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.119 seconds.