Question Save from Picturebox

Aeron_2010

New member
Joined
Aug 22, 2010
Messages
2
Programming Experience
Beginner
Hi! I would like to save directly to drive C: my barcode in picture box. But it seem I am only getting a black screen. Can anyone help me to solve it? Thanks in advance...


Private Sub equivalentvalue()
ArrBarCode(0) = "000110100"
ArrBarCode(1) = "100100001"
ArrBarCode(2) = "001100001"
ArrBarCode(3) = "101100000"
ArrBarCode(4) = "000110001"
ArrBarCode(5) = "100110000"
ArrBarCode(6) = "001110000"
ArrBarCode(7) = "000100101"
ArrBarCode(8) = "100100100"
ArrBarCode(9) = "001100100"
ArrBarCode(10) = "100001001"
ArrBarCode(11) = "001001001"
ArrBarCode(12) = "101001000"
ArrBarCode(13) = "000011001"
ArrBarCode(14) = "100011000"
ArrBarCode(15) = "001011000"
ArrBarCode(16) = "000001101"
ArrBarCode(17) = "100001100"
ArrBarCode(18) = "001001100"
ArrBarCode(19) = "000011100"
ArrBarCode(20) = "100000011"
ArrBarCode(21) = "001000011"
ArrBarCode(22) = "101000010"
ArrBarCode(23) = "000010011"
ArrBarCode(24) = "100010010"
ArrBarCode(25) = "001010010"
ArrBarCode(26) = "000000111"
ArrBarCode(27) = "100000110"
ArrBarCode(28) = "001000110"
ArrBarCode(29) = "000010110"
ArrBarCode(30) = "110000001"
ArrBarCode(31) = "011000001"
ArrBarCode(32) = "111000000"
ArrBarCode(33) = "010010001"
ArrBarCode(34) = "110010000"
ArrBarCode(35) = "011010000"
ArrBarCode(36) = "010000101"
ArrBarCode(37) = "110000100"
ArrBarCode(38) = "011000100"
ArrBarCode(39) = "010101000"
ArrBarCode(40) = "010100010"
ArrBarCode(41) = "010001010"
ArrBarCode(42) = "000101010"
ArrBarCode(43) = "010010100"
End Sub
Sub brcde()
Dim e As Graphics
Dim fnt As Font
fnt = New Font("Comics Sans MS", 10)

Call equivalentvalue()

picBarcode.CreateGraphics.Clear(Color.DarkGray)
pos = 10
BarCode = UCase(txtBorrID.Text)
For x = 1 To Len(BarCode)
Temp = Mid$(BarCode, x, 1)
Select Case Temp
Case "0" To "9"
Codevalue = Val(Temp)
Case "A" To "Z"
Codevalue = Asc(Temp) - 55
Case "-"
Codevalue = 36
Case "."
Codevalue = 37
Case " "
Codevalue = 38
Case "$"
Codevalue = 39
Case "/"
Codevalue = 40
Case "+"
Codevalue = 41
Case "%"
Codevalue = 42
Case "*"
Codevalue = 43
Case Else

picBarcode.CreateGraphics.Clear(Color.DarkGray)
picBarcode.CreateGraphics.DrawString(Temp & "is not valid", fnt, Brushes.Black, 20, 169)
Exit Sub
End Select

For y = 1 To 9
If y / 2 = Int(y / 2) Then
pos = pos + 1 + (3 * Val(Mid$(ArrBarCode(Codevalue), y, 1)))
Else
For z = 1 To 1 + (3 * Val(Mid$(ArrBarCode(Codevalue), y, 1)))
picBarcode.CreateGraphics.DrawLine(Pens.Black, pos, 1, pos, 50)
pos = pos + 1
Next z
End If
Next y
pos = pos + 1
Next x

'picBarcode.Image = CType(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Bitmap)
'picBarcode.Image.Save("C:\barcode.bmp", System.Drawing.Imaging.ImageFormat.Bmp)

Dim bm As New System.Drawing.Bitmap(200, 100)
bm.Save("C:\barcode.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

'picBarcode.Image.Save("C:\barcode.bmp", System.Drawing.Imaging.ImageFormat.Bmp)

End Sub
 
You can use Graphics.FromImage (bm) and draw your bar to the image, then save the image.

For painting in PictureBox you should use the Paint event, and the e.Graphics there.
 

Latest posts

Back
Top