我正在使用这个类来填充基于 LockBits 函数的位图像素:
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices.Marshal
Public Class Fill
Public Shared Function Process(ByVal b As Bitmap) As Bitmap
Dim bmd As BitmapData = _
b.LockBits(New Rectangle(0, 0, b.Width, b.Height), _
System.Drawing.Imaging.ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb)
Dim scan0 As IntPtr = bmd.Scan0
Dim stride As Integer = bmd.Stride
' Here's the speedier method.
' define an array to store each pixels color as an int32
Dim pixels(b.Width * b.Height - 1) As Integer
' this is system.runtime.interopservices.marshall.copy
Copy(scan0, pixels, 0, pixels.Length)
' loop through all pixels and fill
For i As Integer = 0 To pixels.Length - 1
pixels(i) = Color.Red.ToArgb
Next
' Copy the data back from the array to the locked memory
Copy(pixels, 0, scan0, pixels.Length)
' finally we unlock the bits.
b.UnlockBits(bmd)
Return b
End Function
End Class
现在,我需要填充一个椭圆,而不是填充所有像素(实际上它会是很多椭圆,这就是我使用 LockBits 的原因),所以我在谷歌上搜索了一种使用某种公式逐像素绘制椭圆的方法,但我没有找到太多帮助,而且我对这些数学东西也不擅长。所以,我的问题是:如何创建一个形成填充椭圆的像素数组?谢谢你
.
补充(随意忽略):
我会准确地解释我想要做什么,所以它可能会帮助你理解我的情况。实际上,我正在研究一个函数,该函数应该在 a 上生成具有随机宽度和高度(在特定范围内)的填充椭圆位图的特定区域,而填充的像素必须占该区域像素总数的百分比,这就是为什么我需要逐个像素(或使用像素数组)绘制椭圆以跟踪数量填充像素。