Sunday, March 25, 2012

barcode to image function does not work...

I have built a custom function in my report to convert my barcode data into a
barcode image. The data is a string from the database my images are made
just fine but they are not made as barcodes but as numbers (i.e. 1432808734).
The following is the code I am using:
Public Function CreateBarCodeImage(ByVal sText As String) As Byte()
Dim textLength As Integer = sText.Length
Dim fontSize As Integer = 20
Dim Width As Integer = (fontSize * textLength) - ((fontSize *
textLength) / 3)
Dim Height As Integer = fontSize + 2
'Initialize Graphics
Dim rectF As System.Drawing.RectangleF = New
System.Drawing.RectangleF(0, 0, Width, Height)
Dim pic As System.Drawing.Bitmap = New System.Drawing.Bitmap(Width,
Height, Drawing.Imaging.PixelFormat.Format16bppRgb555)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(pic)
g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
'Set Colors
Dim fontColor As System.Drawing.Color = System.Drawing.Color.FromName("Black")
Dim rectColor As System.Drawing.Color = System.Drawing.Color.FromName("White")
Dim fgBrush As System.Drawing.SolidBrush = New
System.Drawing.SolidBrush(fontColor)
Dim bgBrush As System.Drawing.SolidBrush = New
System.Drawing.SolidBrush(rectColor)
g.FillRectangle(New
System.Drawing.SolidBrush(System.Drawing.Color.White), rectF)
Dim fontName As String = "mrvcode39m.ttf"
Dim style As System.Drawing.FontStyle = Drawing.FontStyle.Regular
Dim font As System.Drawing.Font = New System.Drawing.Font(fontName,
20, style)
Dim format As System.Drawing.StringFormat = New
System.Drawing.StringFormat
g.DrawString(sText, font, fgBrush, rectF, format)
Dim imageBytes() As Byte = Nothing
Dim memoryStream As System.IO.MemoryStream = New
System.IO.MemoryStream
pic.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp)
pic.Dispose()
imageBytes = memoryStream.ToArray()
memoryStream.Close()
Return (imageBytes)
End Function
Can anyone tell me what I am doing wrong? I would like to avoid having to by
something to do this. But I will even do that if someone can help me make it
work.If you're format is CODE 3 of 9 then I suggest that you can use the font for
this.
"CarrieWells" wrote:
> I have built a custom function in my report to convert my barcode data into a
> barcode image. The data is a string from the database my images are made
> just fine but they are not made as barcodes but as numbers (i.e. 1432808734).
> The following is the code I am using:
> Public Function CreateBarCodeImage(ByVal sText As String) As Byte()
> Dim textLength As Integer = sText.Length
> Dim fontSize As Integer = 20
> Dim Width As Integer = (fontSize * textLength) - ((fontSize *
> textLength) / 3)
> Dim Height As Integer = fontSize + 2
> 'Initialize Graphics
> Dim rectF As System.Drawing.RectangleF = New
> System.Drawing.RectangleF(0, 0, Width, Height)
> Dim pic As System.Drawing.Bitmap = New System.Drawing.Bitmap(Width,
> Height, Drawing.Imaging.PixelFormat.Format16bppRgb555)
> Dim g As System.Drawing.Graphics => System.Drawing.Graphics.FromImage(pic)
> g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
> g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
> 'Set Colors
> Dim fontColor As System.Drawing.Color => System.Drawing.Color.FromName("Black")
> Dim rectColor As System.Drawing.Color => System.Drawing.Color.FromName("White")
> Dim fgBrush As System.Drawing.SolidBrush = New
> System.Drawing.SolidBrush(fontColor)
> Dim bgBrush As System.Drawing.SolidBrush = New
> System.Drawing.SolidBrush(rectColor)
> g.FillRectangle(New
> System.Drawing.SolidBrush(System.Drawing.Color.White), rectF)
> Dim fontName As String = "mrvcode39m.ttf"
> Dim style As System.Drawing.FontStyle = Drawing.FontStyle.Regular
> Dim font As System.Drawing.Font = New System.Drawing.Font(fontName,
> 20, style)
> Dim format As System.Drawing.StringFormat = New
> System.Drawing.StringFormat
> g.DrawString(sText, font, fgBrush, rectF, format)
> Dim imageBytes() As Byte = Nothing
> Dim memoryStream As System.IO.MemoryStream = New
> System.IO.MemoryStream
> pic.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp)
> pic.Dispose()
> imageBytes = memoryStream.ToArray()
> memoryStream.Close()
> Return (imageBytes)
> End Function
> Can anyone tell me what I am doing wrong? I would like to avoid having to by
> something to do this. But I will even do that if someone can help me make it
> work.|||I tried that first but the fields using the 3 of 9 font won't export to
Adobe; the field just shows up blank. My customer has to have that piece of
functionality. All the other posts that talked about this issue said the
solution was to turn the barcoded text into an image. But I can't get my
funtion to work.
I'm sure I've either left soemthing it needs out, I just can't figure out
what.
"Jon Gonzales" wrote:
> If you're format is CODE 3 of 9 then I suggest that you can use the font for
> this.
> "CarrieWells" wrote:
> > I have built a custom function in my report to convert my barcode data into a
> > barcode image. The data is a string from the database my images are made
> > just fine but they are not made as barcodes but as numbers (i.e. 1432808734).
> > The following is the code I am using:
> >
> > Public Function CreateBarCodeImage(ByVal sText As String) As Byte()
> > Dim textLength As Integer = sText.Length
> > Dim fontSize As Integer = 20
> > Dim Width As Integer = (fontSize * textLength) - ((fontSize *
> > textLength) / 3)
> > Dim Height As Integer = fontSize + 2
> >
> > 'Initialize Graphics
> > Dim rectF As System.Drawing.RectangleF = New
> > System.Drawing.RectangleF(0, 0, Width, Height)
> > Dim pic As System.Drawing.Bitmap = New System.Drawing.Bitmap(Width,
> > Height, Drawing.Imaging.PixelFormat.Format16bppRgb555)
> > Dim g As System.Drawing.Graphics => > System.Drawing.Graphics.FromImage(pic)
> >
> > g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
> > g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
> >
> > 'Set Colors
> > Dim fontColor As System.Drawing.Color => > System.Drawing.Color.FromName("Black")
> > Dim rectColor As System.Drawing.Color => > System.Drawing.Color.FromName("White")
> > Dim fgBrush As System.Drawing.SolidBrush = New
> > System.Drawing.SolidBrush(fontColor)
> > Dim bgBrush As System.Drawing.SolidBrush = New
> > System.Drawing.SolidBrush(rectColor)
> >
> > g.FillRectangle(New
> > System.Drawing.SolidBrush(System.Drawing.Color.White), rectF)
> >
> > Dim fontName As String = "mrvcode39m.ttf"
> > Dim style As System.Drawing.FontStyle = Drawing.FontStyle.Regular
> > Dim font As System.Drawing.Font = New System.Drawing.Font(fontName,
> > 20, style)
> >
> > Dim format As System.Drawing.StringFormat = New
> > System.Drawing.StringFormat
> >
> > g.DrawString(sText, font, fgBrush, rectF, format)
> >
> > Dim imageBytes() As Byte = Nothing
> >
> > Dim memoryStream As System.IO.MemoryStream = New
> > System.IO.MemoryStream
> >
> > pic.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp)
> > pic.Dispose()
> >
> > imageBytes = memoryStream.ToArray()
> > memoryStream.Close()
> >
> > Return (imageBytes)
> > End Function
> >
> > Can anyone tell me what I am doing wrong? I would like to avoid having to by
> > something to do this. But I will even do that if someone can help me make it
> > work.|||When I look into your code, It seems that you use the font also but whats the
code for? Are you aware that you can use the font in design time, as long as
the font was installed in your system. You can just have a TextBox control
with a font of that and set the border and readonly property of the control.
Remember, every computer that uses your system must have the font of code 39
installed on each.
Regards.|||Were you able to get it running? I am having the same problem with
Code 3 of 9.
What is happening on my app. is that in RS it looks fine but when
exporting to PDF, I get the values not converted to C39, just numbers.
this is also happening on zipcode fonts and OCR-A fonts.
"CarrieWells" <CarrieWells@.discussions.microsoft.com> wrote in message news:<F34A7BBB-94D4-47D9-BB9E-706F1AF6C5CB@.microsoft.com>...
> I tried that first but the fields using the 3 of 9 font won't export to
> Adobe; the field just shows up blank. My customer has to have that piece of
> functionality. All the other posts that talked about this issue said the
> solution was to turn the barcoded text into an image. But I can't get my
> funtion to work.
> I'm sure I've either left soemthing it needs out, I just can't figure out
> what.
>
> "Jon Gonzales" wrote:
> > If you're format is CODE 3 of 9 then I suggest that you can use the font for
> > this.
> >
> > "CarrieWells" wrote:
> >
> > > I have built a custom function in my report to convert my barcode data into a
> > > barcode image. The data is a string from the database my images are made
> > > just fine but they are not made as barcodes but as numbers (i.e. 1432808734).
> > > The following is the code I am using:
> > >
> > > Public Function CreateBarCodeImage(ByVal sText As String) As Byte()
> > > Dim textLength As Integer = sText.Length
> > > Dim fontSize As Integer = 20
> > > Dim Width As Integer = (fontSize * textLength) - ((fontSize *
> > > textLength) / 3)
> > > Dim Height As Integer = fontSize + 2
> > >
> > > 'Initialize Graphics
> > > Dim rectF As System.Drawing.RectangleF = New
> > > System.Drawing.RectangleF(0, 0, Width, Height)
> > > Dim pic As System.Drawing.Bitmap = New System.Drawing.Bitmap(Width,
> > > Height, Drawing.Imaging.PixelFormat.Format16bppRgb555)
> > > Dim g As System.Drawing.Graphics => > > System.Drawing.Graphics.FromImage(pic)
> > >
> > > g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
> > > g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
> > >
> > > 'Set Colors
> > > Dim fontColor As System.Drawing.Color => > > System.Drawing.Color.FromName("Black")
> > > Dim rectColor As System.Drawing.Color => > > System.Drawing.Color.FromName("White")
> > > Dim fgBrush As System.Drawing.SolidBrush = New
> > > System.Drawing.SolidBrush(fontColor)
> > > Dim bgBrush As System.Drawing.SolidBrush = New
> > > System.Drawing.SolidBrush(rectColor)
> > >
> > > g.FillRectangle(New
> > > System.Drawing.SolidBrush(System.Drawing.Color.White), rectF)
> > >
> > > Dim fontName As String = "mrvcode39m.ttf"
> > > Dim style As System.Drawing.FontStyle = Drawing.FontStyle.Regular
> > > Dim font As System.Drawing.Font = New System.Drawing.Font(fontName,
> > > 20, style)
> > >
> > > Dim format As System.Drawing.StringFormat = New
> > > System.Drawing.StringFormat
> > >
> > > g.DrawString(sText, font, fgBrush, rectF, format)
> > >
> > > Dim imageBytes() As Byte = Nothing
> > >
> > > Dim memoryStream As System.IO.MemoryStream = New
> > > System.IO.MemoryStream
> > >
> > > pic.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp)
> > > pic.Dispose()
> > >
> > > imageBytes = memoryStream.ToArray()
> > > memoryStream.Close()
> > >
> > > Return (imageBytes)
> > > End Function
> > >
> > > Can anyone tell me what I am doing wrong? I would like to avoid having to by
> > > something to do this. But I will even do that if someone can help me make it
> > > work.

No comments:

Post a Comment