【发布时间】:2017-05-11 18:01:34
【问题描述】:
如何仅从右上和右下(右侧)舍入缩放 (CenterCrop) 的图像。
我发现那个类可以做类似的事情(TopRoundedImage,感谢作者),但对于左上角和右上角。我正在尝试更改它,但我想我仍然做错了。
另外,我正在使用 Glide 从 Internet 请求图像,然后我只想圆右侧。
我尝试使用背景可绘制对象,但它不起作用(我读它是因为规模)。
public class RightRoundedImageView extends AppCompatImageView
{
private final RectF roundRect = new RectF();
private float rect_radius = 7;
private final Paint maskPaint = new Paint();
private final Paint zonePaint = new Paint();
public RightRoundedImageView(Context context, AttributeSet attrs)
{
super(context, attrs);
init();
}
public RightRoundedImageView(Context context)
{
super(context);
init();
}
private void init()
{
maskPaint.setAntiAlias(true);
maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
zonePaint.setAntiAlias(true);
zonePaint.setColor(Color.WHITE);
float density = getResources().getDisplayMetrics().density;
rect_radius = rect_radius * density;
}
public void setRectAdius(float radius)
{
rect_radius = radius;
invalidate();
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
int w = getWidth();
int h = getHeight();
// roundRect.set(0, 0, w, h + rect_radius);//round top
roundRect.set(0, 0, w + rect_radius, h); //round left
// roundRect.set(0, 0, w - rect_radius, h); //round all
}
@Override
public void draw(Canvas canvas)
{
canvas.saveLayer(roundRect, zonePaint, Canvas.ALL_SAVE_FLAG);
canvas.drawRoundRect(roundRect, rect_radius, rect_radius, zonePaint);
canvas.saveLayer(roundRect, maskPaint, Canvas.ALL_SAVE_FLAG);
super.draw(canvas);
canvas.restore();
}
}
如果有人知道或可以提供帮助,将不胜感激。谢谢。
【问题讨论】:
-
您可以发布您正在寻找的示例图片吗?
-
@Lingeshwaran 请检查图片