像Image Straightening Android一样实现Instagram

时间:2013-10-21 12:18:51

标签: android image rotation zoom instagram

使用此链接: Image Straightening in 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 );
}

0 个答案:

没有答案