Android Glide识别图像是不是一个正圆

需求如果网络下载的图片是圆形就正常显示,不是的话做处理。

思路:Glide下载下来,获取宽高,拿到中心点,根据半径取像素点,判断是否相等,全部相等就是圆。下面是实现,精度一般,勉强能用。

Glide.with(mContext).load(item.getVedioPicture()).asBitmap().into(new SimpleTarget() {

@Override

    public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {

int width=resource.getWidth();

        int height=resource.getHeight();

        int r= (int) (height/1.9);//半径比真正半径大,预防图片不是一个非常正规的圆。

        Map map=new HashMap<>();

//看精度这是循环36次没十度一次

        for (int theta =0; theta <360; theta=theta+10) {

double t = (theta *3.14159265) /180; // 角度值0 ~ 2*PI

            int  x0 = (int) Math.round(width/2 - r * Math.cos(t));

            int y0 = (int) Math.round(height/2 - r * Math.sin(t));

//判断是否超出边界。

            if (x0 < width && x0 >0 && y0 < height && y0 >0) {

Log.e("呜呜呜亢","这是一个像素"+resource.getPixel(x0,y0));

                map.put(resource.getPixel(x0,y0),1);

            }

}

//根据map特性同样的key值只会才在一个判断是否小于2,小于2表示这个圆环上都是同样的像素

if(map.size()<2){

Log.e("啊啊啊啊","这是一个圆啊啊啊啊啊啊啊");

            ((ImageView)helper.getView(R.id.res_img)).setImageBitmap(resource);

        }else {

}

}

});

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容