国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

android之設置圓角圖片的方法

2020-02-21 17:33:47
字體:
來源:轉載
供稿:網友
在開發過程中,我們需要將圖像顯示為圓角,我們可以在XML中設置可繪制的形狀,但是今天武林技術頻道小編給大家簡單介紹android之設置圓角圖片的方法,一起進入下文學習一下吧!
復制代碼 代碼如下:


android:id="@+id/layout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>


package com.test.demo;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MyActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Drawable drawable = getResources().getDrawable(R.drawable.bg);
// BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
// Bitmap bitmap = bitmapDrawable.getBitmap();

LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
Drawable drawable = getResources().getDrawable(R.drawable.bg);
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable.getBitmap();

BitmapDrawable bbb = new BitmapDrawable(toRoundCorner(bitmap, 30));
layout.setBackgroundDrawable(bbb);
//ImageView imageView = (ImageView) findViewById(R.id.imgShow);
//imageView.setImageBitmap(MyActivity.getRoundedCornerBitmap(bitmap));
//imageView.setImageBitmap(MyActivity.toRoundCorner(bitmap, 20));
}
public static Bitmap toRoundCorner(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;
}
}
上文是武林技術頻道小編為大家搜集到的相關介紹,希望對你了解android之設置圓角圖片的方法有所幫助!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 明星| 韩城市| 广东省| 余江县| 灵宝市| 威信县| 岳阳市| 和平县| 甘泉县| 江口县| 兴城市| 稷山县| 思茅市| 新竹市| 鄂托克旗| 鹤峰县| 沙雅县| 五大连池市| 夹江县| 米林县| 大邑县| 景泰县| 专栏| 凤台县| 襄垣县| 克拉玛依市| 无棣县| 抚顺市| 大埔县| 大城县| 宁蒗| 浙江省| 普格县| 新绛县| 宜宾市| 宁化县| 城步| 大姚县| 南宫市| 临沂市| 基隆市|