bitmapshader和canvas.scaling android

bitmapshader和canvas.scaling android,android,bitmap,android-canvas,paint,Android,Bitmap,Android Canvas,Paint,有人对以下问题有什么提示或解释吗? 我使用位图着色器绘制路径。当画布未缩放时,它看起来很好(第一张图片)。 当我缩放到(放大)中时,bitmapshader不会被缩放,看起来非常难看。放大后,我尝试了几种方法来重新创建bitmapshader,但没有成功:-(。有人有什么提示吗 没有缩放,看起来不错: 缩放时,它看起来很难看: 代码: canvas.scale(scalex, scaley); canvas.translate(itranslatex, itranslatey

有人对以下问题有什么提示或解释吗? 我使用位图着色器绘制路径。当画布未缩放时,它看起来很好(第一张图片)。 当我缩放到(放大)中时,bitmapshader不会被缩放,看起来非常难看。放大后,我尝试了几种方法来重新创建bitmapshader,但没有成功:-(。有人有什么提示吗

没有缩放,看起来不错:

缩放时,它看起来很难看:

代码:

    canvas.scale(scalex, scaley);
    canvas.translate(itranslatex, itranslatey);


    fillBMP = makePatternCross(fscalex, 1, Color.GREEN/*,fscalex,fscaley*/);
    fillBMPshader = new BitmapShader(fillBMP, BitmapShader.TileMode.REPEAT, BitmapShader.TileMode.REPEAT);
    paintshader = new Paint();
    paintshader.setShader(fillBMPshader);   


    canvas.drawPath(cpath.path, paintshader);



private static Bitmap makePatternCross(float fSize, float fStrokewith,int iColor) {
    Log.v("Create Patter makePatternCross","makePatternCross");

    float fBitmapSizeOrig = 10;
    fBitmapSizeOrig=fBitmapSizeOrig*fSize;
    Bitmap bm = Bitmap.createBitmap((int)fBitmapSizeOrig,(int) fBitmapSizeOrig,Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bm);
    //c.scale(200, 200);
    c.drawColor(Color.WHITE);
    Paint p = new Paint();
    p.setColor(iColor);
    //p.setStrokeWidth(iStrokewith);
    p.setStrokeWidth(fStrokewith/fSize);
    p.setStrokeWidth((float) 0.000001);
    c.drawLine(0, 0, fBitmapSizeOrig, fBitmapSizeOrig, p);
    c.drawLine(0, fBitmapSizeOrig, fBitmapSizeOrig, 0, p);

    if (fSize != 1) {
        int iNewSize = (int) (( fBitmapSizeOrig) * fSize);
        bm = Bitmap.createScaledBitmap(bm, iNewSize, iNewSize, false);
    }

    int width = bm.getWidth();
    int height = bm.getHeight();
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            if (bm.getPixel(x, y) == Color.WHITE) {
                bm.setPixel(x, y, Color.TRANSPARENT);
            } else {
                // bm.setPixel(x, y, bm.getPixel(x, y));
            }
        }
    }
    return bm;
}
canvas.scale(scalex,scaley);
canvas.translate(itranslatey,itranslatey);
fillBMP=makePatternCross(fscalex,1,Color.GREEN/*,fscalex,fscaley*/);
fillBMPshader=新的位图着色器(fillBMP,BitmapShader.TileMode.REPEAT,BitmapShader.TileMode.REPEAT);
paintshader=new Paint();
paintshader.setShader(fillBMPshader);
canvas.drawPath(cpath.path,paintshader);
私有静态位图makePatternCross(float-fSize、float-fStrokewith、int-iColor){
Log.v(“创建模式MakepatterCross”,“MakepatterCross”);
浮动fBitmapSizeOrig=10;
fBitmapSizeOrig=fBitmapSizeOrig*fSize;
位图bm=Bitmap.createBitmap((int)fBitmapSizeOrig,(int)fBitmapSizeOrig,Bitmap.Config.ARGB_8888);
画布c=新画布(bm);
//c、 比例(200200);
c、 drawColor(颜色:白色);
油漆p=新油漆();
p、 setColor(iColor);
//p、 设置行程宽度(iStrokewith);
p、 设置行程宽度(fStrokewith/fSize);
p、 设定行程宽度((浮动)0.000001);
c、 抽绳(0,0,fBitmapSizeOrig,fBitmapSizeOrig,p);
c、 抽绳(0,fBitmapSizeOrig,fBitmapSizeOrig,0,p);
如果(fSize!=1){
int-iNewSize=(int)((fBitmapSizeOrig)*fSize);
bm=Bitmap.createScaledBitmap(bm,iNewSize,iNewSize,false);
}
int width=bm.getWidth();
int height=bm.getHeight();
对于(int x=0;x
不确定这是否是您想要的。但是,如果使用矩阵缩放位图,它将保留比正常缩放更高的质量

Matrix matrix = new Matrix();
matrix.postScale(desiredScale, desiredScale);
Bitmap scaledBitmap = Bitmap.createBitmap(sampledSrcBitmap, 0, 0, sampledSrcBitmap.getWidth(), sampledSrcBitmap.getHeight(), matrix, true);
此外,当分辨率从较低变为较高时,您也可以尝试以下方法:

Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);

非常感谢你的帮助。但这不是解决办法。我尝试了不同的值,但仍然是一样的。我用一种新的方式解决了这个问题。我用路径来画我的图案,与我喜欢的区域相交。然后没有出现缩放问题。@ McFixPoT它已经旧了,但是如果你解决了,请考虑发布解决方案。