如何将Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo); Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(circleBitmap); Paint paint = new Paint(); paint.setAntiAlias(true); canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, 0, 0, paint); canvas.drawBitmap(circleBitmap, 0, 0, null);返回的bitmap对象放入imageview
时间: 2023-06-03 19:06:15 浏览: 179
中显示?
答:你可以使用以下代码将bitmap对象放入ImageView中显示:
```java
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(circleBitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, 0, 0, paint);
canvas.drawBitmap(circleBitmap, 0, 0, null);
ImageView imageView = findViewById(R.id.imageView);
imageView.setImageBitmap(circleBitmap);
```
阅读全文