1、自定义一个mView extended ImageView,重写他的ondraw函数 把一个原始drawable资源decode成bitmap,缩小为0.667 然后直接用canvas.drawbitmap绘制出来,效果非常差,画笔设置了paint.setAntiAlias(true); 但是如果把他绘制在一个ARGB_8888的bitmap上,再绘制这个bitmap,效果很好 求解释
2、还是上面这个mView 把一个112px(宽度为准)左右的图片,放大到130px左右,再旋转15度 直接用canvas.drawbitmap绘制出来,效果奇差 画笔设置了paint.setAntiAlias(true); 求解决办法
2、还是上面这个mView 把一个112px(宽度为准)左右的图片,放大到130px左右,再旋转15度 直接用canvas.drawbitmap绘制出来,效果奇差 画笔设置了paint.setAntiAlias(true); 求解决办法
Paint p = new Paint();
p.setDither(true);
把mView类贴上来看一下
设置了setDither也没用,至少说效果没有显著提高下面这个是代码:
public class RotateView extends ImageView { Paint mPaint;
Bitmap userBmp;
Matrix matrix;
public RotateView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
mPaint=new Paint();
mPaint.setAntiAlias(true);
mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
mPaint.setDither(true);
}
@Override
public void setImageBitmap(Bitmap bmp) {
// TODO Auto-generated method stub
userBmp=bmp;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
if(userBmp!=null)
{
matrix=new Matrix();
float xScale=75f/userBmp.getWidth();
float yScale=75f/userBmp.getHeight();
if(userBmp.getHeight()<userBmp.getWidth())
{
matrix.postScale(xScale, yScale);
}
else
{
matrix.postScale(xScale, xScale);
}
matrix.postScale(1.75f, 1.75f);
matrix.postRotate(15);
matrix.postTranslate(50, 4);
canvas.drawBitmap(userBmp, matrix, mPaint);
matrix=null;
}
}
}
matrix.postScale(1.75f, 1.75f);
matrix.postRotate(15);
matrix.postTranslate(50, 4);
把效果都单独试试看会不会太差,或者不加效果看看,太差的话就不是代码的问题了
canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG));