문제

It is possible to render a view at a low resolution, and then scale it up to fit the actual size of your view using the setFixedSize() method of a SurfaceHolder. However, the scaling is done with some kind of interpolation, causing everything to blur.
Is there any method for changing the method of interpolation to nearest neighbour or just turning it off?

Here is an example of what I mean, Made with a 4x4 surface in a fullscreen-view:
What I want What I get
Left image: This is how I want the result to look (here achieved by drawing a nonfiltered bitmap)
Right image: This is what happens when the 4x4 canvas is scaled to fullscreen.

Sample code for generating the right image if anyone's interested:

public class ScaleView extends SurfaceView implements SurfaceHolder.Callback {
    private final static float[] points = {0,0, 2,0, 4,0, 1,1, 3,1, 0,2, 2,2, 4,2, 1,3, 3,3};
    private Paint white;
    public ScaleView(Context context) {
        super(context);
        white = new Paint();
        white.setColor(0xFFFFFFFF);
        getHolder().addCallback(this);
    }
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height){
        Canvas c = holder.lockCanvas();
        try{
            c.drawPoints(points, white);
        }finally{
            holder.unlockCanvasAndPost(c);
        }
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder){
        holder.setFixedSize(4, 4);
    }
    @Override
    public void surfaceDestroyed(SurfaceHolder holder){}
}

Note: The square pattern above is just an example of the effect I want to avoid. I am looking for a general solution that can be applied to any view (with a surfaceholder) with any content.

도움이 되었습니까?

해결책

Sorry, you can't control this. It is not defined what kind of scaling will be done on these surfaces -- it depends on the hardware and how it is configured. Also, this kind of extreme scaling really should be avoided, since in some cases hardware can't do it so you will end up in slower paths. (For example if surfaces are being put into overlays, many hardware overlay engines can't do that kind of extreme scaling.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top