Android的 - 触摸绘图 [英] Android - touch drawing
问题描述
我在看<一href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html"相对=nofollow>这个样本由谷歌绘图应用,当我运行在模拟器中的应用程序,并尝试绘制我的鼠标,图纸不顺利出现。该圆圈出现与他们之间的差距。只有当我拖我的鼠标慢慢地,我得到一个完整的线。我还没有实际的设备来测试这个,所以我想知道这是怎么会在实际设备上也,或这是一个模拟的行为呢?
I am looking at this sample drawing app by Google, and when I run the app in the simulator and try to draw with my mouse, the drawing does not appear smoothly. The circles are appearing with gaps between them. Only when I drag my mouse slowly I get a unbroken line. I don't yet have an actual device to test this on, so I want to know if this is how it will be on the actual device also, or is this a simulator behavior?
如果这是怎么会出现在设备上。此外,我应该怎么做才能让触摸绘图顺利?
If this is how it will appear on the device also, what should I do to make the touch drawing smooth?
更新:
实际的code,做图纸是:
The actual code that does the drawing is:
private void drawPoint(float x, float y, float pressure, float width) {
if (width < 1) width = 6;
if (mBitmap != null) {
float radius = width / 2;
int pressureLevel = (int)(pressure * 255);
mPaint.setARGB(pressureLevel, 255, 255, 255);
mCanvas.drawCircle(x, y, radius, mPaint);
mRect.set((int) (x - radius - 2), (int) (y - radius - 2),
(int) (x + radius + 2), (int) (y + radius + 2));
invalidate(mRect);
}
}
@Override public boolean onTouchEvent(MotionEvent event) {
int N = event.getHistorySize();
int P = event.getPointerCount();
for (int i = 0; i < N; i++) {
for (int j = 0; j < P; j++) {
mCurX = event.getHistoricalX(j, i);
mCurY = event.getHistoricalY(j, i);
drawPoint(mCurX, mCurY,
event.getHistoricalPressure(j, i),
event.getHistoricalTouchMajor(j, i));
}
}
for (int j = 0; j < P; j++) {
mCurX = event.getX(j);
mCurY = event.getY(j);
drawPoint(mCurX, mCurY, event.getPressure(j), event.getTouchMajor(j));
}
}
任何帮助改善这将是极大的AP preciated。
Any help in improving it would be greatly appreciated.
推荐答案
这将是参差不齐的,但我相信,code为画点,所以如果你只画一条线,开始在那里的最后端被吸引到新的点,这将是连续的。
It will be jagged, but I believe that code is drawing points, so if you just draw a line, starting where the last end was drawn to the new point, it will be continuous.
是的,它会寻找同样的方式在实际设备上。
And yes, it will look the same way on an actual device.
另一种选择,而我是从内存在做,是有一些pressure值是0和255之间,或0和1,将其设置为最高值,所有的时间。这实际上可能是一个简单的解决你的问题。
The other option, which I am doing from memory, is there was some pressure value that was between 0 and 255, or 0 and 1, set it to the highest value, all the time. That may actually be a simple solution to your problem.
这将帮助,如果你表现出code,实际上是做图纸,顺便说一句。
It would help if you show the code that is actually doing the drawing, btw.
更新:
正如我所提到的变化这一行:
As I mentioned change this line:
int pressureLevel = (int)(pressure * 255);
到
int pressureLevel = (int)(255);
应该解决您的问题。
should fix your problem.
如果说没有的话,而不是使用画圆
您可能希望只使用的drawLine
,那么你会跟踪你刚刚绘制的最后一个圆圈。
If that doesn't then rather than using drawCircle
you may want to just use drawLine
, then you would keep track of the last circle you had just drawn.
这篇关于Android的 - 触摸绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!