开发者

how to align center a bitmap inside a canvas in android?

i have a bitmap on canvas.i need to align bitmap to centre of canvas(centre of the image should be in centre of canvas.in my requirement,there should not give fixed points to align bitmap).while portrait view how to scale canvas and image appropriate to resolution?

    public void onDraw(Canvas canvas) {
    Bitmap imgtable = BitmapFactory.decodeRe开发者_如何转开发source(getResources(), R.drawable.table_01);
    canvas.drawColor(Color.TRANSPARENT);
    canvas.drawBitmap(imgtable, 10, 10, null);

    }


While i do not know the specific methods of getting the canvas width and bitmap width in Android, to place an bitmap at the center usually goes something like this.

centreX = (canvasWidth  - bitmapWidth) /2

centreY = (canvasHeight - bitmapHeight) /2

Then place your image at centreX,centreY

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜