View去锯齿,在有些机器需要在图层的软件层才能实现
来源:互联网 发布:熊猫加速器mac版 编辑:程序博客网 时间:2024/05/18 00:05
众所周知,android绘图抗锯齿常规方法有两种:一种在Paint设置,一种在Canvas设置:
package com.example.root.antialias;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Matrix;import android.graphics.Paint;import android.graphics.PaintFlagsDrawFilter;import android.util.AttributeSet;import android.util.Log;import android.view.View;/** * Created by root on 7/31/16. */public class AntiAliasView extends View { private PaintFlagsDrawFilter paintFlagsDrawFilter; private Matrix mMatrix = new Matrix(); private Paint mPaint = new Paint(); private Bitmap bitmap; public AntiAliasView(Context context, AttributeSet attributeSet){ super(context,attributeSet); if(this.isHardwareAccelerated()){ Log.d("vfp8341","Opened"); setLayerType(View.LAYER_TYPE_SOFTWARE, null); Log.d("vfp8341","If hardWareAccelerated:" + this.isHardwareAccelerated()); }else { Log.d("vfp8341","Closed"); Log.d("vfp8341","LayerType before:" + getLayerType()); setLayerType(View.LAYER_TYPE_SOFTWARE, null); Log.d("vfp8341","LayerType after:" + getLayerType()); Log.d("vfp8341","If hardWareAccelerated:" + this.isHardwareAccelerated()); } paintFlagsDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG); mPaint.setAntiAlias(true); mPaint.setFilterBitmap(true); mMatrix.setRotate(-30); mMatrix.postScale(1.0f, 1.0f); bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.math); } @Override public void onDraw(Canvas canvas){ super.onDraw(canvas); canvas.translate(0,100); //for the contrast canvas.drawBitmap(bitmap,mMatrix,null); canvas.translate(0,260); //Paint canvas.drawBitmap(bitmap,mMatrix,mPaint); canvas.translate(0, 260); //PaintFlagsDrawFilter canvas.setDrawFilter(paintFlagsDrawFilter); canvas.drawBitmap(bitmap, mMatrix, null); }}
在HuaweiG520上运行,如果把构造函数里的if-else去掉,则两种去锯齿方法都无效;如果加上if-else,其实就是一句setLayerType有效,则两种去锯齿方法都生效(G520不支持Studio截图,只好拍照了)。如下是三张图从上到下叠加了的,效果不是太明显,仔细看的话,边沿确实不一样。G520分辨率低,还可勉强看的出来,在N6则完全无效果,锯齿被分辨率消化了:
Log如下:
08-20 10:04:57.102 2292-2292/com.example.root.antialias D/vfp8341: Closed
08-20 10:04:57.102 2292-2292/com.example.root.antialias D/vfp8341: LayerType before:0
08-20 10:04:57.102 2292-2292/com.example.root.antialias D/vfp8341: LayerType after:1
08-20 10:04:57.102 2292-2292/com.example.root.antialias D/vfp8341: If hardWareAccelerated:false
View中定义:
public static final int LAYER_TYPE_HARDWARE = 2;
public static final int LAYER_TYPE_NONE = 0;
public static final int LAYER_TYPE_SOFTWARE = 1;
说明在该机器必须在软件层才能开启抗锯齿。之前看过文章说硬件加速会对抗锯齿有影响,但是这种情况下硬件加速一直是关闭的。
0 0
- View去锯齿,在有些机器需要在图层的软件层才能实现
- UIView层动画在view转换上的应用
- 怎么样才能让层显示在FLASH之上呢
- 改变SEO思想才能站在更高层执行SEO
- 始终飘在右下角的图层
- 总是在顶部的层
- 浮云在右边的层
- 用css3实现鼠标移入在原来的层上面显示另一个层的动画效果
- 11.Tornado在TCP层里的工作机制---TCP层的实现
- 在实现持久层中工具的应用(1)
- 在实现持久层中工具的应用(2)
- 在实现持久层中工具的应用(3)
- 在实现持久层中工具的应用(4)
- 在实现持久层中工具的应用(5)
- 在实现持久层中工具的应用(6)
- Android开发之fsl在HAL层Camera的实现
- Android开发之fsl在HAL层Camera的实现
- sendmsg在传输层的实现(一)
- PS基础及选框工具笔记(CS6)
- gsoap入门:Schema类型映射塈将xsd:date类型转为struct tm
- bzoj2151(贪心,stl->堆和pair
- 从头到尾解析Hash 表算法
- The object of type 'RectTransform' has been destroyed but you are still trying to access it
- View去锯齿,在有些机器需要在图层的软件层才能实现
- 简单实现标题栏悬浮状态,使用PullToRefreshListView上拉加载下拉刷新
- mac电脑中javaweb不用odbc来连接access 数据库
- 史上最全的英语连读规则一网打尽
- hdu 1849 Rabbit and Grass(Nim博弈入门)
- iOS 8 Auto Layout界面自动布局系列2-使用Xcode的Interface Builder添加布局约束
- EL
- 【01背包+完全背包】HDU3449-Consumer
- 浅谈微信红包的算法