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
}
}
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
COnsume rest client | 6 | 36 | |
Definitions and default visual studio colors | 5 | 58 | |
How to get the web content with different encodings | 2 | 29 | |
Data is not showing from images | 15 | 38 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
24 Experts available now in Live!