Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net NET抓取图像的一部分并在另一个图片框中放大_Vb.net_Picturebox - Fatal编程技术网

Vb.net NET抓取图像的一部分并在另一个图片框中放大

Vb.net NET抓取图像的一部分并在另一个图片框中放大,vb.net,picturebox,Vb.net,Picturebox,在vb.net中,当我单击picturebox中的图像时,我正在调整鼠标位置,并用picturebox 1中图像的放大部分填充第二个picturebox 代码似乎正在运行。。。有点它在picturebox 1中捕获图像的一部分。。。但不是我点击的部分 Private Function magnify(ByVal position As Point) vert2.Clear() horz2.Clear() Dim img As New Bitmap(preciseBox

在vb.net中,当我单击picturebox中的图像时,我正在调整鼠标位置,并用picturebox 1中图像的放大部分填充第二个picturebox

代码似乎正在运行。。。有点它在picturebox 1中捕获图像的一部分。。。但不是我点击的部分

 Private Function magnify(ByVal position As Point)
    vert2.Clear()
    horz2.Clear()

    Dim img As New Bitmap(preciseBox.Width, preciseBox.Height)
    Dim gr As Graphics = Graphics.FromImage(img)
    Dim src As New Rectangle(position.X - 50, position.Y - 50, 100, 100)
    Dim dest As New Rectangle(0, 0, img.Width, img.Height)

    Try
        gr.DrawImage(xrayBox.Image, dest, src, GraphicsUnit.Pixel)
        img = New Bitmap(img, img.Width, img.Height)
        preciseBox.Image = img

        'Draws the crosshair on the magnify box
        vert2.Add(New Point(img.Width / 2, 0))
        vert2.Add(New Point(img.Width / 2, img.Height))
        horz2.Add(New Point(0, img.Height / 2))
        horz2.Add(New Point(img.Width, img.Height / 2))

        draw2 = True
        preciseBox.Invalidate()
    Catch ex As Exception

    End Try
    Return 0
End Function
Picturebox1大小(运行时):宽度646px高度687px Picturebox1.图像大小(运行时):宽度646px高度484px
Picturebox2大小(运行时):宽度370px高度230px

您忘记注意PictureBox.SizeMode了。这需要更多的代码将位置映射到图像中的像素。@HansPassant Picturebox 1和2都处于正常大小模式。在将图像放入picturebox之前,我会重新调整其大小,使其适合、填充空间(水平或垂直)并保持其比例。在这种情况下,我认为我不需要重新映射,因为Picturebox中的像素应该与图像中像素的位置相匹配。当我通过调试器时,我正在添加所有内容的大小。空的Catch块正在吞噬所有可能的错误。删除它就行了。除了使调试变得困难之外,它没有任何作用。我很感激关于catch块的建议。事实上,我只是还没有给它添加逻辑。这里的问题是,我似乎没有抛出错误。我实际上得到的是一个区域,而不是我点击的区域。