如何画出移动的心电图? 我想做个android程序,类似于网上有一个通过摄像头在闪光灯常亮的帮助下,拍摄手指血流运动,从而在屏幕上显示心电图的程序。我现在很烦恼的是,如何把画出来的心电图向左移动,而且执行速度要快,不要有闪动,诸位有什么比较好的建议和方法吗?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以去看看appdemo里os/Sensors。。他也是一个类似的东西。。 一个数组存个种点~画的时候把出现在屏幕上的点连起来就行了。比如说line(point1.x, point1.y, point2.x, point2.y) http://topic.csdn.net/u/20110830/00/61b7fd1e-22cb-4255-985e-3b10513b0a13.html昨天看到的一个帖子 源码一份!private class GraphView extends View implements SensorListener { private Bitmap mBitmap; private Paint mPaint = new Paint(); private Canvas mCanvas = new Canvas(); private Path mPath = new Path(); private RectF mRect = new RectF(); private float mLastValues[] = new float[3 * 2]; private float mOrientationValues[] = new float[3]; private int mColors[] = new int[3 * 2]; private float mLastX; private float mScale[] = new float[2]; private float mYOffset; private float mMaxX; private float mSpeed = 1.0f; private float mWidth; private float mHeight; public GraphView(Context context) { super(context); mColors[0] = Color.argb(192, 255, 64, 64); mColors[1] = Color.argb(192, 64, 128, 64); mColors[2] = Color.argb(192, 64, 64, 255); mColors[3] = Color.argb(192, 64, 255, 255); mColors[4] = Color.argb(192, 128, 64, 128); mColors[5] = Color.argb(192, 255, 255, 64); mPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mRect.set(-0.5f, -0.5f, 0.5f, 0.5f); mPath.arcTo(mRect, 0, 180); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565); mCanvas.setBitmap(mBitmap); mCanvas.drawColor(0xFFFFFFFF); mYOffset = h * 0.5f; mScale[0] = -(h * 0.5f * (1.0f / (SensorManager.STANDARD_GRAVITY * 2))); mScale[1] = -(h * 0.5f * (1.0f / (SensorManager.MAGNETIC_FIELD_EARTH_MAX))); mWidth = w; mHeight = h; if (mWidth < mHeight) { mMaxX = w; } else { mMaxX = w - 50; } mLastX = mMaxX; super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { synchronized (this) { if (mBitmap != null) { final Paint paint = mPaint; final Path path = mPath; final int outer = 0xFFC0C0C0; final int inner = 0xFFff7010; if (mLastX >= mMaxX) { mLastX = 0; final Canvas cavas = mCanvas; final float yoffset = mYOffset; final float maxx = mMaxX; final float oneG = SensorManager.STANDARD_GRAVITY * mScale[0]; paint.setColor(0xFFAAAAAA); cavas.drawColor(0xFFFFFFFF); cavas.drawLine(0, yoffset, maxx, yoffset, paint); cavas.drawLine(0, yoffset + oneG, maxx, yoffset + oneG, paint); cavas.drawLine(0, yoffset - oneG, maxx, yoffset - oneG, paint); } canvas.drawBitmap(mBitmap, 0, 0, null); float[] values = mOrientationValues; if (mWidth < mHeight) { float w0 = mWidth * 0.333333f; float w = w0 - 32; float x = w0 * 0.5f; for (int i = 0; i < 3; i++) { canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.translate(x, w * 0.5f + 4.0f); canvas.save(Canvas.MATRIX_SAVE_FLAG); paint.setColor(outer); canvas.scale(w, w); canvas.drawOval(mRect, paint); canvas.restore(); canvas.scale(w - 5, w - 5); paint.setColor(inner); canvas.rotate(-values[i]); canvas.drawPath(path, paint); canvas.restore(); x += w0; } } else { float h0 = mHeight * 0.333333f; float h = h0 - 32; float y = h0 * 0.5f; for (int i = 0; i < 3; i++) { canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.translate(mWidth - (h * 0.5f + 4.0f), y); canvas.save(Canvas.MATRIX_SAVE_FLAG); paint.setColor(outer); canvas.scale(h, h); canvas.drawOval(mRect, paint); canvas.restore(); canvas.scale(h - 5, h - 5); paint.setColor(inner); canvas.rotate(-values[i]); canvas.drawPath(path, paint); canvas.restore(); y += h0; } } } } } public void onSensorChanged(int sensor, float[] values) { // Log.d(TAG, "sensor: " + sensor + ", x: " + values[0] + ", y: " + // values[1] + ", z: " + values[2]); synchronized (this) { if (mBitmap != null) { final Canvas canvas = mCanvas; final Paint paint = mPaint; if (sensor == SensorManager.SENSOR_ORIENTATION) { for (int i = 0; i < 3; i++) { mOrientationValues[i] = values[i]; } } else { float deltaX = mSpeed; float newX = mLastX + deltaX; int j = (sensor == SensorManager.SENSOR_MAGNETIC_FIELD) ? 1 : 0; for (int i = 0; i < 3; i++) { int k = i + j * 3; final float v = mYOffset + values[i] * mScale[j]; paint.setColor(mColors[k]); canvas.drawLine(mLastX, mLastValues[k], newX, v, paint); mLastValues[k] = v; } if (sensor == SensorManager.SENSOR_MAGNETIC_FIELD) mLastX += mSpeed; } invalidate(); } } } public void onAccuracyChanged(int sensor, int accuracy) { // TODO Auto-generated method stub } }有问题加QQ群:50466093 代码格式弄错了,晕!private class GraphView extends View implements SensorListener { private Bitmap mBitmap; private Paint mPaint = new Paint(); private Canvas mCanvas = new Canvas(); private Path mPath = new Path(); private RectF mRect = new RectF(); private float mLastValues[] = new float[3 * 2]; private float mOrientationValues[] = new float[3]; private int mColors[] = new int[3 * 2]; private float mLastX; private float mScale[] = new float[2]; private float mYOffset; private float mMaxX; private float mSpeed = 1.0f; private float mWidth; private float mHeight; public GraphView(Context context) { super(context); mColors[0] = Color.argb(192, 255, 64, 64); mColors[1] = Color.argb(192, 64, 128, 64); mColors[2] = Color.argb(192, 64, 64, 255); mColors[3] = Color.argb(192, 64, 255, 255); mColors[4] = Color.argb(192, 128, 64, 128); mColors[5] = Color.argb(192, 255, 255, 64); mPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mRect.set(-0.5f, -0.5f, 0.5f, 0.5f); mPath.arcTo(mRect, 0, 180); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565); mCanvas.setBitmap(mBitmap); mCanvas.drawColor(0xFFFFFFFF); mYOffset = h * 0.5f; mScale[0] = -(h * 0.5f * (1.0f / (SensorManager.STANDARD_GRAVITY * 2))); mScale[1] = -(h * 0.5f * (1.0f / (SensorManager.MAGNETIC_FIELD_EARTH_MAX))); mWidth = w; mHeight = h; if (mWidth < mHeight) { mMaxX = w; } else { mMaxX = w - 50; } mLastX = mMaxX; super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { synchronized (this) { if (mBitmap != null) { final Paint paint = mPaint; final Path path = mPath; final int outer = 0xFFC0C0C0; final int inner = 0xFFff7010; if (mLastX >= mMaxX) { mLastX = 0; final Canvas cavas = mCanvas; final float yoffset = mYOffset; final float maxx = mMaxX; final float oneG = SensorManager.STANDARD_GRAVITY * mScale[0]; paint.setColor(0xFFAAAAAA); cavas.drawColor(0xFFFFFFFF); cavas.drawLine(0, yoffset, maxx, yoffset, paint); cavas.drawLine(0, yoffset + oneG, maxx, yoffset + oneG, paint); cavas.drawLine(0, yoffset - oneG, maxx, yoffset - oneG, paint); } canvas.drawBitmap(mBitmap, 0, 0, null); float[] values = mOrientationValues; if (mWidth < mHeight) { float w0 = mWidth * 0.333333f; float w = w0 - 32; float x = w0 * 0.5f; for (int i = 0; i < 3; i++) { canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.translate(x, w * 0.5f + 4.0f); canvas.save(Canvas.MATRIX_SAVE_FLAG); paint.setColor(outer); canvas.scale(w, w); canvas.drawOval(mRect, paint); canvas.restore(); canvas.scale(w - 5, w - 5); paint.setColor(inner); canvas.rotate(-values[i]); canvas.drawPath(path, paint); canvas.restore(); x += w0; } } else { float h0 = mHeight * 0.333333f; float h = h0 - 32; float y = h0 * 0.5f; for (int i = 0; i < 3; i++) { canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.translate(mWidth - (h * 0.5f + 4.0f), y); canvas.save(Canvas.MATRIX_SAVE_FLAG); paint.setColor(outer); canvas.scale(h, h); canvas.drawOval(mRect, paint); canvas.restore(); canvas.scale(h - 5, h - 5); paint.setColor(inner); canvas.rotate(-values[i]); canvas.drawPath(path, paint); canvas.restore(); y += h0; } } } } } public void onSensorChanged(int sensor, float[] values) { // Log.d(TAG, "sensor: " + sensor + ", x: " + values[0] + ", y: " + // values[1] + ", z: " + values[2]); synchronized (this) { if (mBitmap != null) { final Canvas canvas = mCanvas; final Paint paint = mPaint; if (sensor == SensorManager.SENSOR_ORIENTATION) { for (int i = 0; i < 3; i++) { mOrientationValues[i] = values[i]; } } else { float deltaX = mSpeed; float newX = mLastX + deltaX; int j = (sensor == SensorManager.SENSOR_MAGNETIC_FIELD) ? 1 : 0; for (int i = 0; i < 3; i++) { int k = i + j * 3; final float v = mYOffset + values[i] * mScale[j]; paint.setColor(mColors[k]); canvas.drawLine(mLastX, mLastValues[k], newX, v, paint); mLastValues[k] = v; } if (sensor == SensorManager.SENSOR_MAGNETIC_FIELD) mLastX += mSpeed; } invalidate(); } } } public void onAccuracyChanged(int sensor, int accuracy) { // TODO Auto-generated method stub } } 这是监测sensor水平位置的波动图,和心电图那个是一样的,只是数据不一样而已。这个需要你自己改。如果有问题加QQ群:50466093,一起讨论! lz ,最近也做这个东西,现在有问题了,但是你们群也加不进去,我qq是我名字,你把我拉群里吧,或者可以给我发一个心电图的例子。谢谢啊 ImageView 放大缩小的问题 android 如何实现如下界面 android如今情景怎么样,工作怎么样? android 无焦点获取键盘输入内容 如何限制录音的时间 Cheapest Dofus Kamas Online tab中使用selector无法更改背景 用过MQTT+APOLLO1.7的求助 请教,关于jar的版本标识问题 通过上海发布的API获取交通卡余额,但OkHttp收到不是json对象而是html代码 android弹出对话框 android 加载100M左右的图片
昨天看到的一个帖子
private class GraphView extends View implements SensorListener {
private Bitmap mBitmap;
private Paint mPaint = new Paint();
private Canvas mCanvas = new Canvas();
private Path mPath = new Path();
private RectF mRect = new RectF();
private float mLastValues[] = new float[3 * 2];
private float mOrientationValues[] = new float[3];
private int mColors[] = new int[3 * 2];
private float mLastX;
private float mScale[] = new float[2];
private float mYOffset;
private float mMaxX;
private float mSpeed = 1.0f;
private float mWidth;
private float mHeight; public GraphView(Context context) {
super(context);
mColors[0] = Color.argb(192, 255, 64, 64);
mColors[1] = Color.argb(192, 64, 128, 64);
mColors[2] = Color.argb(192, 64, 64, 255);
mColors[3] = Color.argb(192, 64, 255, 255);
mColors[4] = Color.argb(192, 128, 64, 128);
mColors[5] = Color.argb(192, 255, 255, 64); mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
mRect.set(-0.5f, -0.5f, 0.5f, 0.5f);
mPath.arcTo(mRect, 0, 180);
} @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
mCanvas.setBitmap(mBitmap);
mCanvas.drawColor(0xFFFFFFFF);
mYOffset = h * 0.5f;
mScale[0] = -(h * 0.5f * (1.0f / (SensorManager.STANDARD_GRAVITY * 2)));
mScale[1] = -(h * 0.5f * (1.0f / (SensorManager.MAGNETIC_FIELD_EARTH_MAX)));
mWidth = w;
mHeight = h;
if (mWidth < mHeight) {
mMaxX = w;
} else {
mMaxX = w - 50;
}
mLastX = mMaxX;
super.onSizeChanged(w, h, oldw, oldh);
} @Override
protected void onDraw(Canvas canvas) {
synchronized (this) {
if (mBitmap != null) {
final Paint paint = mPaint;
final Path path = mPath;
final int outer = 0xFFC0C0C0;
final int inner = 0xFFff7010; if (mLastX >= mMaxX) {
mLastX = 0;
final Canvas cavas = mCanvas;
final float yoffset = mYOffset;
final float maxx = mMaxX;
final float oneG = SensorManager.STANDARD_GRAVITY
* mScale[0];
paint.setColor(0xFFAAAAAA);
cavas.drawColor(0xFFFFFFFF);
cavas.drawLine(0, yoffset, maxx, yoffset, paint);
cavas.drawLine(0, yoffset + oneG, maxx, yoffset + oneG,
paint);
cavas.drawLine(0, yoffset - oneG, maxx, yoffset - oneG,
paint);
}
canvas.drawBitmap(mBitmap, 0, 0, null); float[] values = mOrientationValues;
if (mWidth < mHeight) {
float w0 = mWidth * 0.333333f;
float w = w0 - 32;
float x = w0 * 0.5f;
for (int i = 0; i < 3; i++) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.translate(x, w * 0.5f + 4.0f);
canvas.save(Canvas.MATRIX_SAVE_FLAG);
paint.setColor(outer);
canvas.scale(w, w);
canvas.drawOval(mRect, paint);
canvas.restore();
canvas.scale(w - 5, w - 5);
paint.setColor(inner);
canvas.rotate(-values[i]);
canvas.drawPath(path, paint);
canvas.restore();
x += w0;
}
} else {
float h0 = mHeight * 0.333333f;
float h = h0 - 32;
float y = h0 * 0.5f;
for (int i = 0; i < 3; i++) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.translate(mWidth - (h * 0.5f + 4.0f), y);
canvas.save(Canvas.MATRIX_SAVE_FLAG);
paint.setColor(outer);
canvas.scale(h, h);
canvas.drawOval(mRect, paint);
canvas.restore();
canvas.scale(h - 5, h - 5);
paint.setColor(inner);
canvas.rotate(-values[i]);
canvas.drawPath(path, paint);
canvas.restore();
y += h0;
}
} }
}
} public void onSensorChanged(int sensor, float[] values) {
// Log.d(TAG, "sensor: " + sensor + ", x: " + values[0] + ", y: " +
// values[1] + ", z: " + values[2]);
synchronized (this) {
if (mBitmap != null) {
final Canvas canvas = mCanvas;
final Paint paint = mPaint;
if (sensor == SensorManager.SENSOR_ORIENTATION) {
for (int i = 0; i < 3; i++) {
mOrientationValues[i] = values[i];
}
} else {
float deltaX = mSpeed;
float newX = mLastX + deltaX; int j = (sensor == SensorManager.SENSOR_MAGNETIC_FIELD) ? 1
: 0;
for (int i = 0; i < 3; i++) {
int k = i + j * 3;
final float v = mYOffset + values[i] * mScale[j];
paint.setColor(mColors[k]);
canvas.drawLine(mLastX, mLastValues[k], newX, v,
paint);
mLastValues[k] = v;
}
if (sensor == SensorManager.SENSOR_MAGNETIC_FIELD)
mLastX += mSpeed;
}
invalidate();
}
}
} public void onAccuracyChanged(int sensor, int accuracy) {
// TODO Auto-generated method stub }
}
有问题加QQ群:50466093
private Bitmap mBitmap;
private Paint mPaint = new Paint();
private Canvas mCanvas = new Canvas();
private Path mPath = new Path();
private RectF mRect = new RectF();
private float mLastValues[] = new float[3 * 2];
private float mOrientationValues[] = new float[3];
private int mColors[] = new int[3 * 2];
private float mLastX;
private float mScale[] = new float[2];
private float mYOffset;
private float mMaxX;
private float mSpeed = 1.0f;
private float mWidth;
private float mHeight; public GraphView(Context context) {
super(context);
mColors[0] = Color.argb(192, 255, 64, 64);
mColors[1] = Color.argb(192, 64, 128, 64);
mColors[2] = Color.argb(192, 64, 64, 255);
mColors[3] = Color.argb(192, 64, 255, 255);
mColors[4] = Color.argb(192, 128, 64, 128);
mColors[5] = Color.argb(192, 255, 255, 64); mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
mRect.set(-0.5f, -0.5f, 0.5f, 0.5f);
mPath.arcTo(mRect, 0, 180);
} @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
mCanvas.setBitmap(mBitmap);
mCanvas.drawColor(0xFFFFFFFF);
mYOffset = h * 0.5f;
mScale[0] = -(h * 0.5f * (1.0f / (SensorManager.STANDARD_GRAVITY * 2)));
mScale[1] = -(h * 0.5f * (1.0f / (SensorManager.MAGNETIC_FIELD_EARTH_MAX)));
mWidth = w;
mHeight = h;
if (mWidth < mHeight) {
mMaxX = w;
} else {
mMaxX = w - 50;
}
mLastX = mMaxX;
super.onSizeChanged(w, h, oldw, oldh);
} @Override
protected void onDraw(Canvas canvas) {
synchronized (this) {
if (mBitmap != null) {
final Paint paint = mPaint;
final Path path = mPath;
final int outer = 0xFFC0C0C0;
final int inner = 0xFFff7010; if (mLastX >= mMaxX) {
mLastX = 0;
final Canvas cavas = mCanvas;
final float yoffset = mYOffset;
final float maxx = mMaxX;
final float oneG = SensorManager.STANDARD_GRAVITY
* mScale[0];
paint.setColor(0xFFAAAAAA);
cavas.drawColor(0xFFFFFFFF);
cavas.drawLine(0, yoffset, maxx, yoffset, paint);
cavas.drawLine(0, yoffset + oneG, maxx, yoffset + oneG,
paint);
cavas.drawLine(0, yoffset - oneG, maxx, yoffset - oneG,
paint);
}
canvas.drawBitmap(mBitmap, 0, 0, null); float[] values = mOrientationValues;
if (mWidth < mHeight) {
float w0 = mWidth * 0.333333f;
float w = w0 - 32;
float x = w0 * 0.5f;
for (int i = 0; i < 3; i++) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.translate(x, w * 0.5f + 4.0f);
canvas.save(Canvas.MATRIX_SAVE_FLAG);
paint.setColor(outer);
canvas.scale(w, w);
canvas.drawOval(mRect, paint);
canvas.restore();
canvas.scale(w - 5, w - 5);
paint.setColor(inner);
canvas.rotate(-values[i]);
canvas.drawPath(path, paint);
canvas.restore();
x += w0;
}
} else {
float h0 = mHeight * 0.333333f;
float h = h0 - 32;
float y = h0 * 0.5f;
for (int i = 0; i < 3; i++) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.translate(mWidth - (h * 0.5f + 4.0f), y);
canvas.save(Canvas.MATRIX_SAVE_FLAG);
paint.setColor(outer);
canvas.scale(h, h);
canvas.drawOval(mRect, paint);
canvas.restore();
canvas.scale(h - 5, h - 5);
paint.setColor(inner);
canvas.rotate(-values[i]);
canvas.drawPath(path, paint);
canvas.restore();
y += h0;
}
} }
}
} public void onSensorChanged(int sensor, float[] values) {
// Log.d(TAG, "sensor: " + sensor + ", x: " + values[0] + ", y: " +
// values[1] + ", z: " + values[2]);
synchronized (this) {
if (mBitmap != null) {
final Canvas canvas = mCanvas;
final Paint paint = mPaint;
if (sensor == SensorManager.SENSOR_ORIENTATION) {
for (int i = 0; i < 3; i++) {
mOrientationValues[i] = values[i];
}
} else {
float deltaX = mSpeed;
float newX = mLastX + deltaX; int j = (sensor == SensorManager.SENSOR_MAGNETIC_FIELD) ? 1
: 0;
for (int i = 0; i < 3; i++) {
int k = i + j * 3;
final float v = mYOffset + values[i] * mScale[j];
paint.setColor(mColors[k]);
canvas.drawLine(mLastX, mLastValues[k], newX, v,
paint);
mLastValues[k] = v;
}
if (sensor == SensorManager.SENSOR_MAGNETIC_FIELD)
mLastX += mSpeed;
}
invalidate();
}
}
} public void onAccuracyChanged(int sensor, int accuracy) {
// TODO Auto-generated method stub }
}