1

This is a test project for antialias in Surface View and View,

in the View : ( it's very good for antialias )

@Override
protected void onDraw(Canvas canvas) {
    Paint p = new Paint();
    p.setColor(Color.WHITE);
    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG));  
    canvas.drawColor(Color.BLACK);
    Matrix mMatrix = new Matrix();
    mMatrix.postScale(0.34f, 0.34f);
    canvas.drawBitmap(mBitmap, mMatrix, p);
    canvas.drawText("View Anti alias", 100, 300, p);
}

in the Surface View : ( ugly -_-!!)

public void doDraw(Canvas canvas) {
    Paint p = new Paint();
    p.setColor(Color.WHITE);
    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
    canvas.drawColor(Color.BLACK);
    Matrix mMatrix = new Matrix();
    mMatrix.postScale(0.34f, 0.34f);
    canvas.drawBitmap(mBitmap, mMatrix, p);
    canvas.drawText("Surface View Anti alias", 100, 300, p);
}

u can download the source from here: http://sharpidea.co.cc/GifViewTest.rar

any one can tell me how to anti alias in surfaceView ?

sharpidea
  • 11
  • 1
  • 4
  • Having similar problems when using drawPath() on the surfaceHolder.lockCanvas() canvas. Tried all kinds of Paint combinations and setDrawFilter() on the canvas. Appreciate an update on this if you found the solution. – kctang Oct 06 '11 at 15:12

1 Answers1

0

You need to use p.setFilterBitmap(true) to do what you want.

Xaver Kapeller
  • 49,491
  • 11
  • 98
  • 86
Romain Guy
  • 97,993
  • 18
  • 219
  • 200