首页 > 其他分享 >androidImageView

androidImageView

时间:2022-12-14 23:55:58浏览次数:37  
标签:int bitmap androidImageView ImageView drawable Bitmap Config

// 1.从资源中获取Bitmap
ImageView mImageView1 = (ImageView) findViewById(R.id.img_1);
DrawableUtils.UseBitmap(this, mImageView1, R.drawable.gril);

 


// 1.从资源中获取Bitmap
public static void UseBitmap(Context context, ImageView imageView, int drawableId) {

Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
drawableId);
imageView.setImageBitmap(bitmap);

}

// 5. Drawable----> Bitmap
public static Bitmap DrawableToBitmap(Drawable drawable) {

// 获取 drawable 长宽
int width = drawable.getIntrinsicWidth();
int heigh = drawable.getIntrinsicHeight();

drawable.setBounds(0, 0, width, heigh);

// 获取drawable的颜色格式
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
// 创建bitmap
Bitmap bitmap = Bitmap.createBitmap(width, heigh, config);
// 创建bitmap画布
Canvas canvas = new Canvas(bitmap);
// 将drawable 内容画到画布中
drawable.draw(canvas);
return bitmap;
}

 

 

        // 3. 圆角图片
        ImageView mImageView3 = (ImageView) findViewById(R.id.img_3);
        mImageView3.setImageBitmap(DrawableUtils.SetRoundCornerBitmap(
                DrawableUtils.DrawableToBitmap(getResources().getDrawable(
                        R.drawable.img1)), 60));

  

 

标签:int,bitmap,androidImageView,ImageView,drawable,Bitmap,Config
From: https://www.cnblogs.com/xiamaocheng/p/16983988.html

相关文章