|
-
Nov 1st, 2005, 04:10 PM
#1
Thread Starter
Hyperactive Member
Resize Picture
Hello, I have a program that makes a barcode on a picturebox that is on my form, then saves it to a file. Below is the code:
VB Code:
Private Sub CreateBarcode()
Dim X As Integer, Y As Integer, z As Integer, pos As Integer
Dim Barcode As String
Dim Cur As String
Dim CurVal As Integer
Dim BC(43) As String
BC(0) = "000110100" '0
BC(1) = "100100001" '1
BC(2) = "001100001" '2
BC(3) = "101100000" '3
BC(4) = "000110001" '4
BC(5) = "100110000" '5
BC(6) = "001110000" '6
BC(7) = "000100101" '7
BC(8) = "100100100" '8
BC(9) = "001100100" '9
BC(10) = "100001001" 'A
BC(11) = "001001001" 'B
BC(12) = "101001000" 'C
BC(13) = "000011001" 'D
BC(14) = "100011000" 'E
BC(15) = "001011000" 'F
BC(16) = "000001101"
BC(17) = "100001100"
BC(18) = "001001100"
BC(19) = "000011100"
BC(20) = "100000011"
BC(21) = "001000011"
BC(22) = "101000010"
BC(23) = "000010011"
BC(24) = "100010010"
BC(25) = "001010010"
BC(26) = "000000111"
BC(27) = "100000110"
BC(28) = "001000110"
BC(29) = "000010110"
BC(30) = "110000001"
BC(31) = "011000001"
BC(32) = "111000000" 'W
BC(33) = "010010001" 'X
BC(34) = "110010000" 'Y
BC(35) = "011010000" 'Z
BC(36) = "010000101" '-
BC(37) = "110000100" '.
BC(38) = "011000100" '<spc>
BC(39) = "010101000" '$
BC(40) = "010100010" '/
BC(41) = "010001010" '+
BC(42) = "000101010" '%
BC(43) = "010010100" '* (used for start/stop character only)
picBarCode.Cls
pos = 10
Barcode = UCase(FixedItemCode) 'fixeditem code = the charactes in a textbox that is entered and converted to a barcode.
'Add Start & Stop characters
Barcode = "*" & Barcode & "*"
'Generate Barcode
For X = 1 To Len(Barcode)
Cur = Mid$(Barcode, X, 1)
Select Case Cur
Case "0" To "9"
CurVal = Val(Cur)
Case "A" To "Z"
CurVal = Asc(Cur) - 55
Case "-"
CurVal = 36
Case "."
CurVal = 37
Case " "
CurVal = 38
Case "$"
CurVal = 39
Case "/"
CurVal = 40
Case "+"
CurVal = 41
Case "%"
CurVal = 42
Case "*"
CurVal = 43
Case Else 'oops!
picBarCode.Cls
picBarCode.Print Cur & " is Invalid"
Exit Sub
End Select
For Y = 1 To 9
If Y / 2 = Int(Y / 2) Then
'SPACE
pos = pos + 1 + (3 * Val(Mid$(BC(CurVal), Y, 1)))
Else
'BAR
For z = 1 To 1 + (3 * Val(Mid$(BC(CurVal), Y, 1)))
picBarCode.Line (pos, 1)-(pos, 50)
pos = pos + 1
Next z
End If
Next Y
pos = pos + 1 'make inter-character gap (ie: 1 narrow space)
Next X
picBarCode.CurrentX = Len(Barcode) * 7 'kinda center
picBarCode.Print Barcode
SavePicture picBarCode.Image, BarcodePicture
My question is, right now I have a picturebox that is 8835 twips wide...is there a way that I can have it automatically resize to the size of whatever the barcode is? Say the picturebox starts out at 8835 twips...when a barcode is generated, and the barcode itself only takes up 1000 twips...it resizes the picturebox and centers the barcode.
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
Nov 2nd, 2005, 10:12 AM
#2
Thread Starter
Hyperactive Member
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
Nov 3rd, 2005, 12:48 AM
#3
Re: Resize Picture
Easiest that comes to my mind is that you resize the picturebox to the required size, then draw the new barcode and then have the picturebox inside another picturebox and center it.
As a tip, you could set ScaleMode to vbPixels to be sure you don't draw to certain position multiple times. And then the code to center something inside something:
VB Code:
Picture2.Move (Picture1.ScaleWidth - Picture2.Width) \ 2, (Picture1.ScaleHeight - Picture2.Height) \ 2
-
Nov 3rd, 2005, 07:31 AM
#4
Thread Starter
Hyperactive Member
Re: Resize Picture
I don't believe that would work, in theory I could have a barcode that took up 1 inch...and I could have a barcode that took up 6 inches.
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
Nov 3rd, 2005, 09:01 AM
#5
Re: Resize Picture
It is all about calculation:
1. you know how big your barcode needs to be (= how many items)
2. thus you know how to calculate how many pixels you need (you could pretend to draw it, but instead you just calculate the space you need; same code, you just don't draw)
3. you resize the picturebox to your needs
4. you center the picturebox inside the other picturebox
5. you draw the barcode
I can't see a problem.
-
Nov 3rd, 2005, 10:30 AM
#6
Thread Starter
Hyperactive Member
Re: Resize Picture
I found for my needs, this comes pretty close:
VB Code:
picBarCode.Width = picBarCode.Width + (Len(Barcode) * 275)
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|