我正在尝试拍摄照片,然后允许用户添加一些效果、绘图、将其他 Assets 拖到图像、添加文本等。就像 snapchat 相机。
我已经关注了 Camera 2 API sample .代码的主要部分位于 Camera2BasicFragment.java
我已经实现了捕获和预览图像,但是示例将图像设置在 TextureView
中,但我不知道如何继续操作图像。
我不知道我是否应该使用 TextureView
或 Canvas
或 SurfaceView
。
我想要的最终图像结果示例:
提前致谢。
最佳答案
拍摄您的照片,保存您的图像。然后在 ImageView
中,您可以使用 Bitmap
和 ColorMatrix
应用您想要的所有类型的效果。
这里我给出一个小样本来制作图像灰度
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应该对你有帮助
希望对您有所帮助!!
关于android - 拍摄照片并应用效果(缩放、旋转、灰色、用手指绘制),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35604954/