. 비트 맵을 사용하여 배경 화면을 설정하는 과정에서 큰 어려움을 겪었습니다. 나는 그 해답을 알아 내려고 노력했다.
내가- 피하기 작물
- scaleType처럼 벽지에 비트 맵을 설정하려는
: fit_center (수직 중심을 정렬, 원래 비트 맵의 비율을 유지)
는
내가 그것을 어떻게
. 비트 맵을 사용하여 배경 화면을 설정하는 과정에서 큰 어려움을 겪었습니다. 나는 그 해답을 알아 내려고 노력했다.
내가: fit_center (수직 중심을 정렬, 원래 비트 맵의 비율을 유지)
내가 그것을 어떻게
화면 크기에 따라 새 비트 맵을 만들려면 그림의 크기를 조정해야합니다.
여기에 코드입니다 :
Bitmap bitmapOrg = BitmapFactory.decodeFile(getApplicationContext()
.getFilesDir().toString() + "/images/" + imagename);
Log.e("imageheight", "" + bitmapOrg.getHeight());
Log.e("imagewidth", "" + bitmapOrg.getWidth());
double imageheight = bitmapOrg.getHeight();
double imagewidth = bitmapOrg.getWidth();
DisplayMetrics metrics = getApplicationContext().getResources()
.getDisplayMetrics();
double screenwidth = metrics.widthPixels;
double sreeenheight = metrics.heightPixels;
Log.e("screennwidth", "" + screenwidth);
double newratio = screenwidth/imagewidth;
Log.e("newratio", "" + newratio);
double newratio1 = newratio * imageheight;
double newratio2 = newratio * (imagewidth - 10); // 10 margin in width
Log.e("newratio1", "" + newratio1);
int mainheight = (int) newratio1;
// int mainweidth = (int) imagewidth;
int mainweidth = (int) newratio2;
Log.e("Mainheight", "" + mainheight);
Log.e("Mainweidtht", "" + mainweidth);
// Here you will get the scaled bitmap
Bitmap new_ScaledBitmap = Bitmap.createScaledBitmap(bitmapOrg, mainweidth,mainheight, true);
// Use this bitmap as wallpaper
음 .. 감사합니다 너무 많은 답변을하지만,이 코드는 작동하지 않습니다 .... – HoJunLee
은 먼저 가로 세로 비율이 화면이있다거나 작은 것보다 큰 경우 결정해야, 아무것도를 절단하지 않고 화면에 비트 맵을 맞추려면. 이미지 종횡비가 화면 종횡비보다 크면 문제의 두 번째 이미지처럼 비트 맵이 화면보다 높거나 넓지 않음을 의미합니다. 그래서 당신은 같은 높이에 따라 이미지 크기를 조정해야합니다
이미지의 크기를 조절할 같은 폭을 기반으로해야합니다 그렇지if(imageWidth/imageHeight > screenWidth/screenHeight){
scaleFactor = screenHeight/imageHeight;
imageXPosition = screenWidth/2-imageWidth/2;
imageYPosition = 0;
: 당신은 사용하여 비트 맵을 그릴이 값을 사용할 수 있습니다
}else{
scaleFactor = screenWidth/imageHeight;
imageXPosition = 0;
imageYPosition = screenWidth/2-imageWidth/2;
}
Matrix 또는 imageWidth*scaleFactor
및 imageHeight*scaleFactor
크기의 비트 맵을 만들고 imageXPosition
| imageYPosition
(이 더 많은 메모리 절약입니다.
그래서 당신은 전체 화면을 채우기 위해 비트 맵을 원하거나 @Gumbo은 위의 이미지처럼자를 수하지? – Gumbo
위의 이미지에서처럼 잘려서하지 않습니다! – HoJunLee