【发布时间】:2016-01-28 14:13:44
【问题描述】:
我有问题。我需要在图像上画一些圆圈,但我不知道为什么,它只画了一个圆圈。我把代码放在下面是为了更好地解释它:
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();
}
我在一些 ArrayList 上有我想要绘制的点的坐标,而且这个坐标是相对于图像的,所以我必须将图像宽度和图像高度的坐标相乘。
它只画了一个绿色圆圈,但我需要(在那次追逐中)画五个绿点和四个红点。
我也放了arraylist信息:
presasX = [49.583333333333,80.833333333333,13.541666666667,4.5833333333333,77.708333333333,49.583333333333,4.5833333333333,95.208333333333,96.875] P>
presasY = [49.722222222222, 5, 22.5, 20.277777777778, 33.888888888889, 49.722222222222, 20.277777777778, 54.7222222226666666]
颜色 = [2, 2, 2, 2, 2, 1, 1, 1, 1]
非常感谢!
【问题讨论】:
-
Float.parseFloat(presasX.get(i)) * myImage.getWidth()- 鉴于presasX.get(0) == 49.583333333333,这将是一个非常大的数字,超出了图像的范围。 -
我除以 100,但结果相同。有什么想法吗?
标签: java android canvas bitmap imageview