简体   繁体   English

每次单击按钮后如何从位图中删除点

[英]How to remove points from bitmap after each button click

I have a system which places a small dot on my bitmap for each menu option I select. 我有一个系统,在我选择的每个菜单选项的位图上都放置一个小点。 However I only want one dot to appear on my bitmap at one time so when I click a second option another dot will appear. 但是,我一次只希望一个点出现在我的位图上,所以当我单击第二个选项时,将出现另一个点。 I have a clearPoint method which is used to clear the points off the bitmap, how could I implement it so when i press a new button option the new dot is drawn but the previous is removed instead off all dots being removed. 我有一个clearPoint方法,该方法用于清除位图上的点,如何实现它,因此当我按下新按钮选项时,会绘制新点,但会删除前一个点,而不是删除所有点。

This is my menu option 这是我的菜单选项

@Override
public boolean onMenuItemClick(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
        case R.id.A:
            fmob.mZoomView.setPoint(list.get(0).getLocationY(), list.get(0).getLocationX());
            Toast.makeText(getBaseContext(), "Location A", Toast.LENGTH_SHORT).show();
        return true;
        case R.id.B:
            Toast.makeText(getBaseContext(), "Selected Location B", Toast.LENGTH_SHORT).show();
            fmob.mZoomView.setPoint(list.get(1).getLocationY(), list.get(1).getLocationX());
            return true;
        default:
            return false;
    }
}

This is my clearPoint method 这是我的clearPoint方法

public void clearPoints() {
    points.clear();
    routepoints.clear();
    invalidate();
}

If you already have an event listener, then you should make a method which uses premade methods to first> clear the bitmap, second> add the new point, and third> display the updated bitmap. 如果您已经有一个事件侦听器,那么您应该制作一个使用预制方法的方法,以首先>清除位图,其次>添加新的点,然后第三位>显示更新的位图。 It has to be done in that order or else a semantical error may occur. 必须以该顺序进行,否则可能会发生语义错误。 I would just have the method structured like this: 我只需要这样构造方法:

public void newPoint(int x, int y) /*throws InvalidPointException*/{
    clearPoints();
    //clear the points on the bitmap

    updateBitmapDisplay();
    //update the bitmap with the new points

    addPoint(x, y);
    //add the point to the bitmap

    updateBitmapDisplay();
    //update the bitmap with new points
}

You would then have to use top-down-programming to make these methods using what is available to you. 然后,您将必须使用自顶向下编程来使用可用的方法来制作这些方法。 I don't fully understand your question fully, though, so this may be of no use to you. 不过,我无法完全理解您的问题,因此这可能对您没有用。 Sorry if that turns out to be the case and you needed something different. 抱歉,事实确实如此,您需要其他内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM