如何在弧形顶部绘制位图图像

时间:2017-10-31 05:18:33

标签: java android canvas android-canvas

我想在每个画布弧中的顶部绘制图像

 private void drawImage(Canvas canvas, float tempAngle, Bitmap bitmap,String mValue) {
    //get every arc img width and angle
    int imgWidth = (radius / mWheelItems.size());
    //int imgWidth = (radius / 3);
    float angle = (float) ((tempAngle + 360 / mWheelItems.size() /2) * Math.PI / 180);
    //calculate x and y
    int x = (int) (center + radius / 2 / 2 * Math.cos(angle));
    int y = (int) (center + radius / 2 / 2 * Math.sin(angle));

    int top=y - imgWidth/2;
    int bottom=y +imgWidth/2;

    int left=x - imgWidth /2;
    int right=x + imgWidth / 2;

        Rect rect = new Rect(left, top, right, bottom);

                final Rect rect1 = new Rect(x - imgWidth /2 , y - imgWidth / 2  , bitmap.getWidth() , bitmap.getHeight());

   canvas.drawBitmap(bitmap, null, rect, null);
}

根据物品的大小制作弧

结果显示为

enter image description here

但是我希望顶部显示的图像位图与rect一样。红色也想要大尺寸的图像或位图

enter image description here

1 个答案:

答案 0 :(得分:0)

由特定标签和大屏幕平板电脑解决

根据角度

更改X和Y坐标
if(tempAngle==0) {
        x = x + 50;
    }

    if(tempAngle==60) {
        y = y + 50;
    }
    if(tempAngle==120) {

        imgWidth = imgWidth-12;
        y = y + 20;
        x = x - 40;
    }
    if(tempAngle==180) {
        imgWidth = imgWidth+12;
        x = x - 50;
    }
    if(tempAngle==240) {
        y = y - 50;
    }
    if(tempAngle==300) {
        y = y - 20;
        x = x + 40;
    }