Graphics
Smoothing
We can improve our images by smoothing. This reduces the ugly
"pixelated" quality of the images.
1. [ VB ] Smoothing
The first line is drawn without smoothing, the second is smoothed.
We set the smoothing on - after this all the drawing operations are
slower, but better.
test text
1. [ C++ ] Smoothing
The first line is drawn without smoothing, the second is smoothed.
We set the smoothing on - after this all the drawing operations are
slower, but better.
Anti aliasing is on by default. However we can turn it off.
test text
1. [ Java ] Smoothing
static void drawFlag(Graphics2D g)
{
g.setColor(Color.white);
g.fillRect(0,0,200,180);
g.setColor(Color.black);
//The first line is not smoothed
g.drawLine(20,20,30,160);
//The second line is smoother
g.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.drawLine(40,20,50,160);
}
Big
Show all
The first line is drawn without smoothing, the second is smoothed.
We set the smoothing on - after this all the drawing operations are
slower, but better.
See Graphics2D RenderingHints for the bewildering variety
of options available.
g.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
test text
1. [ C# ] Smoothing
static void drawFlag(Graphics g)
{
g.FillRectangle(Brushes.White,0,0,70,180);
//The first line is not smoothed
g.DrawLine(Pens.Black,20,20,30,160);
//The second line is smoother
g.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawLine(Pens.Black,40,20,50,160);
}
Big
Show all
The first line is drawn without smoothing, the second is smoothed.
We set the smoothing on - after this all the drawing operations are
slower, but better.
See Graphics.SmoothingMode from the MSDN library.
The other options are AntiAlias Default HighQuality HighSpeed Invalid None
g.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
test text
1. [ Perl ] Smoothing
sub drawFlag{
my ($g) = @_;
my $bg = $g->colorAllocate(255,255,255);
$g->filledRectangle(0,0,70,180,$bg);
my $black = $g->colorAllocate(0,0,0);
$g->line(20,20,30,160,$black);
$g->setAntiAliased($black);
$g->line(40,20,50,160,gdAntiAliased);
}
Big
Show all
The first line is drawn without smoothing, the second is smoothed.
We set the smoothing on - after this all the drawing operations are
slower, but better.
There must be be enough colours allocated for this to work (we use
"true colour" here. One colour is specified as the anti alias and the
special colour gdAntiAliased may be used.
test text