I’m trying to draw text without antialiasing on a canvas in Android. The font I want to use is a file cour.ttf, which I’ve copied from my PC’s C:\windows\fonts directory to my app’s assets directory.
I’m using this code:
paint.setColor(Color.BLACK);
paint.setTypeface(Typeface.createFromAsset(getAssets(),"cour.ttf"));
paint.setTextSize(20);
paint.setAntiAlias(false);
canvas.drawText("ABCDE abcde 12345 -+/#.",100,100,paint);
The setAntiAlias function doesn’t appear to have any effect though.
This picture shows my results:
http://oi47.tinypic.com/35253wo.png
The first line is a screenshot from the app, with antialiasing set to false.
The second line is a screenshot from the app with antialiasing set to true.
The third line is what I would expect to get, it’s a screenshot made from my PC in notepad.exe with the same font.
Am I doing something wrong or is this the expected output with antialiasing off? What I’m trying to achieve here is to have pixelated unblurred text.
Any help is much appreciated.
EDIT:
I haven’t quite found the solution yet, but I did find something interesting:
adding android:hardwareAccelerated="false" to my Activity cleared it up quite a bit. Apperently this is turned on by default on Android 4. There’s still a (very light) shadow visible that I’d like to remove though.
Screenshot with hardware acceleration disabled:
http://oi49.tinypic.com/aayypj.png
The pixels densities on PC and phone seem to be different, that is why the difference in appearance of text. You can’t compare the phone rendered text with the one rendered on your PC. I think the pixel density on your phone is high, so you not able to see the effect of anti-aliasing.