如何创建与图像,圆角的背景无国界无国界、图像、圆角、背景

2023-09-13 02:11:00 作者:小青春、无限坑

我想创建一个背景为我的LinearLayout有带圆角的图像。我见过很多例子如何做到这一点,但不是我想要的东西。在大多数案件我已经看到了使用填充人们创造它,但是当我做到这一点吸引了一种边界,而我不希望任何边界,只是圆角

 < XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目>
    <形状>
            <边角安卓topLeftRadius =20dp机器人:topRightRadius =20dp/>
    < /形状>
    < /项目>
     <项目>
        <位图机器人:SRC =@可绘制/头/>
    < /项目>
< /层列表>
 

解决方案

罗曼盖伊的形象与圆润的边角

使用自定义绘制对象的绘制()使用Canvas.drawRoundRect一个圆角矩形。诀窍是使用涂料用BitmapShader填补了圆角矩形纹理,而不是一个简单的色彩。

的http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/

样品可以下载@ https://docs.google。 COM /文件/ D / 0B3dxhm5xm1sia2NfM3VKTXNjUnc /编辑?PLI = 1

word中自选图形的圆角矩形怎么设置

下面是另一个链接

How作出的ImageView有圆角

另一个链接

http://ruibm.com/?p=184

 公共类ImageHelper {
公共静态位图getRoundedCornerBitmap(位图位图,诠释像素){
位图输出= Bitmap.createBitmap(bitmap.getWidth(),位图
        .getHeight(),Config.ARGB_8888);
帆布油画=新的Canvas(输出);

最终诠释色= 0xff424242;
最终的涂料粉刷=新的油漆();
最终矩形矩形=新的Rect(0,0,bitmap.getWidth(),bitmap.getHeight());
最后RectF rectF =新RectF(RECT);
最终浮动roundPx =像素;

paint.setAntiAlias​​(真正的);
canvas.drawARGB(0,0,0,0);
paint.setColor(颜色);
canvas.drawRoundRect(rectF,roundPx,roundPx,油漆);

paint.setXfermode(新PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(位图,矩形,矩形,油漆);

返回输出;
}
}
 

I'm trying to create a background for my LinearLayout that has an Image with rounded corners. I've seen many examples how to do that but not exactly what I want. In most of cases I've seen people using padding to create it, but when I do this it draws a kind of border, and I don't want any border, just the rounded corner

    <?xml version="1.0" encoding="UTF-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item >
    <shape>
            <corners android:topLeftRadius="20dp" android:topRightRadius="20dp"/>
    </shape> 
    </item>
     <item >
        <bitmap android:src="@drawable/header"/>
    </item>
</layer-list>

解决方案

Romain Guy's image with rounded corner

Use a custom Drawable that draws a rounded rectangle using Canvas.drawRoundRect(). The trick is to use a Paint with a BitmapShader to fill the rounded rectangle with a texture instead of a simple color.

http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/

The sample can be downloaded @ https://docs.google.com/file/d/0B3dxhm5xm1sia2NfM3VKTXNjUnc/edit?pli=1

Here's another link

How to make an ImageView to have rounded corners

Another link

http://ruibm.com/?p=184

public class ImageHelper {
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
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 = pixels;

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;
} 
}