基于opencv的相机之鬼怪贴图功能实现(十一)

简介

  本篇是对实现图片处理功能:【鬼怪贴图】实现的记录。

实现原理

  本功能实现比较简单,主要就是使用Android的Canvas模块。根据最底下鬼怪贴图菜单,来选择对应贴图,接着touch函数根据移动操作,利用Canvas
来更新鬼怪贴图在原图像中的位置。

具体代码

 
public class ButtonListener implements OnClickListener, OnTouchListener{
        @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        ghostVariable.curGhostBtnNumber = arg0.getId() + ghostVariable.ghostOffsetNumber;
        ghostVariable.ghostNowPic = ((BitmapDrawable) getResources().getDrawable(
                         ghostVariable.ghostPicture[ghostVariable.curGhostBtnNumber])).getBitmap();
        ghostVariable.ghostFunction.saveMyBitmap(ghostVariable.tmpMatName, ghostVariable.ghostBitmapBackground);
    }
}
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
        if(event.getAction() == MotionEvent.ACTION_MOVE ){
            ghostVariable.ghostBitmapBackground = ghostVariable.ghostFunction.getLoacalBitmap(ghostVariable.tmpMatName)
                             .copy(Bitmap.Config.ARGB_8888, true);
            ghostVariable.myGhostcanvas.setBitmap(ghostVariable.ghostBitmapBackground);
            ghostVariable.myGhostcanvas.drawBitmap(ghostVariable.ghostNowPic,
                  event.getX() - ghostVariable.ghostWidthStart) * ghostVariable.ghostPicWidthScale - 
                              (ghostVariable.ghostNowPic.getWidth() / 2), event.getY() * ghostVariable.ghostPicHeightScale -
                              (ghostVariable.ghostNowPic.getHeight() / 2), null);
            ghostVariable.mypicGhostImageView_1.setImageBitmap(ghostVariable.ghostBitmapBackground);
        }
        return true;
    }

    在鬼怪贴图菜单栏中,点击对应选项之后,onClick将根据ghostVariable.curGhostBtnNumber,来更新当前贴图操作会被使用的鬼怪图片到ghostVariable.ghostNowPic中。用户在图片上滑动的时候,将触发onTouch函数,该函数根据滑动坐标位置,利用myGhostcanvas来实现贴图操作,并通过更新mypicGhostImageView_1,将结果实时显示出来。

效果演示

  对应的效果图片如下:
               
         贴图效果 
具体演示下载:http://download.csdn.net/detail/u011630458/9261617

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值