Closed jzafrilla closed 9 years ago
Hi jzafrilla, i found one very simple way to fix this (API 8+). Thanks to this article on stackoverflow : http://stackoverflow.com/questions/6908604/android-crop-center-of-bitmap
In CircularImaveView.java, around L80, just use ThumbnailUtils.extractThumbnail with canvasSize.
canvasSize = canvas.getWidth();
if(canvas.getHeight()<canvasSize) canvasSize = canvas.getHeight();
BitmapShader shader = new BitmapShader(Bitmap.createScaledBitmap(ThumbnailUtils.extractThumbnail(image, canvasSize, canvasSize), canvasSize, canvasSize, false), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(shader);
Thanks for your response R3n4rD, it works perfect!!, final solution
if (image != null) {
int canvasSize = canvas.getWidth();
if(canvas.getHeight()<canvasSize){
canvasSize = canvas.getHeight();
}
BitmapShader shader = new BitmapShader(Bitmap.createScaledBitmap(
ThumbnailUtils.extractThumbnail(image, canvasSize,
canvasSize), canvasSize, canvasSize, false),
Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(shader);
//shader = new BitmapShader(Bitmap.createScaledBitmap(image, canvas.getWidth(), canvas.getHeight(), false), 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 - 4.0f, paintBorder);
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter - 4.0f, paint);
}
Thank you for your contributions guys. I add your update :)
If you use this library with images 4:3 / 16:9 / 9:16 / it doesn't respect de aspect ratio. If you use 1:1 images, works perfectly