Drawing scaled bitmaps on a SurfaceView — no antialiasing

前端 未结 3 522
忘了有多久
忘了有多久 2020-12-18 09:00

I\'m sorry if this topic has been brought before, but all my searches on the web and google groups did not help me.

I\'m currently developing a little game with the

相关标签:
3条回答
  • 2020-12-18 09:52

    If it comes down to it, you can manually antialias without too much trouble. Just apply a simple lowpass filter (something like an NxN average) to the pixel data before asking the bitmap object to rescale itself.

    0 讨论(0)
  • 2020-12-18 09:54

    you may clear canvas buffer by youself! such as follows:

    canvas.drawColor(Color.TRANSPARENT, android.graphics.PorterDuff.Mode.CLEAR);
    
    0 讨论(0)
  • 2020-12-18 10:00

    First when you load your bitmap you make sure that you don't lose any image quality by settings options to argb_8888:

    Options options = new Options();    
    options.inScaled = false; 
    options.inPreferredConfig = Bitmap.Config.ARGB_8888; 
    Bitmap pic = BitmapFactory.decodeResource(getResources(), R.id.pic, options);
    

    When you scale the bitmap turn on the filter:

    pic = Bitmap.createScaledBitmap(pic, screenW, screenH, true);
    

    However if one streaches the image too much inevitably it degrades in quality.

    When you use paint you can improve quality but lose on speed with turning on ditherig and filtering:

    Paint paint = new Paint(); 
    paint.setFlags(Paint.DITHER_FLAG);
    paint.setFilterBitmap(true);
    

    Finally the entire activity window could be set on argb_4444 instead on argb_8888 (OS < 2.3). You can chage this if you instert this line before setContentView:

    getWindow().setFormat(PixelFormat.RGBA_8888); 
    
    0 讨论(0)
提交回复
热议问题