2013-07-15 44 views
0

我想用Canvas.scale(2f,2f)放大我的位圖,但是當我這樣做時,圖像消失。Canvas.Scale,位圖消失

這裏是我的代碼:

int srcLeft = GodFrameWidth * GodCurAnimation; 
    int srcTop = 0; 
    int srcRight = (GodFrameWidth * GodCurAnimation) + GodFrameWidth; 
    int srcBottom = GodFrameHeight; 

    float destLeft = CanvasWidth/2 - GodFrameWidth; 
    float destTop = CanvasHeight/2; 
    float destRight = destLeft + GodFrameWidth; 
    float destBottom = destTop + GodFrameHeight; 

    RectF dst = new RectF(destLeft, destTop,destRight ,destBottom); 
    Rect src = new Rect(srcLeft,srcTop,srcRight,srcBottom); 
    canvas.save(); 
    canvas.scale(2f, 2f); 
    canvas.drawBitmap(GodMap, src, dst,Pencil); 
    canvas.restore(); 

,如果我不擴展它,它正好出現在屏幕上,在那裏我希望它是中間。

任何想法?

回答

0

我建議你,規模it.For例如之前翻譯你的畫布樞軸:

canvas.save(); 
canvas.translate(50, 50); 
canvas.scale(0.5f, 0.5f); 
canvas.drawRect(0.0, 0.0, 5.0, 5.0, paint); 
canvas.restore(); 

這將吸引長度爲5.0長方形,和寬度5.0,比例縮小到2.5的長度和寬度,然後將其移動到(50,50)。 Code reference