달력

5

« 2024/5 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
728x90
반응형

안드로이드 - ImageView Round처리

원본출처:

http://blowmj.tistory.com/entry/Android-ImageView-Round%EC%B2%98%EB%A6%AC%ED%95%98%EA%B8%B0

getRoundedCornerBitmap 클래스로 해주면 됩니다.




public class ImageRound extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

ImageView img = (ImageView)findViewById(R.id.image);

Bitmap bm = BitmapFactory.decodeResource(getResources(),

R.drawable.icon);

img.setImageBitmap(getRoundedCornerBitmap(bm, 10));

}

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;

}

}

728x90
반응형
:
Posted by mapagilove