Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.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 如何在Visual Basic中使用GetPixel for Bitmap()_Vb.net_Bitmap - Fatal编程技术网

Vb.net 如何在Visual Basic中使用GetPixel for Bitmap()

Vb.net 如何在Visual Basic中使用GetPixel for Bitmap(),vb.net,bitmap,Vb.net,Bitmap,这是我的代码,我得到一个错误,说GetPixel不是Bitmap()的成员。。我不确定我做错了什么。请原谅我做错了什么,我以前从未用VB编写过代码。Plessleron 我不确定你粘贴的代码是否具备所需的一切 下面是一个代码示例,您可以在Visual Basic中使用位图 首先,您需要添加“Imports System.Drawing” 下面是一个使用位图所需的代码示例 Public Class Form1 Private Sub Form1_Load(sender As Object,

这是我的代码,我得到一个错误,说
GetPixel不是Bitmap()的成员。
。我不确定我做错了什么。请原谅我做错了什么,我以前从未用VB编写过代码。

Plessleron

我不确定你粘贴的代码是否具备所需的一切

下面是一个代码示例,您可以在Visual Basic中使用位图

首先,您需要添加“Imports System.Drawing”

下面是一个使用位图所需的代码示例

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim terrain As Bitmap(500, 500)
        terrain = New Bitmap(500, 500)
        terrain.GetPixel(250, 250)
    End Sub
End Class

正如错误消息所说,
Bitmap
没有名为
GetPixel
的成员。你想让terrain.GetPixel(250250)做什么?既然你说你没有用VB.net编码,你应该知道一些事情。“获取像素”和“设置像素”功能的速度非常慢。我知道它们更容易使用,但最终你肯定会头疼。一种更快的方法是使用锁位并自己迭代集合。有人在这个网站上做了一个很好的小项目,称这个类为FastPixel。搜索它,你会发现一个关于这个主题的很好的演示,其中有一些关于它是如何工作的信息。我知道这不能回答你的问题,但我想你可能会喜欢这些信息。
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text.RegularExpressions
Imports System.Drawing

Namespace Rextester
    Public Module Program
        Public Sub Main(args() As string)
            'Your code goes here
            Console.WriteLine("Hello, world!")

            Try
        ' Retrieve the image.
        Dim image1 = New Bitmap( _
            "C:\temp\Grapes.jpg", _
            True)

        Dim x, y As Integer

        ' Loop through the images pixels to reset color.
        For x = 0 To image1.Width - 1
            For y = 0 To image1.Height - 1
                Dim pixelColor As Color = image1.GetPixel(x, y)
                Dim newColor As Color = _
                    Color.FromArgb(pixelColor.R, 0, 0)
                image1.SetPixel(x, y, newColor)
            Next
        Next

        ' Set the PictureBox to display the image.
        Console.WriteLine(image1)

        ' Display the pixel format in Label1.
        Console.Writeline("Pixel format: " + image1.PixelFormat.ToString())

    Catch ex As ArgumentException
        Console.Writeline("There was an error." _
            & "Check the path to the image file.")
    End Try
        End Sub
    End Module
End Namespace