拍摄照片并应用效果(缩放、旋转、灰色、用手指绘制)

Capture photo and apply effects (scale, rotate, grey, draw with finger)

我正在尝试拍摄照片,然后允许用户添加一些效果、绘图、将其他资产拖到图像、添加文本等。就像 snapchat 相机。

我已经关注了Camera 2 API sample。代码的主要部分位于 Camera2BasicFragment.java

我已经实现了截取和预览图像,但是示例中设置了图像TextureView,但我不知道如何继续操作图像。

我不知道我是否应该使用 TextureViewCanvasSurfaceView

我想要的最终图像结果示例:

提前致谢。

拍摄您的照片,保存您的图像。然后在 ImageView 中,您可以使用 BitmapColorMatrix 应用您想要的所有类型的效果。 这里我给个小样做个图片灰度

    public void toGrayscale() {
        ColorMatrix matrix = new ColorMatrix();
        matrix.setSaturation(0);

        ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
        imageView.setColorFilter(filter);
    }

应用效果后,只需将可绘制对象保存到图像文件中,如下所示:

public void saveDrawable(ImageView imageView) throws FileNotFoundException {
    Bitmap bitmap = getBitmapFromImageView(imageView);
    OutputStream fOut = null;
    try {
        fOut = new FileOutputStream(absolutePath);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 95, fOut);
    } finally {
        if (fOut != null) {
            try {
                fOut.close();
            } catch (IOException e) {
                //report error
            }
        }

    }
}

@NonNull
private Bitmap getBitmapFromImageView(ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    Rect bounds = drawable.getBounds();
    Bitmap bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.draw(canvas);
    return bitmap;
}

有一个很好的图书馆可以帮助你https://github.com/chrisbanes/PhotoView


用手指画画这道题how to draw line on imageview along with finger in android应该能帮到你

希望对您有所帮助!!