1
Eclipse redlines width, height, width, height
在回調中的doSomething()arg列表中。左邊的紅色小X;說:var值從外部調用回調函數:
Multiple markers at this line
- Cannot refer to a non-final variable height inside an inner class defined in a different
method
- Cannot refer to a non-final variable width inside an inner class defined in a different
method
- Cannot refer to a non-final variable width inside an inner class defined in a different
method
- Cannot refer to a non-final variable height inside an inner class defined in a different
method
很顯然,我不想重複getWindowManager().getDefaultDisplay()
從holder
回調內部或從doSomething()
內多次獲得這些值浪費週期。
這整個snip是在一個類中。
感謝您的任何幫助。
...
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
...
final GL10 gl = (GL10) eglContext.getGL();
final Handler handler = new Handler();
SurfaceHolder holder = view.getHolder();
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
int w = 0;
int h = 0;
int x = 0;
int y = 0;
int b[] = new int[w * (y + h)];
int bt[] = new int[w * h];
IntBuffer ib = IntBuffer.wrap(b);
ib.position(0);
gl.glReadPixels(x, 0, w, y + h, GL10.GL_RGBA,GL10.GL_UNSIGNED_BYTE,ib);
...
holder.addCallback(new Callback() {
private EGLSurface surface;
private Runnable painter;
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
painter = new Runnable() {
@Override
public void run() {
doSomething(width, height, width, height, gl);
}
};
handler.post(painter);
}
}); //Callback ends.
}
private void doSomething(int x, int y, int w, int h, GL10 gl) {
// do something
}
真棒!謝謝阿蘭。 – user225626 2010-07-17 00:10:24
這是我的榮幸:) – 2010-07-17 01:34:30