본문 바로가기
728x90

bitmap3

[android studio] 배경화면 이미지용량으로 인한 에러 이미지 크기나 용량이 너무 큰 배경화면 그림을 쓰다보니 처음에는 단순하게 생각해서 android:background= 식으로 썼더니 Error inflating class 에러가 나왔다. 그래서 이미지를 화면 크기에 맞춰서 수정을 하여 넣을 수 있도록 코드상에서 아래처럼 처리를 하였다. //화면크기를 구하기 Display display = getActivity().getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getRealSize(size); int width = size.x; int height = size.y; //배경이미지를 넣을 layout LinearLayout layout = (LinearLayout)root.. 2021. 10. 29.
[android studio] image 회전시키기, bitmap 이미지 회전 아래 메서드를 이용하여 이미지를 회전 시킬 수 있다. // 이미지 회전 함수 public Bitmap rotateImage(Bitmap src, float degree) { // Matrix 객체 생성 Matrix matrix = new Matrix(); // 회전 각도 셋팅 matrix.postRotate(degree); // 이미지와 Matrix 를 셋팅해서 Bitmap 객체 생성 return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); } drawable을 bitmap으로 변환시킨 뒤 회전처리를 할 수도 있고, imageView의 이미지를 아래와 같이 BitmapDrawable로 변환시킨 뒤 bitmap.. 2021. 10. 24.
[android studio] Drawable을 Bitmap으로, Bitmap을 Drawable로 변경하기 Drawable을 Bitmap으로 변경 Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.[drawable명칭]); 또는, Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap(); Bitmap을 Drawable로 변경 Drawable drawable = new BitmapDrawable(bitmap); Drawable을 Bitmap으로 변경한 뒤 canvas에 넣거나 수정할 경우 [Immutable bitmap passed to Canvas constructor]라는 예외 error가 발생하는 경우가 있다. 이런경우, 아래와 같이 bitmap을 복사한 뒤 사용하면 error를 피해갈 수.. 2021. 10. 24.
728x90