如何转换VB的所有项目文件 [英] How converting all project file for VB
本文介绍了如何转换VB的所有项目文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Drawing;
using System.Windows.Forms;
using Dynamsoft.Barcode;
using TouchlessLib;
using System.Diagnostics;
namespace BarcodeReaderApp
{
public partial class Form1 : Form
{
private BarcodeReader _barcodeReader;
private TouchlessMgr _touch;
private const int _previewWidth = 640;
private const int _previewHeight = 480;
public Form1()
{
InitializeComponent();
// Initialize Dynamsoft Barcode Reader
_barcodeReader = new BarcodeReader();
// Initialize Touchless
_touch = new TouchlessMgr();
}
private void button1_Click(object sender, EventArgs e)
{
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = "Open Image";
//dlg.Filter = "bmp files (*.bmp)|*.bmp";
if (dlg.ShowDialog() == DialogResult.OK)
{
Bitmap bitmap = null;
try
{
bitmap = new Bitmap(dlg.FileName);
}
catch (Exception exception)
{
MessageBox.Show("File not supported.");
return;
}
pictureBox1.Image = new Bitmap(dlg.FileName);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
if (pictureBox1.Image == null)
{
MessageBox.Show("Please load an image!");
return;
}
ReadBarcode((Bitmap)pictureBox1.Image);
}
private void button3_Click(object sender, EventArgs e)
{
string button_text = button3.Text;
if (button_text.Equals("Start Webcam"))
{
button3.Text = "Stop Webcam";
StartCamera();
}
else
{
button3.Text = "Start Webcam";
StopCamera();
}
}
private void StartCamera()
{
if (_touch.Cameras.Count == 0)
{
MessageBox.Show("No USB webcam connected");
button3.Text = "Start Webcam";
return;
}
// Start to acquire images
_touch.CurrentCamera = _touch.Cameras[0];
_touch.CurrentCamera.CaptureWidth = _previewWidth; // Set width
_touch.CurrentCamera.CaptureWidth = _previewHeight; // Set height
_touch.CurrentCamera.OnImageCaptured += new EventHandler<cameraeventargs>(OnImageCaptured); // Set preview callback function
}
private void StopCamera()
{
button3.Text = "Start Webcam";
if (_touch.CurrentCamera != null)
{
_touch.CurrentCamera.OnImageCaptured -= new EventHandler<cameraeventargs>(OnImageCaptured);
}
}
private void OnImageCaptured(object sender, CameraEventArgs args)
{
// Get the bitmap
Bitmap bitmap = args.Image;
// Read barcode and show results in UI thread
this.Invoke((MethodInvoker)delegate
{
pictureBox1.Image = bitmap;
ReadBarcode(bitmap);
});
}
private void ReadBarcode(Bitmap bitmap)
{
// Read barcodes with Dynamsoft Barcode Reader
Stopwatch sw = Stopwatch.StartNew();
sw.Start();
BarcodeResult[] results = _barcodeReader.DecodeBitmap(bitmap);
sw.Stop();
Console.WriteLine(sw.Elapsed.TotalMilliseconds + "ms");
// Clear previous results
textBox1.Clear();
if (results == null)
{
textBox1.Text = "No barcode detected!";
return;
}
// Display barcode results
foreach (BarcodeResult result in results)
{
textBox1.AppendText(result.BarcodeText + "\n");
textBox1.AppendText("\n");
}
}
}
}
我尝试了什么:
What I have tried:
Public Class Form2
Inherits Form
Private _barcodeReader As BarcodeReader
Private _touch As TouchlessMgr
Private Const _previewWidth As Integer = 640
Private Const _previewHeight As Integer = 480
Public Sub New()
InitializeComponent()
' Initialize Dynamsoft Barcode Reader
_barcodeReader = New BarcodeReader()
' Initialize Touchless
_touch = New TouchlessMgr()
End Sub
Private Sub AboutThisApplicationToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutThisApplicationToolStripMenuItem.Click
AboutBox2.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myFileDlog As New OpenFileDialog()
myFileDlog.InitialDirectory = "c:\"
myFileDlog.Filter = "All Files (*.*)|*.*" &
"|Image Files (*.jpg)|*.jpg" &
"|Image Files (*.bmp)|*.bmp" &
"|Image Files (*.png)|*.png"
myFileDlog.FilterIndex = 1
myFileDlog.RestoreDirectory = True
If myFileDlog.ShowDialog() = DialogResult.OK Then
PictureBox87.Image = Image.FromFile(myFileDlog.FileName)
End If
TextBox1.Text = myFileDlog.FileName
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If PictureBox87.Image Is Nothing Then
MessageBox.Show("Please load an image!")
Return
End If
ReadBarcode(DirectCast(PictureBox87.Image, Bitmap))
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim button_text As String = Button2.Text
If button_text.Equals("Start Webcam") Then
Button2.Text = "Stop Webcam"
StartCamera()
Else
Button2.Text = "Start Webcam"
StopCamera()
End If
End Sub
Private Sub StartCamera()
'Form2._touch As touchlessmgr.crrentCamera As Camera
'Event camera().OnImageCaptured As eventhandler(of cameraeventargs)
If _touch.Cameras.Count = 0 Then
MessageBox.Show("No USB webcam connected")
Button2.Text = "Start Webcam"
Return
End If
' Start to acquire images
_touch.CurrentCamera = _touch.Cameras(0)
_touch.CurrentCamera.CaptureWidth = _previewWidth
' Set width
_touch.CurrentCamera.CaptureWidth = _previewHeight
' Set height
_touch.CurrentCamera.OnImageCaptured += New EventHandler(Of CameraEventArgs)(AddressOf OnImageCaptured)
' Set preview callback function
End Sub
Private Sub StopCamera()
Button2.Text = "Start Webcam"
If _touch.CurrentCamera IsNot Nothing Then
'_touch.CurrentCamera.OnImageCaptured -= New EventHandler(Of CameraEventArgs)(AddressOf OnImageCaptured)
End If
End Sub
Private Sub OnImageCaptured(sender As Object, args As CameraEventArgs)
' Get the bitmap
Dim bitmap As Bitmap = args.Image
' Read barcode and show results in UI thread
Me.Invoke(DirectCast(Sub()
PictureBox87.Image = bitmap
ReadBarcode(bitmap)
End Sub, MethodInvoker))
End Sub
Private Sub ReadBarcode(bitmap As Bitmap)
' Read barcodes with Dynamsoft Barcode Reader
Dim sw As Stopwatch = Stopwatch.StartNew()
sw.Start()
Dim results As BarcodeResult() = _barcodeReader.DecodeBitmap(bitmap)
sw.[Stop]()
Console.WriteLine(sw.Elapsed.TotalMilliseconds + "ms")
' Clear previous results
RichTextBox1.Clear()
If results Is Nothing Then
RichTextBox1.Text = "No barcode detected!"
Return
End If
' Display barcode results
For Each result As BarcodeResult In results
RichTextBox1.AppendText(result.BarcodeText + vbLf)
RichTextBox1.AppendText(vbLf)
Next
End Sub
End Class
打印屏幕:
[ IMAGE Screen Project ]
推荐答案
已经有一段时间了,但是我的头,在VB中,你需要做类似的事情:
It has been a while, but off the top of my head, in VB, you need to do something like:
AddHandler _touch.CurrentCamera.OnImageCaptured, AddressOf OnImageCaptured()
这篇关于如何转换VB的所有项目文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文