IT/프로그래밍
안드로이드에서 이미지를 전체화면으로 늘려서 채우기
이금성
2015. 12. 25. 03:04
안드로이드에서 배경이미지 등을 넣을때 전체화면으로 사이즈를 조정하는 예제입니다.
가로, 세로 사이즈를 받아서 이미지를 해당 사이즈로 늘리는 방식을 사용하면 됩니다.
아래 샘플 예제를 참고하시기 바랍니다.
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 | package kr.cuenet.imageexample; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.view.View; public class ImageView extends View { Bitmap mBackgroundImage; public ImageView(Contextcontext) { super(context); mBackgroundImage = BitmapFactory.decodeResource(getResources(), R.mipmap.background, null); } @Override public void onDraw(Canvascanvas) { Rect dest = new Rect(0, 0, getWidth(),getHeight()); Paint paint = new Paint(); paint.setFilterBitmap(true); canvas.drawBitmap(mBackgroundImage, null, dest, paint); } } |