Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android正在尝试绕过位图的角点_Android_Bitmap_Imageview - Fatal编程技术网

android正在尝试绕过位图的角点

android正在尝试绕过位图的角点,android,bitmap,imageview,Android,Bitmap,Imageview,我有一个imageView,我正在尝试创建圆角,尝试了这篇文章中的所有解决方案:但没有任何效果。。这是我的XML <RelativeLayout android:id="@+id/RL_ImageHolder" android:layout_width="150dp" android:layout_height="180dp" android:layout_alignBottom="@+id/relativeLayout2" android:

我有一个imageView,我正在尝试创建圆角,尝试了这篇文章中的所有解决方案:但没有任何效果。。这是我的XML

    <RelativeLayout
    android:id="@+id/RL_ImageHolder"
    android:layout_width="150dp"
    android:layout_height="180dp"
    android:layout_alignBottom="@+id/relativeLayout2"
    android:layout_alignParentLeft="true"
    android:layout_alignTop="@+id/relativeLayout2"
    android:layout_marginLeft="10dp" >

    <ImageView
        android:id="@+id/imgPreview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:contentDescription="Preview"

         />
</RelativeLayout>
图像设置正确,但保持矩形。。你知道为什么它不起作用吗


编辑:刚刚发现,仅当包含图像的布局具有固定的宽度/高度时,is才起作用。。我得想想怎么办。谢谢大家

尝试以下代码片段:

public static Bitmap GetCurveImage(Bitmap bitmap) {
        // Bitmap myCoolBitmap = ... ; // <-- Your bitmap you
        // want rounded
        int w = bitmap.getWidth(), h = bitmap.getHeight();

        // We have to make sure our rounded corners have an
        // alpha channel in most cases
        Bitmap rounder = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(rounder);

        // We're going to apply this paint eventually using a
        // porter-duff xfer mode.
        // This will allow us to only overwrite certain pixels.
        // RED is arbitrary. This
        // could be any color that was fully opaque (alpha =
        // 255)
        Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        xferPaint.setColor(Color.RED);

        // We're just reusing xferPaint to paint a normal
        // looking rounded box, the 20.f
        // is the amount we're rounding by.
        canvas.drawRoundRect(new RectF(0, 0, w, h), 5.0f, 5.0f, xferPaint);

        // Now we apply the 'magic sauce' to the paint
        xferPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

        Bitmap result = Bitmap.createBitmap(bitmap.getWidth(),
                bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas resultCanvas = new Canvas(result);
        resultCanvas.drawBitmap(bitmap, 0, 0, null);
        resultCanvas.drawBitmap(rounder, 0, 0, xferPaint);

        return result;
    } 
公共静态位图GetCurveImage(位图){

//Bitmap mycolbitmap=…;//检查:通过调用Canvas.drawRect()可以用更少的代码以更高效的方式实现并在画图上设置位图着色器。@Romanguy:是的,你说得对。很抱歉,我直到现在才意识到这一点。你的建议非常好而且直截了当。当我需要在我的项目中应用圆角图像时,我将应用你的代码。谢谢。:)
public static Bitmap GetCurveImage(Bitmap bitmap) {
        // Bitmap myCoolBitmap = ... ; // <-- Your bitmap you
        // want rounded
        int w = bitmap.getWidth(), h = bitmap.getHeight();

        // We have to make sure our rounded corners have an
        // alpha channel in most cases
        Bitmap rounder = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(rounder);

        // We're going to apply this paint eventually using a
        // porter-duff xfer mode.
        // This will allow us to only overwrite certain pixels.
        // RED is arbitrary. This
        // could be any color that was fully opaque (alpha =
        // 255)
        Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        xferPaint.setColor(Color.RED);

        // We're just reusing xferPaint to paint a normal
        // looking rounded box, the 20.f
        // is the amount we're rounding by.
        canvas.drawRoundRect(new RectF(0, 0, w, h), 5.0f, 5.0f, xferPaint);

        // Now we apply the 'magic sauce' to the paint
        xferPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

        Bitmap result = Bitmap.createBitmap(bitmap.getWidth(),
                bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas resultCanvas = new Canvas(result);
        resultCanvas.drawBitmap(bitmap, 0, 0, null);
        resultCanvas.drawBitmap(rounder, 0, 0, xferPaint);

        return result;
    }