【问题标题】:Is it possible to save touch gesture history into image in Android?是否可以将触摸手势历史保存到 Android 中的图像中?
【发布时间】:2013-02-23 18:59:53
【问题描述】:

我想在 Android 平台上开发一个可以将触摸手势历史保存到图像中的应用。

这是android开发者网站上关于触摸手势历史的简要说明。

"History。通过调用MotionEvent方法getHistorySize()可以得到一个手势历史的大小,然后通过运动事件的getHistorical方法可以得到每个历史事件的位置、大小、时间、压力. 历史记录在渲染用户手指轨迹时很有用,例如触摸绘图。有关详细信息,请参阅 MotionEvent 参考。"

来源:http://developer.android.com/training/gestures/movement.html

【问题讨论】:

    标签: android image gesture


    【解决方案1】:

    简短的回答:是的,这是可能的。引用的文档描述的是,当运动事件到达您的活动时,您可以获得这一事件的历史记录。这是因为在将它们传送到您的 Activity 之前可能会经过一段时间,并且 Android 会在此期间累积事件。每次收到 onTouch 时,您都需要提取此信息并将其存储在某种数据结构中。然后在您的 onDraw 方法中将其显示给用户。如果要将创建的位图图像写入文件,可以使用

    Bitmap bm2 = createBitmap();
    // Do the draw commands to the bitmap here
    OutputStream stream = new FileOutputStream("/sdcard/test.jpg");
    /* Write bitmap to file using JPEG and 80% quality hint for JPEG. */
    bm2.compress(CompressFormat.JPEG, 80, stream);
    

    此代码来自stackOverflow question

    【讨论】:

    • 非常感谢您的回答... :D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多