Professional Documents
Culture Documents
QRCode
Imports ThoughtWorks.QRCode.Codec
Imports ThoughtWorks.QRCode.Codec.Data
Public Class formLeerGenerarCodigosQR
Private colorFondoQR As Integer =
Color.FromArgb(255, 255, 255, 255).ToArgb
Private colorQR As Integer =
Color.FromArgb(255, 0, 0, 0).ToArgb
Private Function AdjustQRVersion(ByVal TextEncode As String,
ByVal qrCodeErrCorrect As _
Codec.QRCodeEncoder.ERROR_CORRECTION) As Integer
Dim textb() As Byte =
System.Text.UTF8Encoding.UTF8.GetBytes(TextEncode)
Dim ibits As Integer = ((textb.Length + 1) * 8) + 8
Return -1
Select Case qrCodeErrCorrect
'Correccin de errores del 7%
Case QRCodeEncoder.ERROR_CORRECTION.L
Select Case ibits
Case Is <= 152
Return 1
Case Is <= 272
Return 2
Case Is <= 440
Return 3
Case Is <= 640
Return 4
Case Is <= 864
Return 5
Case Is <= 1088
Return 6
Case Is <= 1248
Return 7
Case Is <= 1552
Return 8
Case Is <= 1856
Return 9
Case Is <= 2192
Return 10
Case Is <= 2592
Return 11
Case Is <= 2960
Return 12
Case Is <= 3424
Return 13
Case Is <= 3688
Return 14
Case Is <= 4184
Return 15
Case Is <= 4712
Return 16
Case Is <= 5176
Return 17
Case Is <= 5768
Return 18
Case Is <= 6360
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Else
Return
End Select
19
6888
20
7456
21
8048
22
8752
23
9392
24
10208
25
10960
26
11744
27
12248
28
13048
29
13880
30
14744
31
15640
32
16568
33
17528
34
18448
35
19472
36
20528
37
21616
38
22496
39
23648
40
-1
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
864
6
992
7
1232
8
1456
9
1728
10
2032
11
2320
12
2672
13
2920
14
3320
15
3624
16
4056
17
4504
18
5016
19
5352
20
5712
21
6256
22
6880
23
7312
24
8000
25
8496
26
9024
27
9544
28
10136
29
10984
30
11640
31
12328
32
13048
33
13800
34
14496
35
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Else
Return
End Select
15312
36
15936
37
16816
38
17728
39
18672
40
-1
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Else
Return
End Select
22
4912
23
5312
24
5744
25
6032
26
6464
27
6968
28
7288
29
7880
30
8264
31
8920
32
9368
33
9848
34
10288
35
10832
36
11408
37
12016
38
12656
39
13328
40
-1
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
Case Is <=
Return
800
9
976
10
1120
11
1264
12
1440
13
1576
14
1784
15
2024
16
2264
17
2504
18
2728
19
3080
20
3248
21
3536
22
3712
23
4112
24
4304
25
4768
26
5024
27
5288
28
5608
29
5960
30
6344
31
6760
32
7208
33
7688
34
7888
35
8432
36
8768
37
9136
38
Case Is <=
Return
Case Is <=
Return
Case Else
Return
End Select
End Select
End Function
9776
39
10208
40
-1
txtEventoDesde.ValueChanged, txtEventoDescripcion.TextChanged
txtTextoQR.Text = "BEGIN:VEVENT" + vbCrLf + "SUMMARY:" +
txtEventoAsunto.Text + vbCrLf +
"DTSTART:" +
txtEventoDesde.Value.Year.ToString("0000") +
txtEventoDesde.Value.Month.ToString("00") +
txtEventoDesde.Value.Day.ToString("00") +
"T" + txtEventoDesdeHora.Value.Hour.ToString("00") +
txtEventoDesdeHora.Value.Minute.ToString("00") +
"00" + vbCrLf +
"DTEND:" + txtEventoHasta.Value.Year.ToString("0000") +
txtEventoHasta.Value.Month.ToString("00") +
txtEventoHasta.Value.Day.ToString("00") +
"T" + txtEventoHastaHora.Value.Hour.ToString("00") +
txtEventoHastaHora.Value.Minute.ToString("00") +
"00" + vbCrLf +
"LOCATION:" + txtEventoUbicacion.Text + vbCrLf +
"DESCRIPTION:" + txtEventoDescripcion.Text +
vbCrLf + "END:VEVENT"
End Sub
Private Sub btGenerarQR_Click(sender As System.Object,
e As System.EventArgs) Handles btGenerarQR.Click
If txtEscalaPixel.Text.Trim = "" Then
MsgBox("Debe indicar la escala de los pxeles del " +
"QR que se generar.",
MsgBoxStyle.Information + MsgBoxStyle.OkOnly)
txtEscalaPixel.Focus()
Else
If Val(txtEscalaPixel.Text) = 0 Then
txtEscalaPixel.Text = 4
End If
Dim generarCodigoQR As QRCodeEncoder = New QRCodeEncoder
generarCodigoQR.QRCodeEncodeMode =
Codec.QRCodeEncoder.ENCODE_MODE.BYTE
generarCodigoQR.QRCodeScale = Int32.Parse(txtEscalaPixel.Text)
Select Case lsNivelCorreccion.Text
Case "Bajo (7%)"
generarCodigoQR.QRCodeErrorCorrect =
Codec.QRCodeEncoder.ERROR_CORRECTION.L
Case "Medio (15%)"
generarCodigoQR.QRCodeErrorCorrect =
Codec.QRCodeEncoder.ERROR_CORRECTION.M
Case "Alto (25%)"
generarCodigoQR.QRCodeErrorCorrect =
Codec.QRCodeEncoder.ERROR_CORRECTION.Q
Case "Muy alto (30%)"
generarCodigoQR.QRCodeErrorCorrect =
Codec.QRCodeEncoder.ERROR_CORRECTION.H
End Select
'La versin "0" calcula automticamente el tamao
generarCodigoQR.QRCodeVersion = 0
'' --------- Forzar una determinada version ----------''En caso de querer forzar una determinada version
'(tamao) el siguiente cdigo devuelve la
If IsNothing(imgQR.Image) Then
MsgBox("No se ha generado el Cdigo QR. Antes de guardar " +
"debe generar un cdigo QR.",
MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Else
dlGuardar.Filter = "JPEG|*.jpg|Mapa de Bits|*.bmp|Gif|*.gif|PNG|*.pn
g"
dlGuardar.Title = "Guardar cdigo QR"
dlGuardar.FileName = "codigo_qr"
dlGuardar.ShowDialog()
If (dlGuardar.FileName <> "") Then
Select Case dlGuardar.FilterIndex
Case 1
imgQR.Image.Save(dlGuardar.FileName,
System.Drawing.Imaging.ImageFormat.Jpeg)
Case 2
imgQR.Image.Save(dlGuardar.FileName,
System.Drawing.Imaging.ImageFormat.Bmp)
Case 3
imgQR.Image.Save(dlGuardar.FileName,
System.Drawing.Imaging.ImageFormat.Gif)
Case 4
imgQR.Image.Save(dlGuardar.FileName,
System.Drawing.Imaging.ImageFormat.Png)
End Select
End If
End If
End Sub
Private Sub btImprimirQR_Click(sender As System.Object,
e As System.EventArgs) Handles btImprimirQR.Click
If IsNothing(imgQR.Image) Then
MsgBox("No se ha generado el Cdigo QR. Antes de " +
"imprimir debe generar un cdigo QR.",
MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Else
dlImprimir.Document = imprimirDoc
If dlImprimir.ShowDialog = Windows.Forms.DialogResult.OK Then
imprimirDoc.Print()
End If
End If
End Sub
Private Sub PrintDocument1_PrintPage(sender As System.Object,
e As System.Drawing.Printing.PrintPageEventArgs) _
Handles imprimirDoc.PrintPage
e.Graphics.DrawImage(imgQR.Image, 0, 0)
End Sub
Private Sub btSelImagenQR_Click(sender As System.Object,
e As System.EventArgs) Handles btSelImagenQR.Click
Dim dlAbrirImagenQR As New OpenFileDialog
dlAbrirImagenQR.InitialDirectory =
My.Computer.FileSystem.SpecialDirectories.MyPictures
dlAbrirImagenQR.Filter = "*.bmp;*.gif;*.jpg;*.png|*.bmp;*.gif;*.jpg;*.pn
g"
dlAbrirImagenQR.RestoreDirectory = True
dlAbrirImagenQR.CheckFileExists = True
dlAbrirImagenQR.CheckPathExists = True
If dlAbrirImagenQR.ShowDialog = Windows.Forms.DialogResult.OK Then
txtLeerQRImagen.Text = dlAbrirImagenQR.FileName
End If
End Sub
Private Sub btDecodificarImagenQR_Click(sender As System.Object,
e As System.EventArgs) Handles btDecodificarImagenQR.Click
If IsNothing(imgQRExistente.Image) Then
MsgBox("Antes de decodificar una imagen QR a su texto " +
"correspondiente QR Code debe seleccionar la imagen.",
MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
btSelImagenQR.Focus()
Else
Try
Dim decoder As QRCodeDecoder = New QRCodeDecoder
If opLeerForzarUTF8.Checked Then
txtLeerQRTexto.Text =
decoder.decode(New QRCodeBitmapImage( _
New Bitmap(imgQRExistente.Image)),
System.Text.Encoding.UTF8)
Else
txtLeerQRTexto.Text =
decoder.decode(New QRCodeBitmapImage( _
New Bitmap(imgQRExistente.Image)))
End If
Catch ex As Exception
MsgBox(ex.Message,
MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
End Try
End If
End Sub
Private Sub txtLeerQRImagen_TextChanged(sender As System.Object,
e As System.EventArgs) Handles txtLeerQRImagen.TextChanged
If System.IO.File.Exists(txtLeerQRImagen.Text) Then
imgQRExistente.Image = New Bitmap(txtLeerQRImagen.Text)
End If
End Sub
Private Sub tabFormatoQR_SelectedIndexChanged(sender As System.Object, _
e As System.EventArgs) Handles tabFormatoQR.SelectedIndexChanged
If tabFormatoQR.SelectedTab Is tabQRSMS Then
txtSMSMensaje_TextChanged(sender, e)
End If
If tabFormatoQR.SelectedTab Is tabQRURL Then
txtURL_TextChanged(sender, e)
End If
If tabFormatoQR.SelectedTab Is tabQRTexto Then
txtTextoLibre_TextChanged(sender, e)
End If
If tabFormatoQR.SelectedTab Is tabQRNumeroTelefono Then
txtNumeroTelefono_TextChanged(sender, e)
End If
If tabFormatoQR.SelectedTab Is tabQRVcard Then
txtVcardNombre_TextChanged(sender, e)
End If
If tabFormatoQR.SelectedTab Is tabQRMAIL Then
txtEMailDestinatario_TextChanged(sender, e)
End If
If tabFormatoQR.SelectedTab Is tabQREvento Then
txtEventoAsunto_TextChanged(sender, e)
End If
If tabFormatoQR.SelectedTab Is tabQRRedWifi Then
txtRedWifiSSID_TextChanged(sender, e)
End If
If tabFormatoQR.SelectedTab Is tabQRGeolocalizacion Then
txtGeoLatitud_TextChanged(sender, e)
End If
End Sub
Private Sub linkURL_LinkClicked(sender As System.Object, _
e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) _
Handles linkURL.LinkClicked
System.Diagnostics.Process.Start("http://www.ajpdsoft.com")
End Sub
End Class