This is my code. This question is somewhat related from this question: Trying to scale down a Bitmap in Android not working
I commented out the options.inSampleSize
and I still get the rotation (counter-clockwise 90 degrees seemingly). This seems like a fairly simple scaling down of an image, from Google documentation, and I'm not sure how I'm getting a rotated image.
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);
}
The byte[] is originally from Commonsware CWAC Camera library, and I've tried taking a look at: Android Reduce Size Of Camera Picture
UPDATE:
I have started pulling away more code to try to make it more apparent where this rotation could be coming from. I have it narrowed down to this. (This code still causes rotation)
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);
}