Last post Mar 18, 2008 11:37 AM by ponedog99
Mar 10, 2008 03:55 PM|DezTech|LINK
Imagine you were creating an online photo album and could choose from a variety of layouts for each page. I have a collection of hundreds of EPS files that define the various layout formats for placing the photos. An example of one of the layouts is below
as a GIF image. What I would like to be able to do is open a source image file (either EPS, GIF, or PNG) and create a GDI+ Region object based on the white areas of my source image. I could make the white or gray areas transparent portions of a GIF/PNG file
if that makes life easier. I could then manipulate the final output based on operations performed on the auto-determined regions...
Please let me know how to accomplish this, thanks....
Example Layout Format Input Image (again, I'd like to somehow create a Region based on the white areas).
Mar 12, 2008 05:07 PM|DezTech|LINK
Still no luck finding a solution while searching the Net, but I imagine I could do a brute-force pixel-by-pixel survey of my input image. On an average 1000x1000 pixel image this would mean checking 1,000,000 pixels, but maybe that's the only way. So unless
someone has a better solution, I'd write a double loop to go through the pixels of the image and test each pixel for my target color (white). If the pixel matches I'd do a GraphicsPath.AddRectangle for that pixel and then create my Region object based on
the final GraphicsPath.
But again, if there's any better ideas out there, PLEASE let me know, thanks...
Mar 18, 2008 11:37 AM|ponedog99|LINK
Private Function BitmapToRegion(ByVal bitmap As Bitmap, ByVal transparencyColor As Color) As Region
If bitmap Is Nothing Then
Throw New ArgumentNullException("Bitmap", "Bitmap cannot be Nothing!")
Dim height As Integer = bitmap.Height
Dim width As Integer = bitmap.Width
Dim path As New Drawing2D.GraphicsPath
Dim i As Integer
Dim j As Integer
For j = 0 To (height - 1)
For i = 0 To (width - 1)
If Not bitmap.GetPixel(i, j).Equals(transparencyColor) Then
Dim x0 As Integer = i
Do While ((i < width) AndAlso (Not bitmap.GetPixel(i, j).Equals(transparencyColor)))
i += 1
path.AddRectangle(New Rectangle(x0, j, i - x0, 1))
Dim region As New Region(path)