크기가 854 x 480 (내 테스트 전화의 정확한 화면 해상도) 인 백그라운드 리소스가 있습니다. 이 리소스를 내 앱에로드하면 비례 배분됩니다. 나는 여기를 탐색하여 몇 가지 제안을 시도했지만, 어떤 미친 이유 때문에 적절한 크기로 확장되지 않습니다.안드로이드 비트 맵 스케일링이 잘못되었습니다.
리소스가 화면 크기와 동일하므로 배경 리소스의 크기가 왜 증가하는지 잘 모르겠습니다. 1281 x 720까지 크기가 조정되며 이유는 알 수 없습니다.
변환이 일어나는 코드는 다음과 같습니다 당신은 스케일링의 여러 버전을 알 수 있습니다
public Sprite newSpriteLargeResource(Resources res, SpriteFormat format,
int resId, int reqWidth, int reqHeight) {
Options options = new Options();
options.inJustDecodeBounds = true;
Bitmap bitmap = null;
options.inSampleSize = calculateSample(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeResource(res, resId, options);
Matrix m = new Matrix();
RectF inRect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
RectF outRect = new RectF(0, 0, reqWidth, reqHeight);
boolean scaled;
scaled = m.setRectToRect(inRect, outRect, Matrix.ScaleToFit.CENTER);
if (scaled) {
float[] bmpValues = new float[9];
m.getValues(bmpValues);
Bitmap.createScaledBitmap(bitmap,
(int) ((bitmap.getWidth() * bmpValues[0])),
(int) ((bitmap.getHeight() * bmpValues[4])), true);
}else{
Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true);
}
return new AndroidSprite(bitmap, format);
}
private int calculateSample(Options options, int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int heightRatio = Math.round((float) height
/(float) reqHeight);
final int widthRatio = Math.round((float) width/(float) reqWidth);
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
. 이처럼 코드를 유지하는 유일한 이유는 내가 여러 버전의 배율을 시도했음을 보여주고 그 중 모두가 내가 원하는 것처럼 작동하지 않았 음을 보여주는 것입니다. 배경이 아닌 리소스에 대한 또 다른 방법이 있고 문제없이 작동하므로이 두 가지 방법의 어느 부분에 문제가 있다는 것을 알고 있습니다. 이 파일을 사용하는 유일한 이유는 Out of Memory 예외를 피하기 위해 더 큰 이미지 파일을 사용하기 위해서입니다.
nice를 참조하십시오. drawable-nodpi에 넣으면 예상대로 작동합니다. 다시 한 번 감사드립니다! –