这是我的代码。这个问题与这个问题有些相关:Trying to scale down a Bitmap in Android not working
我注释掉了options.inSampleSize
,我仍然得到旋转(看似逆时针90度)。从谷歌文档来看,这似乎是一个相当简单的图像缩小,我不确定我是如何获得旋转图像的。
Bitmap myBitmap = null;
@Override
protected byte[] doInBackground(Object... params) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
//myImageByteArray is 4016 wide
myBitmap = BitmapFactory.decodeByteArray(myImageByteArray, 0, myImageByteArray.length, options);
if (options.outHeight > options.outWidth) {
//options.inSampleSize = calculateInSampleSize(options, 640, 960);
} else {
//options.inSampleSize = calculateInSampleSize(options, 960, 640);
}
options.inJustDecodeBounds = false;
//myImageByteArray is 4016 wide
myBitmap = BitmapFactory.decodeByteArray(myImageByteArray, 0, myImageByteArray.length, options);
//This log statement outputs around 1000 now.
Log.d("bitmap", myBitmap.getWidth()+"");
ByteArrayOutputStream bAOS = new ByteArrayOutputStream();
myBitmap.compress(CompressFormat.JPEG, 50, bAOS);
}
byte[] 最初来自Commonsware CWAC Camera library,我试过看看:Android Reduce Size Of Camera Picture
更新:
我已经开始删除更多的代码,试图让这个轮换的来源更加明显。我把它缩小到这个。(此代码仍然会导致旋转)
Bitmap myBitmap = null;
@Override
protected byte[] doInBackground(Object... params) {
final BitmapFactory.Options options = new BitmapFactory.Options();
myBitmap = BitmapFactory.decodeByteArray(myImageByteArray, 0, myImageByteArray.length, options);
ByteArrayOutputStream bAOS = new ByteArrayOutputStream();
myBitmap.compress(CompressFormat.JPEG, 50, bAOS);
}