0

このリンクを使用: Android での画像の傾き補正

傾きの程度に応じて画像を十分にズームすることに成功しました。しかし、アスペクト比を 1:1 に保ちながら画像を回転させたいと思います。出来ますか?更新された Instagram アプリは、このズーム + 回転機能を提供します。これを行う方法はありますか?

public void setImageStraighten ( Bitmap bitmap, int bmpHeight, int bmpWidth, double theta ) {
    float a = ( float ) Math.atan( bmpHeight / bmpWidth );
    // the length from the center to the corner of the green
    double len1 = ( ( bmpWidth / 2 ) / Math.cos( a - Math.abs( theta ) ) );
    // the length from the center to the corner of the black (^ = power)
    double len2 = Math.sqrt( Math.pow( ( bmpWidth / 2 ) , 2 )  +  Math.pow(( bmpHeight / 2 ) , 2 ));
    // compute the scaling factor
    float curScale = ( float ) ( len2 / len1 );

    Matrix matrix = new Matrix();
    matrix.postScale( curScale, curScale );

    Matrix rotateMtrix = new Matrix(  );
    rotateMtrix.postRotate( 5 );
    Bitmap resizedRotatedBitmap = Bitmap.createBitmap( bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), rotateMtrix, false );

    Bitmap bmp = ScalingUtilities.createScaledBitmap( resizedRotatedBitmap , 720,720, ScalingUtilities.ScalingLogic.CROP);
    int startHeight = (int)((curScale*bmpHeight)- bmpHeight);
    Bitmap resizedBitmap = cropBitmap1( bmp , bmpHeight);
    imgSwap.setImageBitmap( resizedBitmap );
    imgSwap.setScaleType( ImageView.ScaleType.CENTER_CROP );
}
4

0 に答える 0