首页 > 解决方案 > 如何在图像(位图)中找到形状的重心

问题描述

这是我的工作,我试图使用选定的图像坐标在图像(位图)中找到形状的重心:

float xpos = 0f , ypos = 0f;
PointF currF = new PointF();
for (PointF pointF : pointFArrayList){
     xpos += pointF.x;
     pos += pointF.y;
} 
currF.x = xpos/pointFArrayList.size();
currF.y = ypos/pointFArrayList.size();
addRoundIconToViewRed(currF); //Marking the center of gravity

作为示例,请参见此图像:

使用此图像查找 COG

标签: javaandroidimage

解决方案


1.首先将位图设置为图像视图

2.获取该特定图像视图的中心点

     centreX=imageView.getX() + imageView.getWidth()  / 2;
     centreY=imageView.getY() + imageView.getHeight() / 2;

推荐阅读