Search code examples
androidandroid-gpuimageview

android-gpuimage - image straightening with GPUImageView


In my android app.I want to make image Straightening edit feature using android-gpuimage library but GPUImageView doesn't give feature of getBitmap() or setMatrix() then how is it possible please let me know? here is the code to review :

       @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                    if(isStraightenEffectEnabled){
                        float angle = (progress - 45);
                        float width = mGPUImageView.getWidth();  
                        float height = mGPUImageView.getHeight();

                        if (width > height) {
                            width = mGPUImageView.getHeight();
                            height = mGPUImageView.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 = mGPUImageView.getMatrix();
                        if (mMatrix == null) {
                            mMatrix = new Matrix(matrix);
                        }
                        matrix = new Matrix(mMatrix);

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

Is it possible to get mGPUImageView.setMatrix(matrix);

NOW HERE getMatrix() is a method of GPUImageView but setMatrix() or getBitmap() is not method available with GPUImageView class. Any workarounds if possible ?


Solution

  • add getGPUImage in GPUImageView class

    public GPUImage getGPUImage() {
        return mGPUImage;
    }
    

    then get you can get bitmap like this:

    mGPUImageView.getGPUImage().getBitmapWithFilterApplied();