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