3

这是我的代码。这个问题与这个问题有些相关: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);

}
4

1 回答 1

0

这里的问题很可能是图像本身没有旋转,但是图像正在旋转显示,并且您的变换正在清除(或至少不继续)操作系统将用来显示它的元数据方向正确。您对此无能为力,因为操作系统不会将该数据放入图像本身

如果不是这种情况,那么您所拥有的是字节顺序问题。一种格式是从左到右为您提供数据,另一种是从上到下。您需要重新排序字节。

于 2014-01-10T16:58:18.460 回答