我需要在安卓中创建一个四舍五入的ImageView。现在我使用Canvas.clipPath(),但它不支持硬件加速。当然,我在这个视图中使用了View.LAYER_TYPE_SOFTWARE。
public class RoundedCornerImageView extends MaptrixImageView
{
private final Path clipPath = new Path();
public RoundedCornerImageView(Context context)
{
this(context, null);
}
@SuppressLint("NewApi")
public RoundedCornerImageView(Context context, AttributeSet attrs)
{
super(context, attrs);
if (Build.VERSION.SDK_INT >= 11) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
@Override
protected void onDraw(Canvas canvas)
{
float radius = ((float) getWidth()) / 2;
clipPath.reset();
clipPath.addCircle(radius, radius, radius, Path.Direction.CW);
canvas.clipPath(clipPath);
super.onDraw(canvas);
}
}但是我想在这个视图中使用硬件加速。我可以为此ImageView使用XferMode类吗
发布于 2013-04-04 17:42:54
XferMode使用硬件加速。但是它有一些限制:http://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
然而,如果你仍然想使用clipPath,你将无法使用硬件加速。
https://stackoverflow.com/questions/15200931
复制相似问题