I'm using this class to fill pixels of a bitmap based on the LockBits function:
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
Now, instead of filling all the pixels, I need to fill an ellipse (actually it's going to be many ellipses, that's why I use LockBits), so I googled for a way to draw an ellipse pixel by pixel using some kind of formula, but I didn't find much help, also I'm not good with this math stuff. So, my question is: how to create an array of pixels that forms a filled ellipse? thank you
.
supplement (feel free to ignore):
I'll explain exactly what I'm trying to do, so it might help you understand my situation.. Actually, I'm working on a function that's supposed to generate filled ellipses with random width & height (in specific range) on a specific area of a bitmap, while the filled pixels must have a percentage of the total number of pixels in that area, that's why I need to draw the ellipse pixel by pixel (or using an array of pixels) to keep track of the number of filled pixels.