1

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

我遵循了Camera 2 API 示例。代码的主要部分位于 Camera2BasicFragment.java

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

我不知道我是否应该使用 aTextureView或 aCanvas或 a SurfaceView

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

例子

提前致谢。

4

1 回答 1

1

拍摄您的照片,保存您的图像。然后在一个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


用手指画这个问题如何在imageview上画线以及android中的手指应该可以帮助你

希望它有帮助!

于 2016-02-24T15:57:09.987 回答