WEB开发网
开发学院手机开发Android 开发 在Android层实现触摸屏校验 阅读

在Android层实现触摸屏校验

 2010-05-31 14:35:00 来源:WEB开发网   
核心提示:这个类是对ts calibrate里的函数的改写 但是其实仅仅这个是不行的。package com.android.calibrate;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;imp

这个类是对ts calibrate里的函数的改写 但是其实仅仅这个是不行的。

package com.android.calibrate;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import android.util.Log;

public class Calibrate {

private calibration cal;

public Calibrate() {

cal = new calibration();

}

class calibration {

int x[] = new int[5];

int xfb[] = new int[5];

int y[] = new int[5];

int yfb[] = new int[5];

int a[] = new int[7];

};

boolean perform_calibration() {

Log.i("XXW", "perform_calibration");

int j;

float n, x, y, x2, y2, xy, z, zx, zy;

float det, a, b, c, e, f, i;

float scaling = (float)65536.0;

// Get sums for matrix

n = x = y = x2 = y2 = xy = 0;

for (j = 0; j < 5; j++) {

n += 1.0;

x += (float)cal.x[j];

y += (float)cal.y[j];

x2 += (float)(cal.x[j] * cal.x[j]);

y2 += (float)(cal.y[j] * cal.y[j]);

xy += (float)(cal.x[j] * cal.y[j]);

}

// Get determinant of matrix -- check if determinant is too small

det = n * (x2 * y2 - xy * xy) + x * (xy * y - x * y2) + y * (x * xy - y * x2);

if (det < 0.1 && det > -0.1) {

Log.i("ts_calibrate: determinant is too small -- %f ", "" + det);

return false;

}

// Get elements of inverse matrix

a = (x2 * y2 - xy * xy) / det;

b = (xy * y - x * y2) / det;

c = (x * xy - y * x2) / det;

e = (n * y2 - y * y) / det;

f = (x * y - n * xy) / det;

i = (n * x2 - x * x) / det;

// Get sums for x calibration

z = zx = zy = 0;

上一页  2 3 4 5 6 7 8 9 10 11 12  下一页

Tags:Android 实现 触摸屏

编辑录入:coldstar [复制链接] [打 印]
赞助商链接