Matrix.postScale生成像素化图像

时间:2016-09-18 06:18:09

标签: android matrix camera gallery

我正在使用扩展图库视图的library。 但是,我遇到的问题是未选择的项目是像素化的。深入研究代码,我怀疑这是基于输入进行图像处理的函数。

我的问题是,有没有办法确保当代码在图像矩阵上调用postScale时,我的图像不会像素化?

希望有人能指出我正确的方向。

unselectedScale = 0.2f

的值
 @Override
protected boolean getChildStaticTransformation(View child, Transformation t) {
    // We can cast here because FancyCoverFlowAdapter only creates wrappers.
    FancyCoverFlowItemWrapper item = (FancyCoverFlowItemWrapper) child;

    // Since Jelly Bean childs won't get invalidated automatically, needs to be added for the smooth coverflow animation
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        item.invalidate();
    }

    final int coverFlowWidth = this.getWidth();
    final int coverFlowCenter = coverFlowWidth / 2;
    final int childWidth = item.getWidth();
    final int childHeight = item.getHeight();
    final int childCenter = item.getLeft() + childWidth / 2;

    // Use coverflow width when its defined as automatic.
    final int actionDistance = (this.actionDistance == ACTION_DISTANCE_AUTO) ? (int) ((coverFlowWidth + childWidth) / 2.0f) : this.actionDistance;

    // Calculate the abstract amount for all effects.
    final float effectsAmount = Math.min(1.0f, Math.max(-1.0f, (1.0f / actionDistance) * (childCenter - coverFlowCenter)));

    // Clear previous transformations and set transformation type (matrix + alpha).
    t.clear();
    t.setTransformationType(Transformation.TYPE_BOTH);

    // Alpha
    if (this.unselectedAlpha != 1) {
        final float alphaAmount = (this.unselectedAlpha - 1) * Math.abs(effectsAmount) + 1;
        t.setAlpha(alphaAmount);
    }

    // Saturation
    if (this.unselectedSaturation != 1) {
        // Pass over saturation to the wrapper.
        final float saturationAmount = (this.unselectedSaturation - 1) * Math.abs(effectsAmount) + 1;
        item.setSaturation(saturationAmount);
    }

    final Matrix imageMatrix = t.getMatrix();

    // Apply rotation.
    if (this.maxRotation != 0) {
        final int rotationAngle = (int) (-effectsAmount * this.maxRotation);
        this.transformationCamera.save();
        this.transformationCamera.rotateY(rotationAngle);
        this.transformationCamera.getMatrix(imageMatrix);
        this.transformationCamera.restore();
    }

    // Zoom.
    if (this.unselectedScale != 1) {
        final float zoomAmount = (this.unselectedScale - 1) * Math.abs(effectsAmount) + 1;
        // Calculate the scale anchor (y anchor can be altered)
        final float translateX = childWidth / 2.0f;
        final float translateY = childHeight * this.scaleDownGravity;
        imageMatrix.preTranslate(-translateX, -translateY);
        imageMatrix.postScale(zoomAmount, zoomAmount);
        imageMatrix.postTranslate(translateX, translateY);
    }

    return true;
}

0 个答案:

没有答案