问题描述
如何将一张图片打开到图片框1,并在sql服务器中找到它(比较2张图片),然后将图片显示到图片框2.
How to open one image to picturebox 1 and find it in sql sever( compare 2 image) and show image same to picturebox2.
推荐答案
Option Strict On
Imports System.Drawing.Imaging
Public Class Form7
Private sw As New Stopwatch
Private Sub Form7_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.BackgroundImage = Image.FromFile("c:\bitmaps\rusty.jpg")
PictureBox1.BackgroundImageLayout = ImageLayout.Zoom
'此图片匹配 PictureBox2.BackgroundImage = Image.FromFile("c:\ bitmaps \ rusty.jpg")
'this image matches PictureBox2.BackgroundImage = Image.FromFile("c:\bitmaps\rusty.jpg")
'此图像不匹配 'PictureBox2.BackgroundImage = Image.FromFile("c:\ bitmaps \ rusty1.bmp")
'this image does not match 'PictureBox2.BackgroundImage = Image.FromFile("c:\bitmaps\rusty1.bmp")
PictureBox2.BackgroundImageLayout = ImageLayout.Zoom Label1.AutoSize = False Label1.Text =" 结束子 私有子Button1_Click(作为对象发送,作为EventArgs发送)处理Button1.Click 昏暗SameImage作为布尔=真 昏暗的x,y为整数 sw.Reset() sw.Start() 使用bmp1作为位图= CType(PictureBox1.BackgroundImage,位图), bmp2作为位图= CType(PictureBox2.BackgroundImage,位图) '看看它们大小是否相同 如果bmp2.Width = bmp1.Width AndAlso bmp2.Height = bmp1.Height然后
PictureBox2.BackgroundImageLayout = ImageLayout.Zoom Label1.AutoSize = False Label1.Text = "" End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim SameImage As Boolean = True Dim x, y As Integer sw.Reset() sw.Start() Using bmp1 As Bitmap = CType(PictureBox1.BackgroundImage, Bitmap), bmp2 As Bitmap = CType(PictureBox2.BackgroundImage, Bitmap) 'see if they are the same size If bmp2.Width = bmp1.Width AndAlso bmp2.Height = bmp1.Height Then
'查看颜色是否匹配-调整精度步骤 变暗为整数= CInt(bmp1.Width/10) 对于x = 0到bmp1.Width 对于y = 0到bmp1.Height 如果bmp1.GetPixel(x,y)<> bmp2.GetPixel(x,y)然后 SameImage =假 退出 万一 下一个 下一个 别的 SameImage =假 万一 最终使用 sw.Stop() 如果SameImage然后 Label1.Text =图像匹配:x =" & x.ToString& " y ="& y.ToString& vbLf& "时间:" & sw.ElapsedTicks.ToString 别的 Label1.Text =图像不匹配:x =" & x.ToString& " y ="& y.ToString& vbLf& "时间:" & sw.ElapsedTicks.ToString 万一 Label1.Refresh() 结束子结束班级
'see if the colors match - adjust step for accuracy Dim thestep As Integer = CInt(bmp1.Width / 10) For x = 0 To bmp1.Width Step thestep For y = 0 To bmp1.Height Step thestep If bmp1.GetPixel(x, y) <> bmp2.GetPixel(x, y) Then SameImage = False Exit For End If Next Next Else SameImage = False End If End Using sw.Stop() If SameImage Then Label1.Text = "Images Match: x = " & x.ToString & " y = " & y.ToString & vbLf & "Time: " & sw.ElapsedTicks.ToString Else Label1.Text = "Images Do Not Match: x = " & x.ToString & " y = " & y.ToString & vbLf & "Time: " & sw.ElapsedTicks.ToString End If Label1.Refresh() End SubEnd Class
这篇关于在Windowsform中使用vb.net搜索一张图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!