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
这是我的代码,我收到错误GetPixel is not a member of Bitmap()
。我不确定我做错了什么。请错过我在这里做错的事情,我以前从未在VB中编码。
答案 0 :(得分:0)
Plesleron
如果您拥有所需的一切,我不确定您粘贴的代码。
以下是您可以在Visual Basic中使用Bitmap所需的代码示例。
首先,您需要添加" Imports System.Drawing"
以下是使用位图所需的代码示例。
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