Plesleron
我不確定您粘貼的代碼是否包含所需的所有內容。
這是一個需要您可以在Visual Basic中使用位圖的代碼示例。
首先,你需要添加「導入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
如錯誤消息所示,「Bitmap」沒有名爲GetPixel的成員。你想要'terrain.GetPixel(250,250)'做什麼? – Blackwood
既然你說你還沒有用VB.net編碼,你應該知道一些事情。 獲取像素和設置像素功能非常慢。我知道他們使用起來更容易,但最終你肯定會頭痛。 更快的方法是使用lockbits並自己遍歷集合。 有人在這個網站上做了一個漂亮的小項目,並稱之爲FastPixel類。搜索一下,你會發現一個很好的演示關於這個主題的好消息,關於它是如何工作的。 我知道這並不回答你的問題,但你可能會喜歡的信息。 – ThatGuy