Android绘制相关注意问题
2018-02-07 00:58
381 查看
画笔粗细导致的Rect和line不精准绘制问题
画笔粗细在画line的时候应该注意,画笔以中心向两边扩展,目前用rect代替line去画,然后rect四周往内偏移画笔一半粗细。
path.op问题
路径取交集的时候如果往path添加的是Rect集合,那么确保Rect不会绘制错误,这样不同path取交集出问题就不难排查
绘制的时候bitmap获取非透明像素
bitmap.extractAlpha();
bitmap使用放大不能用createBitmap要用Martix
取值
getX(),getLeft(),0和getMeasureWidth();
在当前View中绘制(0,0,getMeasureWidth(),getMeasureHeight());
在父容器中绘制View(getX(),getY(),getX()+getMeasureWidth(),getY()+getMeasureHeight();
获取截图
限制当前区域大小,用于父容器使用了adjustclipbounds=true的情况
将bitmap绘制时限制在指定的宽高,rect是View的矩形区域,nullPaint是空对象
保证添加shadower的时候视图大小一致
因为绘制shadower的时候是按照px绘制的,所以我们把px当做dp转成px之后再计算缩放比之后用矩阵放大就能保证视图大小一致
画笔粗细在画line的时候应该注意,画笔以中心向两边扩展,目前用rect代替line去画,然后rect四周往内偏移画笔一半粗细。
path.op问题
路径取交集的时候如果往path添加的是Rect集合,那么确保Rect不会绘制错误,这样不同path取交集出问题就不难排查
绘制的时候bitmap获取非透明像素
bitmap.extractAlpha();
bitmap使用放大不能用createBitmap要用Martix
Matrix matrix = new Matrix(); matrix.postScale(sx, sy); result = Bitmap.createBitmap(width, height, bitmap.getConfig()); Canvas c = new Canvas(result); c.drawBitmap(bitmap, matrix, null); bitmap.recycle(); bitmap = result;
取值
getX(),getLeft(),0和getMeasureWidth();
在当前View中绘制(0,0,getMeasureWidth(),getMeasureHeight());
在父容器中绘制View(getX(),getY(),getX()+getMeasureWidth(),getY()+getMeasureHeight();
获取截图
public static Bitmap getBitmapCache(View view){ //刷新 view.setDrawingCacheEnabled(false); view.setDrawingCacheEnabled(true); Bitmap bitmap = view.getDrawingCache(); //不全 /*view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.buildDrawingCache(); Bitmap bitmap = view.getDrawingCache();*/ //只有黑线 /* view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); Canvas canvas=new Canvas(); Bitmap bitmap=Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),Bitmap.Config.ARGB_8888); view.draw(canvas);*/ return bitmap; }
限制当前区域大小,用于父容器使用了adjustclipbounds=true的情况
Rect clipBounds; private void clip() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setClipToOutline(true); }else{ if (clipBounds==null) clipBounds = new Rect(getLeft(), getTop(), getRight(), getBottom()); ViewCompat.setClipBounds(this, clipBounds); } }
将bitmap绘制时限制在指定的宽高,rect是View的矩形区域,nullPaint是空对象
canvas.drawBitmap(ramdomBitmap, height, width), null, rect, nullPaint);
保证添加shadower的时候视图大小一致
因为绘制shadower的时候是按照px绘制的,所以我们把px当做dp转成px之后再计算缩放比之后用矩阵放大就能保证视图大小一致
相关文章推荐
- Android—广播(Broadcast)—广播的注意事项及相关问题分析
- Android项目开发中务必注意的相关问题
- Android绘制View相关的几个问题
- android View绘制相关问题总结
- Android绘制View相关的几个问题
- 学习Android开发需要注意的十个问题
- 学习Android 注意的十个问题
- android中事件的处理以及应该注意的问题
- 调用android system Search UI须注意的问题
- Android中Proguard和JNI的相关问题
- APK 变成 ZIP:Android 手机应用程序文件下载服务器需要注意的问题
- Android 开发相关注意点
- android相关问题、网摘集锦
- 绘制控件位图背景--需要注意的问题
- android ViewGroup删除子视图时应该注意的一个问题
- 关于团队合作开发项目时的沟通问题!(不仅要注意【相关机能】,还要注意【相似功能】)
- Android发布注意问题
- android相关问题、网摘集锦(持续更新中...)
- Android高手进阶教程(十九)之---Android开发中,使用线程应该注意的问题!
- android线程使用注意问题?【安卓进化二】