トップ回答者
Code128の出力に関して

質問
-
vbの画面上に最大18桁のバーコードを出力したいのですが、何をどうすればできますか?
種類はCode128です。
例えば
画面に18桁のTextBoxと『実行』と書いたボタンと、Code128の出力用の何かしらのコントロールがあるとします。
『実行』ボタン押下で、Code128の出力用の何かしらのコントロールに出力するには何が必要で、どういう記述になりますか?
アウトプットは、まずは画面で考えています。
画面をハンディスキャナで画面を読み込めたらOKです。
TextBoxの中を削除して、TextBoxにカーソルを充てた状態でスキャンすると、同じ値が復活するハズです。
画面のサイズに左右される面はありますが、常識的なサイズの画面とします。
以上、宜しくお願い致します。
回答
-
Code128 のバーコードの画像を生成するには Zen.Barcode.Rendering.Framework が使えそうです。
- Visual Basic でフォームアプリケーションを作成
- フォームに TextBox と Button と PictureBox を配置
- メニューの「プロジェクト」→「Nuget パッケージの管理」を選択して、「参照」タブを開いて「Zen.barcode.rendering.framework」を検索してインストール
- 次のようなコードでバーコード画像をピクチャーボックスへ出力
Imports Zen.Barcode Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If TextBox1.TextLength > 0 Then Dim maxheight As Integer = 40 Dim barcode128 As Code128BarcodeDraw = BarcodeDrawFactory.Code128WithChecksum Dim img As Image = barcode128.Draw(TextBox1.Text, maxheight) PictureBox1.Image = img End If End Sub End Class
※ディスプレイの DPI に応じてバーコード画像の拡縮を行う必要があります。参考サイト: https://stackoverflow.com/questions/35054358/how-to-use-barcode-rendering-framework-codeplex
- 編集済み kenjinoteMVP 2017年9月26日 8:25
- 回答の候補に設定 立花楓Microsoft employee, Moderator 2017年9月27日 0:04
- 回答としてマーク custardpudding 2017年9月28日 5:36
-
手元にバーコードリーダーがないため検証が難しいのですが、出力画像を拡縮するのはどうでしょうか?
Imports Zen.Barcode Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If TextBox1.TextLength > 0 Then Dim maxheight As Integer = 40 Dim barcode128 As Code128BarcodeDraw = BarcodeDrawFactory.Code128WithChecksum Dim img As Image = barcode128.Draw(TextBox1.Text, maxheight) Dim zoom As Double = 2.0 ' 拡大率 Dim img2 As New Bitmap(CInt(img.Width * zoom), CInt(img.Height * zoom)) Dim g As Graphics = Graphics.FromImage(img2) g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor g.DrawImage(img, 0, 0, img2.Width, img2.Height) g.Dispose() PictureBox1.Image = img2 End If End Sub End Class
参考サイト: https://dobon.net/vb/dotnet/graphics/interpolationmode.html
そもそも、ディスプレイに表示されたバーコードの読み取りをバーコードリーダー側が対応しているかという問題もあるかもしれません。
- 回答としてマーク custardpudding 2017年9月28日 5:36
すべての返信
-
Code128 のバーコードの画像を生成するには Zen.Barcode.Rendering.Framework が使えそうです。
- Visual Basic でフォームアプリケーションを作成
- フォームに TextBox と Button と PictureBox を配置
- メニューの「プロジェクト」→「Nuget パッケージの管理」を選択して、「参照」タブを開いて「Zen.barcode.rendering.framework」を検索してインストール
- 次のようなコードでバーコード画像をピクチャーボックスへ出力
Imports Zen.Barcode Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If TextBox1.TextLength > 0 Then Dim maxheight As Integer = 40 Dim barcode128 As Code128BarcodeDraw = BarcodeDrawFactory.Code128WithChecksum Dim img As Image = barcode128.Draw(TextBox1.Text, maxheight) PictureBox1.Image = img End If End Sub End Class
※ディスプレイの DPI に応じてバーコード画像の拡縮を行う必要があります。参考サイト: https://stackoverflow.com/questions/35054358/how-to-use-barcode-rendering-framework-codeplex
- 編集済み kenjinoteMVP 2017年9月26日 8:25
- 回答の候補に設定 立花楓Microsoft employee, Moderator 2017年9月27日 0:04
- 回答としてマーク custardpudding 2017年9月28日 5:36
-
Code128 のバーコードの画像を生成するには Zen.Barcode.Rendering.Framework が使えそうです。
- Visual Basic でフォームアプリケーションを作成
- フォームに TextBox と Button と PictureBox を配置
- メニューの「プロジェクト」→「Nuget パッケージの管理」を選択して、「参照」タブを開いて「Zen.barcode.rendering.framework」を検索してインストール
- 次のようなコードでバーコード画像をピクチャーボックスへ出力
Imports Zen.Barcode Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If TextBox1.TextLength > 0 Then Dim maxheight As Integer = 40 Dim barcode128 As Code128BarcodeDraw = BarcodeDrawFactory.Code128WithChecksum Dim img As Image = barcode128.Draw(TextBox1.Text, maxheight) PictureBox1.Image = img End If End Sub End Class
※ディスプレイの DPI に応じてバーコード画像の拡縮を行う必要があります。参考サイト: https://stackoverflow.com/questions/35054358/how-to-use-barcode-rendering-framework-codeplex
画面(23インチ、フルHD)のバーコードを直接スキャンしても反応なしでした。
画面のスクリーンコピーを印刷してスキャンしても反応無しでした。
画面のスクリーンコピーを印刷する際に200%にして印刷してスキャンすると読み込みました。
大きくしないとダメみたいなので、Dim maxheight As Integer = 40を100に替えてみましたが、バーコードが縦長になっただけでした。
-
手元にバーコードリーダーがないため検証が難しいのですが、出力画像を拡縮するのはどうでしょうか?
Imports Zen.Barcode Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If TextBox1.TextLength > 0 Then Dim maxheight As Integer = 40 Dim barcode128 As Code128BarcodeDraw = BarcodeDrawFactory.Code128WithChecksum Dim img As Image = barcode128.Draw(TextBox1.Text, maxheight) Dim zoom As Double = 2.0 ' 拡大率 Dim img2 As New Bitmap(CInt(img.Width * zoom), CInt(img.Height * zoom)) Dim g As Graphics = Graphics.FromImage(img2) g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor g.DrawImage(img, 0, 0, img2.Width, img2.Height) g.Dispose() PictureBox1.Image = img2 End If End Sub End Class
参考サイト: https://dobon.net/vb/dotnet/graphics/interpolationmode.html
そもそも、ディスプレイに表示されたバーコードの読み取りをバーコードリーダー側が対応しているかという問題もあるかもしれません。
- 回答としてマーク custardpudding 2017年9月28日 5:36
-
Private Sub ButtonEnter_Click(sender As Object, e As EventArgs) Handles ButtonEnter.Click
If Me.TextBoxCode128.TextLength > 0 Then
Dim maxheight As Integer = 100
Dim barcode128 As Code128BarcodeDraw = BarcodeDrawFactory.Code128WithChecksum
Dim img As Image = barcode128.Draw(Me.TextBoxCode128.Text, maxheight, 2)
PictureBox1.Image = img
End If
End Sub
『.Draw』に3つめの引数を指定できそうで、それで大きさは変える事が出来ました。
多分、ラインの太さのドット数を指定するのだろうと思います。
大きさを変えれたので、プリントスクリーンを印刷すればスキャンできました。
画面直接はできません。
スキャナかモニタかの問題のようです。
一旦、これはこれで完了という事にします。
有難うございました。