有人设法使用RoundedBitmapDrawable?如果我错了,请纠正我,但根据我的理解,它会从常规矩形图像中生成圆形图像.
到目前为止我尝试过的是这个
RoundedBitmapDrawable.createRoundedBitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), iconResource))
Run Code Online (Sandbox Code Playgroud)
我试图实现的目标:将任何图像转换为圆形图像并使用ImageView显示它.
如果我把事情搞混了,我所说的都是无意义的.是否可以(或更简单)使用任何新框架?(Android L或新的支持库)
我已经看到了如何创建一个可绘制这是圆了一个位图,以及如何添加一个大纲(AKA中风)周围,这里.
我无法找到如何在不绘制新位图的情况下仅对位图的某些角进行舍入,而不是创建新的位图,并且仍然可以用于中心裁剪ImageView.
这是我发现的,但它确实创建了一个新的位图,并且在带有center-crop的imageView中使用它时(源于此处):
/**
* Create rounded corner bitmap from original bitmap.
*
* @param input Original bitmap.
* @param cornerRadius Corner radius in pixel.
* @param squareTL,squareTR,squareBL,squareBR where to use square corners instead of rounded ones.
*/
public static Bitmap getRoundedCornerBitmap(final Bitmap input, final float cornerRadius, final int w, final int h,
final boolean squareTL, final boolean squareTR, final boolean squareBL, final boolean squareBR) {
final Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888); …Run Code Online (Sandbox Code Playgroud)