I'm working to my project GraPPC, a graphic program.
For the method FloodFill (fill an area with a color) i need to set the color for a single pixel but with the Line method i have some problems. For example, for this method i must to control the color of the adjacent pixels for any pixel and if i use the Line method i cover this pixels!
This is my work in progress :
__________________
HP HW6915 240x240 - Windows Mobile 5.0
I tryed to use the SetPixel method from the ImageLib library but i have the same problem : two pixel for each point! Why?
This is my code (bmp is a BitMap object):
Code:
Sub App_Start Form1.Show bmp.New2(Form1.Width,Form1.Height)
End Sub
Sub Form1_MouseDown (x,y) bmp.SetPixel(x,y,cRed) Form1.Image = bmp.Value
End Sub
__________________
HP HW6915 240x240 - Windows Mobile 5.0
Using your code of SetPixel on a bitmap from ImageLib I too get two pixels. But they are not actually two solid pixels. Looking at them using the Magnifier tool I can see that they are combinations of two or more shaded (not solid colour) pixels. I don't fully understand what is happening here but the reason for this seems to be that although the bitmap is nominally the same size of the form in fact it is not! You can see this by clicking on the right side of the form and noticing that the pixel(s) do not appear under the mouse pointer. The pixels are being stretched in mapping the bitmap onto the form.
You can in fact get a single pixel by adding the BF parameter to Line
Form1.Line(x,y,x+1,y+1,color,BF)
I don't remember having to add this before but maybe my memory is at fault!
EDIT :- Something HAS changed. My FormEx library uses something similar to provide a SetPixel function and it is now broken and produces two pixels? I wonder what has changed?
Klaus, if i use your Pen function in my FloodFill function i receive an error : Windows close the B4PPC with a standard message!!!
And it happen the same thing with the Line method suggested by agraham!!!
For me, the problem is in the memory management of B4PPC. The recoursive method that i use for FloodFill function use a lot of memory. In Visual Basic 6 for Windows i obtain the same result if i use a large area to fill; if i use a small area all works fine.
A question : it's possible to increase the memory used by B4PPC? Or it uses yet the maximum of available RAM memory?
Note : with my code almost all works fine : with a SetPixel function for the Form i'm sure of solve my problem.
__________________
HP HW6915 240x240 - Windows Mobile 5.0
The recoursive method that i use for FloodFill function use a lot of memory.
The problem is not a lack of memory per se but you are running out of stack space on the device. I think that your only solution is to write a non-recursive routine.
I tested the different possibilities of the line function.
It seems having a somewhat strange behaviour:
Line(x,y,x+1,y+1,color) gives a line of two pixels
Line(x,y,x+1,y+1,color,B) gives a square of four pixels
Line(x,y,x+1,y+1,color,BF) gives a single pixel ?
Attached some examples.
I have found some interesting articles about filling polygons with non recursive methods.
I have not yet looked in details, neither tested these methods, but hope they could be helpfull.
I am also looking for a fill method for my IconEdit program.
It seems having a somewhat strange behaviour:
Line(x,y,x+1,y+1,color) gives a line of two pixels
Line(x,y,x+1,y+1,color,B) gives a square of four pixels
Line(x,y,x+1,y+1,color,BF) gives a single pixel ?
It's not so strange if you know what the underlying .NET functions do.
Line(x1,y1,x2,y2,color) Draws a line from x1,y1 to x2,y2. This is the one whose behaviour seems to have changed for me but it is a .NET change not a B4PPC change as it happens in my FormExDesktop libarary which calls .NET directly. Previously it seemed to draw a line from x1,y1 to x2-1,y2-1 which gave a single pixel. Now it behaves as it is documented "Draws a line connecting two Point structures".
Line(x1,y1,x2,y2,color,B) Draws the single pixel border of a rectangle defined by x1,y1, and x2,y2. So four pixels in the minimum case.
Line(x1,y1,x2,y2,color,BF Fills the INTERIOR of a rectangle defined by x1,y1, and x2,y2. So theoretically 0 pixels in the minimum case but it seems to default to 1 pizel located at x1,y1. Actually it always starts the fill at x1,y1 rather than x1+1,y1+1 so you could argue that it is buggy although it IS documented to behave this way.