android - android-gpuimage 中 View 的旋转

标签 android image-processing rotation android-gpuimageview

我正在尝试旋转来自 android-gpuImage 的图像,但旋转不起作用。这是代码

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_document_edit);

    mGPUImageView = (GPUImageView) findViewById(R.id.gpuimage);

    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, REQUEST_PICK_IMAGE);

    seekBar = (SeekBar) findViewById(R.id.seekBar);
    seekBar.setOnSeekBarChangeListener(this);
    findViewById(R.id.btn_rotate).setOnClickListener(this);
    findViewById(R.id.button_save).setOnClickListener(this);

    GPUImageFilter filter = new GPUImageBrightnessFilter();
    switchFilterTo(filter);
    mGPUImageView.requestRender();

}

旋转按钮的OnClick方法:

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btn_rotate:
            rotationAngle -= 90f;
            if (rotationAngle <= -360f)
                rotationAngle = 0f;
            mGPUImageView.setRotationX(rotationAngle);
            mGPUImageView.requestRender();
            break;
    }
}

OnActivityResult 我已经加载了用户从图像 piker Intent 中选择的图像。单击按钮后,我尝试旋转 mGPUImageView 但 View 显示为空白。

下面是我尝试旋转 mGPUImageView

时的图像

View with image loaded

当我旋转时:

enter image description here

我怎样才能实现旋转。请帮忙。

最佳答案

int 标志 = 0;

public void setRotationRight() {
    if (flag == 0) {
        gpuImageView.setRotation(Rotation.ROTATION_90);
        flag = 1;
        AppConfig.log(TAG, "90, flag: " + flag);
    } else if (flag == 1) {
        gpuImageView.setRotation(Rotation.ROTATION_180);
        flag = 2;
        AppConfig.log(TAG, "180, flag: " + flag);
    } else if (flag == 2) {
        gpuImageView.setRotation(Rotation.ROTATION_270);
        flag = 3;
        AppConfig.log(TAG, "270, flag: " + flag);
    } else if (flag == 3) {
        gpuImageView.setRotation(Rotation.NORMAL);
        flag = 0;
        AppConfig.log(TAG, "normal, flag: " + flag);
    }
}

public void setRotationLeft() {
    if (flag == 0) {
        gpuImageView.setRotation(Rotation.ROTATION_270);
        flag = 1;
        AppConfig.log(TAG, "270, flag: " + flag);
    } else if (flag == 1) {
        gpuImageView.setRotation(Rotation.ROTATION_180);
        flag = 2;
        AppConfig.log(TAG, "normal, flag: " + flag);
    } else if (flag == 2) {
        gpuImageView.setRotation(Rotation.ROTATION_90);
        flag = 3;
        AppConfig.log(TAG, "180, flag: " + flag);
    } else if (flag == 3) {
        gpuImageView.setRotation(Rotation.NORMAL);
        flag = 0;
        AppConfig.log(TAG, "90, flag: " + flag);
    }
}

关于android - android-gpuimage 中 View 的旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32092870/

相关文章:

android - NFC SWP 小程序选择返回 6999

android - 两行约束布局

algorithm - 在图片中找到美国国旗?

java - 将两个 BufferedImage 并排复制到一张图像中

video - ffmpeg过滤器顺序旋转比例与覆盖

ios - 旋转设备时布局崩溃

java - 错误 : Unsupported method: AndroidProject. getVariantNames()

android - 蓝牙 LE 连接时间/缓存

javascript - 如何使用 JavaScript/Node.js 创建图像?

jquery - 围绕底部的圆div旋转