Arrays 如何在LockBits数组中使用drawerlipse(如何生成一组形成椭圆的像素)

Arrays 如何在LockBits数组中使用drawerlipse(如何生成一组形成椭圆的像素),arrays,vb.net,bitmap,ellipse,lockbits,Arrays,Vb.net,Bitmap,Ellipse,Lockbits,我使用这个类基于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

我使用这个类基于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
现在,我不需要填充所有的像素,而是需要填充一个椭圆(实际上,它将是许多椭圆,这就是我使用锁位的原因),所以我在谷歌上搜索一种方法,用某种公式逐像素绘制一个椭圆,但我没有找到太多帮助,而且我也不擅长这方面的数学知识。 所以,我的问题是:如何创建一个像素阵列,形成一个填充椭圆?多谢各位

. 补充资料(请随意忽略): 我会详细解释我想做什么,这样可能会帮助你了解我的处境。。
实际上,我正在开发一个函数,该函数应该在位图的特定区域上生成具有随机宽度和高度(在特定范围内)的填充椭圆,而填充像素必须占该区域像素总数的百分比,这就是为什么我需要逐像素绘制椭圆(或使用像素阵列)跟踪填充像素的数量。

椭圆内所有点的公式为:


(x-h)*(x-h)/a*a+(y-k)*(y-k)/b*b图形类非常擅长快速生成椭圆。不要使用锁位,使用Graphics.FromImage()。@HansPassant问题是我需要跟踪函数填充的像素数很难想象这样做的意义。以后你可以数一数。
Dim h, k, a, b, x, y As Integer
Dim res As Double

'arbitrary values of ellipse
h = 200
k = 200
a = 80
b = 60

For x = h - a To h + a
    For y = k - b To k + b
        res = CDbl((x - h) * (x - h)) / CDbl(a * a) + CDbl((y - k) * (y - k)) / CDbl(b * b)

        If res <= 1.0 Then
            'the point (x, y) is inside
        End If

    Next
Next