最近、ImageViewから拡張してCircularImageViewクラスを作成しました。これは、渡されたキャンバスに描くことにより、onDraw(キャンバス)メソッドを介して行われます:描画可能ビットマップを介して画像を設定する際カスタム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でも使用できるようにしました。
私の問題は、ピカソ画像のダウンロードライブラリと一緒にCircularImageViewクラスを試してみると、私はVolleyの代わりにそれを見ています。何が起こるかは、BitmapDrawableを取得するときの最初の行のloadBitmap()関数のClassCastExceptionです。
private void loadBitmap()
{
BitmapDrawable bitmapDrawable = (BitmapDrawable) this.getDrawable();
if(bitmapDrawable != null)
image = bitmapDrawable.getBitmap();
}
ピカソが画像をダウンロードする前に、最初にプレースホルダ画像を丸めます。しかしPicassoによって画像がダウンロードされるとすぐに、BitmapDrawableではなくgetDrawable()が返すようにClassCastExceptionが発生し、PicassoDrawableが失敗します。
CircularImageViewクラスのonDraw(canvas)メソッドのイメージを丸くする作業をしたいのですが、ImageViewをピカソでImageViewを設定する際に、 。これは可能ですか?
ありがとうございます。
これにより、毎回新しいビットマップが作成されます。 – secureboot
DesertIvy、droidx、Jake Whartonに感謝します。これが目的だったプロジェクトは保留になり、問題に直ちに戻ります。私はちょうど完璧な作品で上記を試した。 –