需求如果網(wǎng)絡(luò)下載的圖片是圓形就正常顯示,不是的話做處理。
思路:Glide下載下來,獲取寬高,拿到中心點(diǎn),根據(jù)半徑取像素點(diǎn),判斷是否相等,全部相等就是圓。下面是實(shí)現(xiàn),精度一般,勉強(qiáng)能用。
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);//半徑比真正半徑大,預(yù)防圖片不是一個(gè)非常正規(guī)的圓。
? ? ? ? Map map=new HashMap<>();
//看精度這是循環(huán)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("嗚嗚嗚亢","這是一個(gè)像素"+resource.getPixel(x0,y0));
? ? ? ? ? ? ? ? map.put(resource.getPixel(x0,y0),1);
? ? ? ? ? ? }
}
//根據(jù)map特性同樣的key值只會(huì)才在一個(gè)判斷是否小于2,小于2表示這個(gè)圓環(huán)上都是同樣的像素
if(map.size()<2){
Log.e("啊啊啊啊","這是一個(gè)圓啊啊啊啊啊啊啊");
? ? ? ? ? ? ((ImageView)helper.getView(R.id.res_img)).setImageBitmap(resource);
? ? ? ? }else {
}
}
});