骚操作

1、通过wifi链接调试手机 ( 手机wifi与电脑是同一个网段)

adb devices

adb tcpip 8888 ( 输入可以是任意的 默认是 5555)

adb connect ip:8888

2、旋转Bitmap

Matrix matrix = new Matrix();
matrix.postRotate(degree);//degree 为旋转角度
Bitmap bitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(),
sourceBitmap.getHeight(), matrix, true);//sourceBitmap 是需要处理的原Bitmap

3、系统截图

SurfaceControl类中

screenshot方法有几个重载方法

1)其中一个带了旋转角度的,旋转角度通过Display的角度拿到

mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
mDisplay = mWindowManager.getDefaultDisplay();
mOrientation = mDisplay.getRotation();
switch (mOrientation) {
    case 0:
        mShotOrientation = Surface.ROTATION_0;
        break;
    case 1:
        mShotOrientation = Surface.ROTATION_90;
        break;
    case 2:
        mShotOrientation = Surface.ROTATION_180;
        break;
    case 3:
        mShotOrientation = Surface.ROTATION_270;
        break;
    default:
        mShotOrientation = Surface.ROTATION_0;
        break;
}
public static Bitmap screenshot(Rect sourceCrop, int width, int height,
            int minLayer, int maxLayer, boolean useIdentityTransform,
            int rotation) {
        // TODO: should take the display as a parameter
        IBinder displayToken = SurfaceControl.getBuiltInDisplay(
                SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN);
        return nativeScreenshot(displayToken, sourceCrop, width, height,
                minLayer, maxLayer, false, useIdentityTransform, rotation);
    }

2) 还有一种直接根据屏幕宽高进行截屏的

screenshot(int width, int height)

4、系统相册带角度后,将Bitmap放入ImageView会有角度的旋转

处理方法

private Bitmap doOrientationAdjust(String bitPath, Bitmap sourceBitmap) {
        Bitmap bitmap;
        ExifInterface exif = null;
        try {
            exif = new ExifInterface(bitPath);
        } catch (IOException e) {
            e.printStackTrace();
        }
        int degree = 0;
        if (exif != null) {
            int ori = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_UNDEFINED);
            switch (ori) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    degree = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    degree = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    degree = 270;
                    break;
                default:
                    degree = 0;
                    break;
            }
        }
        if (degree != 0) {
            Matrix matrix = new Matrix();
            matrix.postRotate(degree);
            bitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(),
                    sourceBitmap.getHeight(), matrix, true);

        } else {
            bitmap = sourceBitmap;
        }
        return bitmap;
    }

results for ""

    No results matching ""