如何在画布和路径抗锯齿 [英] how to antialiasing in the canvas and path

查看:1360
本文介绍了如何在画布和路径抗锯齿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见面的时候我使用canvas.clipPath麻烦,它显示锯齿,它看起来并不顺利,我知道如果我用油漆,我可以用mPaint.setFlags(Paint.ANTI_ALIAS_FLAG),这样可以抗锯齿,但在我的code,我不能使用涂料。

i meet a trouble when i use canvas.clipPath,it show sawtooth,it looks not smooth,i know if i used a Paint,i can use mPaint.setFlags(Paint.ANTI_ALIAS_FLAG) ,this can antialiasing ,but in my code ,i cannot use paint.

public static void drawCurrentPageArea(Canvas canvas, Bitmap bitmap) {
    //cebakhja


    canvas.save();
    canvas.clipPath(getPath5(), Region.Op.XOR);
    canvas.drawBitmap(bitmap, 0, 0, null);
    canvas.restore();
}

public static Path getPath5()
{
    Path mPath5 = new Path();

    mPath5.moveTo(ptc.x, ptc.y);
    mPath5.quadTo(pte.x, pte.y, ptb.x,ptb.y);
    mPath5.lineTo(pta.x, pta.y);
    mPath5.lineTo(ptk.x, ptk.y);
    mPath5.quadTo(pth.x, pth.y, ptj.x,ptj.y);
    mPath5.lineTo(ptf.x, ptf.y);
    mPath5.close();
    return mPath5;
}

您可以看到我使用canvas.drawBitmap(位图,0,0,NULL);油漆是null.if我需要添加颜料,你可以有一些建议吗? PIC是作为 http://i.6.cn/cvbnm/36 /5c/20/5d8d20e3bafe432d792793509f99131e.jpg

you can see i use canvas.drawBitmap(bitmap, 0, 0, null); paint is null.if i need add a paint ,can you have some advice? the pic is as http://i.6.cn/cvbnm/36/5c/20/5d8d20e3bafe432d792793509f99131e.jpg

编辑:我定的油漆为空,但不影响

edit:i set the paint that is null ,but not effect

推荐答案

试试这个。

private Paint mBitmapPaint = new Paint() {
    {
        setAntiAlias(true);
        setFilterBitmap(true);
    }
};

public static void drawCurrentPageArea(Canvas canvas, Bitmap bitmap) {
    // cebakhja
    canvas.save();
    canvas.clipPath(getPath5(), Region.Op.XOR);
    canvas.drawBitmap(bitmap, 0, 0, mBitmapPaint);
    canvas.restore();
}

这篇关于如何在画布和路径抗锯齿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆