최근 ImageView에서 색상 테두리가있는 이미지를 순환시키는 CircularImageView 클래스를 만들기 위해 확장했습니다. 이렇게 전달 된 캔버스에 그려서 된 onDraw (캔버스) 방법을 통해 수행된다 : 그릴 수 또는 비트 맵 이미지로 설정시Picasso 이미지 다운로드 라이브러리와 호환되지 않는 사용자 정의 ImageView 클래스
//load the bitmap
loadBitmap();
// init shader
if(image !=null)
{
shader = new BitmapShader(Bitmap.createScaledBitmap(image, viewWidth + (borderWidth * 2), viewHeight + (borderWidth * 2), true), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(shader);
int circleCenter = viewWidth/2;
// circleCenter is the x or y of the view's center
// radius is the radius in pixels of the cirle to be drawn
// paint contains the shader that will texture the shape
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter + borderWidth, paintBorder);
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter, paintBackground);
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter, paint);
}
그래서이 비트는 작동한다. 또한 Google의 Volley NetworkImageView에서도 사용할 수 있도록 확장했습니다.
Volley의 대안으로 피카소 이미지 다운로드 라이브러리와 함께 CircularImageView 클래스를 사용해 보았을 때 내 문제가 발생했습니다. BitmapDrawable을 가져올 때 첫 행의 loadBitmap() 함수에서 ClassCastException이 발생합니다.
private void loadBitmap()
{
BitmapDrawable bitmapDrawable = (BitmapDrawable) this.getDrawable();
if(bitmapDrawable != null)
image = bitmapDrawable.getBitmap();
}
처음에는 Picasso가 그림을 다운로드하기 전에 자리 표시 자 이미지를 반올림했습니다. 그러나 Picasso에서 이미지를 다운로드하자 마자 ClassCastException이 발생하고 BitmapDrawable이 아닌 getDrawable()이 반환되고 PicassoDrawable이 반환됩니다.
나는 CircularImageView 클래스의 onDraw (canvas) 메소드에서 이미지를 반올림하기를 계속하고 싶다. 피카소로 ImageView를 설정할 때마다 프로세스를 수행하는 것과는 정반대로 자동적으로 포함된다. . 이것이 가능한가?
미리 감사드립니다. 피카소와 함께이 일을 할 때
이렇게하면 매번 새로운 비트 맵이 만들어집니다. – secureboot
DesertIvy, droidx 및 Jake Wharton에게 도움을 주셔서 감사합니다. 이 프로젝트는 보류 상태 였고 이제는 문제가 다시 돌아 왔습니다. 나는 방금 완벽한 작품으로 위를 시도했다. –