简体   繁体   English

背景图像圆角

[英]Background Image Rounded Corners

I am have a background image that changes and on top of it I am using rounded corners. 我有一个变化的背景图片,在它上面我使用了圆角。 Is there a way to hide the corners of the image. 有没有一种方法可以隐藏图像的角落。 Below is a screen shot of my widget with the corners showing. 下面是我的小部件的屏幕截图,显示了角落。 在此处输入图片说明

EDIT CODE: 编辑代码:

Bitmap bm1 = BitmapFactory.decodeResource(context.getResources(), Utilities.getDrawableId(ACCUWX.Icons.AL_WIDGETBG_ICON_MAP[Integer.parseInt(wdm.iconCode)]));
Bitmap roundedBm = Utilities.getRoundedCornerBitmap(bm1);
toRet.setImageViewBitmap(R.id.widget_bg, roundedBm);

method call: 方法调用:

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(rect);
        final float roundPx = 12;

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);

        return output;
      }

To show that I have a background image and rounded corners on top of it made from a drawable utilizing xml shape: 为了显示我有一个背景图像,并在其顶部由一个利用xml形状的drawable制成的圆角:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget_bg_rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="true">
    <ImageView
        android:id="@+id/widget_bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/al_widgetbg_06_07_08"
        android:scaleType="center" />

    <LinearLayout 
        android:id="@+id/current_layout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:weightSum="8">
        <RelativeLayout
            android:id="@+id/city_time_rl"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2.5"
            android:background="@drawable/rounded_corners_top"
            android:clipChildren="true">
            <TextView
                android:id="@+id/city" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="MECHANICSBURG"
                android:textSize="16dp"
                android:textColor="@color/dk_blue"
                />

您应该能够通过在透明的背景上绘制圆形矩形之前使背景透明来实现此目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM