myGraphics.SmoothingMode = SmoothingMode.AntiAlias;
and draw the rectangle with lines, instead of placing a dot for each different pixel
myGraphics.DrawLine(myPen,
this should improve drawing quality
e.SmoothingMode = SmoothingMode.HighQuality;
float Cx = this.posx;
float Cy = this.posy;
float Fx = this.finalx;
float Fy = this.finaly;
float Vx = Cx;
float Inc;
Inc=1;
float a = (Cy - Fy) / (Cx - Fx);
float b = (Cx * Fy - Fx * Cy) / (Cx - Fx);
if (Cx > Fx) Inc = -1;
while(Vx != Fx)
{
///////by Interpolation y=ax+b
///////where a=(y1-y2)/(x1-x2)
//////b =(x1*y2-x2*y1)/(x1-x2)
Vy = a * Vx + b;
e.DrawRectangle(Pens.Red, Vx, Vy, 4, 4);
Vx = Vx + Inc;
}
ALGO 1
lineplot(x1,y1,x2,y2)
{
for x=x1 to x2
{
y = f(x)
setPixel(x,y)
}
}
ALGO 2
lineplot(x1,y1,x2,y2)
{
// verify which is bigger: |x2-x1| or |y2-y1|
if |x2-x1| > |y2-y1|
then loop x values from x1 to x2
else loop y values from y1 to y2
}
PSEUDOCODE 1
lineplot(x1,y1,x2,y2)
{
if abs(x2-x1) > abs(y2-y1)
then // loop by varying x values
{
dx = abs(x2-x1) / (x2-x1) // will be +1 or -1
// calculate line equation
m = (y2-y1) / (x2-x1) // if x2=x1 then the line is vertical
c = y1 - m*x1
for x=x1 to x2 step dx
{
y = m*x + c
setPixel(x,y)
}
}
else
{
// do the equivalent by varying y values
}
}
Title | # Comments | Views | Activity |
---|---|---|---|
How to programitically read in the first 4 bytes of a txt file (that is attached) in C# and return its decimal value of '80' ? | 1 | 55 | |
Exception in Log4Net | 1 | 20 | |
bulid json format | 3 | 21 | |
Access properties in nested observable collections | 8 | 10 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
13 Experts available now in Live!