本文介绍了从GestureOverlayView android系统中清除手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用GestureOverlayView画我已经成功地实现了它的任何图片,但是当我要画另一张照片,我需要从GestureOverlayView在我activity.How我能做到这一点清除previous?
请看看我的code:
公共类MainActivity延伸活动{ 私人按钮button_save;
私人按钮button_clear;
私人GestureOverlayView姿势; @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); 的setContentView(R.layout.activity_main); 手势=(GestureOverlayView)findViewById(R.id.gestures);
button_save =(按钮)findViewById(R.id.save_button);
button_clear =(按钮)findViewById(R.id.clearbtn);
button_save.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(查看为arg0){
尝试{
位图gestureImg = gesture.getGesture()。toBitmap(100,100,
8,Color.BLACK); ByteArrayOutputStream BOS =新ByteArrayOutputStream();
gestureImg.com preSS(Bitmap.Com pressFormat.PNG,100,BOS);
字节[] = bArray bos.toByteArray(); 意向意图=新意图(MainActivity.this,
Activity2.class); intent.putExtra(画,bArray);
startActivity(意向); }赶上(例外五){
e.printStackTrace();
Toast.makeText(MainActivity.this,关于字符串,不画
3000).show();
}
}
}); button_clear.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(视图v){ ** //这里做什么来清除我的手绘动画** }
});
}
解决方案
这两行将从您的活动清除创建手势
gesture.cancelClearAnimation();
gesture.clear(真);
I am using GestureOverlayView to draw any picture I have implemented it successfully,but when i want to draw another picture, I need to clear the previous from the GestureOverlayView in my activity.How can I do it ?
Please look into my code :
public class MainActivity extends Activity {
private Button button_save;
private Button button_clear;
private GestureOverlayView gesture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gesture = (GestureOverlayView) findViewById(R.id.gestures);
button_save = (Button) findViewById(R.id.save_button);
button_clear = (Button) findViewById(R.id.clearbtn);
button_save.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
Bitmap gestureImg = gesture.getGesture().toBitmap(100, 100,
8, Color.BLACK);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
gestureImg.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] bArray = bos.toByteArray();
Intent intent = new Intent(MainActivity.this,
Activity2.class);
intent.putExtra("draw", bArray);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "No draw on the string",
3000).show();
}
}
});
button_clear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
**//What to do here to clear my drawn animation**
}
});
}
解决方案
These two lines will clear the created gesture from your activity
gesture.cancelClearAnimation();
gesture.clear(true);
这篇关于从GestureOverlayView android系统中清除手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!