0
我有点困惑我的代码在Android 3和Android 4的工作方式。我试图每2秒拍一张照片,每次找到它的色相和Lum然后使用这些数字作为X Y坐标在canvasView中在地图上画一个十字。我使用可怕的方式在Android 3中工作正常。以下是我的代码块。android老相对较新版本
//this is the Activity to take the picture
public class ProcessAnalyser extends Activity implements OnClickListener,
SurfaceHolder.Callback, Camera.PictureCallback {
... declare a bunch of variables here
static double H, L;
public void onPictureTaken(final byte[] data, Camera camera) {
...code here
H = some value;
L = some value;
}
经过长期RGB工作的H和L得到这是我从隔壁班
// this View draws the cross on a canvas
public class CanvasView extends View {
Bitmap bmp;
float X, Y;
static double kx, ky,width, height;// the code could be wrote whothout all these vars, but I try to split the drawing line of code into smaller chunks
public CanvasView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(inflater != null){
inflater.getContext();//this was the BIG problem
}
bmp=BitmapFactory.decodeResource(getResources(), R.drawable.position);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
width = (double) getWidth();
height = (double) getHeight();
kx = (double)width/360;
ky = (double)height/100;
X = Math.round(ProcessAnalyser.H);
Y = Math.round(ProcessAnalyser.L);
setBackgroundResource(R.drawable.spectrum);
canvas.drawBitmap(bmp, (float)(X *kx)-15, (float) (Y *ky)-15 , null);
}
}
我想这种做法看起来很可怕的人访问某些价值,但它的作品。每次在带有android 3的三星平板电脑上拍摄新照片时,十字会重新绘制在一个新的位置。但是,如果我在带有Android 4的设备上尝试它,则十字架会保持在0.0位置。
我试图把H和L放在一个SQLite中,但是当试图访问它们时它无法从一个View中访问数据库,它看起来像SQLiteOpenHelper没有将视图作为参数,它要求上下文。 – user3140889