android Canvas.drawBitmap 方法的理解
16lz
2021-01-25
在自定义view中需要绘制出画笔的图片,并且在当前按下的位置实时绘制, 我的步骤是:(1)获取资源文件的下的画笔bitmap : Bitmap bitmapPaint = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.paint); (2)在ondraw中 Canvas.drawBitmap(bitmapPaint,move_x,move_y, new Paint(Paint.Paint.ANTI_ALIAS_FLAG));实时绘制运行后结果发现:画笔不在当前按下的位置 经过查看源码发现: canvas.drawBitmap(Bitmap bitmap, float left, float top, Paint paint)中 bitmap --- 需要绘制bitmap对象left ---- bitmap左边距离当前自定义view 左边的 距离top ---- bitmap上边距离当前自定义view 上边的 距离paint ---- 绘制的画笔 我要将画笔显示在当前按下的位置点,所以将bitmap向上平移bitmap的高度: 最终使用: canvas.drawBitmap(bitmapPaint,move_x,move_y-bitmapPaint.getHeight(), new Paint(Paint.ANTI_ALIAS_FLAG)); move_x --- 当前手指按下的屏幕x坐标 move_y --- 当前手指按下的屏幕y坐标
更多相关文章
- Android(安卓)编译过程分析(1)
- 玩转Scroller打造平滑滚动效果
- android 顶部横向滑动菜单效果
- Android(安卓)listView scroll 恢复滚动位置
- Android(安卓)OpenGLES绘制yuv420纹理
- android ImageView 图片宽度全屏,高度自适应的写法
- [Android]使用RecyclerView替代ListView(三)
- LocationManager的使用
- android百度地图