naver / android-imagecropview

android image crop library
Apache License 2.0
254 stars 55 forks source link

image should not be inside of crop frame #6

Closed tyson512 closed 9 years ago

tyson512 commented 9 years ago

In this i have two issues :

1st issue :

based on my requirement i added seekbar in crop screen and apply the straightening to the image using seekbar. and image should not be inside the crop frame.

and here is the code what i added to the source

activity_crop xml in FrameLayout ::

       <SeekBar 
        android:id="@+id/seek"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:progress="45"
        android:max="90"
        />

In CropActivity :

      seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            straighten(progress,imageCropView);
        }
    });

Straightening method :

   public void straighten(float progress, final ImageCropView ivCropimage) {
    float angle = (progress - 45);
    float width = ivCropimage.getViewBitmap().getWidth();
    float height = ivCropimage.getViewBitmap().getHeight();

    if (width > height) {
        width = ivCropimage.getViewBitmap().getHeight();
        height = ivCropimage.getViewBitmap().getWidth();
    }
    float a = (float) Math.atan(height / width);
    // the length from the center to the corner of the green
    float len1 = (width / 2)
            / (float) Math.cos(a - Math.abs(Math.toRadians(angle)));
    // the length from the center to the corner of the black
    float len2 = (float) Math.sqrt(Math.pow(width / 2, 2)
            + Math.pow(height / 2, 2));
    // compute the scaling factor
    float scale = len2 / len1;
    Matrix matrix = ivCropimage.getImageMatrix();
    if (mMatrix == null) {
        mMatrix = new Matrix(matrix);
    }
    matrix = new Matrix(mMatrix);
    imagewidth = ivCropimage.getImageviewWidth();
    imageheight = ivCropimage.getImageviewHeight();

    float newX = (imagewidth / 2) * (1 - scale);
    float newY = (imageheight / 2) * (1 - scale);
    matrix.postScale(scale, scale);
    matrix.postTranslate(newX, newY);
    matrix.postRotate(angle, imagewidth / 2, imageheight / 2);

    ivCropimage.setImageViewMatrix(matrix,angle);
}

In ImageCropView :

public void setImageViewMatrix(Matrix matrix,float angle)
{
    setImageMatrix(matrix);
    mSuppMatrix = matrix;
}

and i just removed 'protected' for "mSuppMatrix" in ImageCropViewBase.

and this is the code what i added. and i run it after that i applied straightening to the image and move the image to down and see the image getting black in the corner like shown below..

screenshot_2015-07-14-15-03-23

2nd issue:

and that too image not saving as rotated after apply the cropping.

how to resolve these issues? is there any way ?

helloyako commented 9 years ago

@tyson512 I'm sorry. I don't support setImageMatrix If you need, please fix it and pull request :) Thank you.