0
사용자가 사진을 찍을 수있는 맞춤형 카메라 활동을 빌드했습니다. 사진은 사진 콜백을 통해 외부 저장 장치 디렉토리에 저장됩니다. 그런 다음 사용자는 그림을 미리 볼 수있는 다른 활동으로 리디렉션됩니다. 미리보기가 표시되기 전에 그림이 별도의 스레드에서 특정 최대 크기로 축소됩니다. 여기Android Desire HD 비트 맵 스케일링
byte[] tempStorage = new byte[16 * 1024];
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imagePath, options);
int oldWidth = options.outWidth;
int oldHeight = options.outHeight;
if (oldWidth > MAX_DIM || oldHeight > MAX_DIM) {
Logger.i(Constants.SCALE_TAG, "Must scale picture");
int scaleFactor = getScaleFactor(oldWidth, oldHeight);
options.inJustDecodeBounds = false;
options.inSampleSize = scaleFactor;
options.inTempStorage = tempStorage;
System.gc();
newB = BitmapFactory.decodeFile(imagePath, options);
} else {
Logger.i(Constants.SCALE_TAG, "No need for scaling");
// We do not need to scale the picture, it is small
// enough.
System.gc();
options.inJustDecodeBounds = false;
options.inTempStorage = tempStorage;
if (!stop) {
newB = BitmapFactory.decodeFile(imagePath, options);
} else {
return;
}
}
배율 인수를 계산하는 코드는 다음과 같습니다 : 여기 스케일링 코드는
private int getScaleFactor(int oldWidth, int oldHeight) {
// Holds the raw scale factor.
float rawScale;
// Get the scaling factor.
if (oldWidth >= oldHeight) {
rawScale = 1.0F/((MAX_DIM * 1.0F)/(oldWidth * 1.0F));
} else {
rawScale = 1.0F/((MAX_DIM * 1.0F)/(oldHeight * 1.0F));
}
Logger.i(Constants.SCALE_TAG, "Raw scale factor: " + rawScale);
return Math.round(rawScale);
}
이 코드는 대부분의 장치에서 잘 작동하지만 어떻게 든 디자 이어 HD 올바르게 사진을 확장하지 않습니다 . 원래 사진을 찍어서 30 배 정도 복제하고 비트 맵으로 스퀴즈하여 이상한 줄무늬 같은 그림을 만든 것처럼 보입니다. 누구든지이 문제를 알고 있습니까?