Java 我能';t在一幅图像上画一个以上的圆

Java 我能';t在一幅图像上画一个以上的圆,java,android,canvas,bitmap,imageview,Java,Android,Canvas,Bitmap,Imageview,我有个问题。我需要在图像上画一些圆,但我不知道为什么,它只画了一个圆。为了更好地解释,我将代码放在下面: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.previsualizacion); myImage = (ImageView) findViewById(R.id.imageView

我有个问题。我需要在图像上画一些圆,但我不知道为什么,它只画了一个圆。为了更好地解释,我将代码放在下面:

protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.previsualizacion);



    myImage = (ImageView) findViewById(R.id.imageView1);

    ctx = getApplicationContext();

    //Obtenemos la información del layout anterior y la asignamos al tamaño del paso
    data = getIntent();
    myBundle = data.getExtras();    

    presasX = myBundle.getStringArrayList("arrayPixelX");
    presasY = myBundle.getStringArrayList("arrayPixelY");
    colores = myBundle.getStringArrayList("arrayColores");      

    Bitmap bitMap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);  
    bitMap = bitMap.copy(bitMap.getConfig(), true);     
    Canvas canvas = new Canvas(bitMap);                 

    Paint paint = new Paint();                          
    paint.setColor(Color.RED);
    paint.setStyle(Style.FILL_AND_STROKE);
    //paint.setStrokeWidth(0.5f);
    paint.setAntiAlias(true);      

    myImage.setImageBitmap(bitMap);
    //changed set image resource to set image background resource
    myImage.setBackgroundResource(R.drawable.pared);

    for(int i = 0; i < presasX.size(); i++)
    {
        if(colores.get(i).equals("1"))
        {
            paint.setColor(Color.GREEN);    
        }
        else if(colores.get(i).equals("2"))
        {
            paint.setColor(Color.RED);  
        }
        else if(colores.get(i).equals("3"))
        {
            paint.setColor(Color.YELLOW);   
        }
        canvas.drawCircle(Float.parseFloat(presasX.get(i)) * myImage.getWidth() / 100, Float.parseFloat(presasY.get(i)) * myImage.getHeight() / 100, 3, paint);
    }

  //invalidate to update bitmap in imageview
    myImage.invalidate();
}
创建时受保护的void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.previsualizacion);
myImage=(ImageView)findViewById(R.id.imageView1);
ctx=getApplicationContext();
//前布局信息和阿西纳莫斯·塔马尼奥·德尔·帕索信息
data=getIntent();
myBundle=data.getExtras();
presasX=myBundle.getStringArrayList(“arrayPixelX”);
presasY=myBundle.getStringArrayList(“arrayPixelY”);
colors=myBundle.getStringArrayList(“ArrayColor”);
位图Bitmap=Bitmap.createBitmap(100100,Bitmap.Config.ARGB_8888);
bitMap=bitMap.copy(bitMap.getConfig(),true);
画布=新画布(位图);
油漆=新油漆();
油漆。设置颜色(颜色。红色);
绘制设置样式(样式填充和笔划);
//油漆。设置行程宽度(0.5f);
paint.setAntiAlias(真);
设置图像位图(位图);
//将设置图像资源更改为设置图像背景资源
myImage.setBackgroundResource(R.drawable.pared);
对于(int i=0;i
我在一些数组列表上列出了我想画的点的坐标,而且这个坐标是相对于一个图像的,所以我必须将这个坐标乘以ImageWidt和imageheight

它只画了一个绿色的圆圈,但我需要画五个绿色的点和四个红色的点

我也放了arraylist信息:

presasX=[49.583333,80.833333,13.5416666667,4.5833333,77.708333333,49.583333,4.5833333,95.208333333,96.875]

PREASY=[49.7222222,5,22.5,20.27777778,33.8888888889,49.722222222,20.2777777778,54.7222222,61.6666667]

颜色=[2,2,2,2,2,1,1,1,1]


非常感谢

这是因为布局尚未完全膨胀,因此myImage.getWidth()和getHeight()返回0。因此,实际上所有圆的中心都是相同的(ImageView的左上角),下一个圆将覆盖上一个圆


对于实际宽度和高度,您可以使用ViewTreeObserver.addOnGlobalLayoutListener,或者以编程方式创建具有所需尺寸的ImageView,或者创建扩展标准ImageView的自定义视图,并实现其()等。

Float.parseFloat(presasX.get(i))*myImage.getWidth()
-假设
presasX.get(0)==49.583333
,这将是一个非常大的数字,超出图像的边界。我除以100,但它的作用相同。知道吗?看看这个