1

I am trying to capture a photo and after that, allow to the user to add some effects, draw, drag other assets to the image, add text, etc. Like snapchat camera.

I have followed the Camera 2 API sample. The major part of the code is at Camera2BasicFragment.java

I have achieved the capture and preview image, but the example set the image in a TextureView, but I do not have idea how to continue to manipulate the image.

I dont know if I should use a TextureView or a Canvas or a SurfaceView.

An example of the final image result that I want:

example

Thanks in advance.

Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57
  • 1
    "allow to the user to add some effects, draw, drag other assets to the image, add text, etc." -- this would make a good book. Stack Overflow is for more specific questions, ones that can be answered in a paragraph or two. – CommonsWare Feb 24 '16 at 14:36
  • Maybe, you could start investigating `ColorMatrices` possibilities (just change some parameters and have GreyScale, Negative, Sepia Toning, ...). And **very fast**, since they work on the global bitmap colors, not pixel by pixel. – Phantômaxx Feb 24 '16 at 14:40
  • 1
    Thanks @HrundiV.Bakshi I will investigate. – AndroidRuntimeException Feb 24 '16 at 14:42
  • You will discover a lot of interesting image alterations which can be done fast and easy (programmatically easy, conceptually... there's a lot to study). – Phantômaxx Feb 24 '16 at 14:45
  • @CommonsWare I dont want an example or anything, I only need orientation. Sorry if I offend you, but StackOverflow is for help others too, not for sarcasm. Thanks for vote down. – AndroidRuntimeException Feb 24 '16 at 14:45
  • 1
    "but StackOverflow is for help others too, not for sarcasm" -- I was not being sarcastic. It *would* make a good book, and Stack Overflow *is* for more specific questions, as you can tell by reading [the site documentation](http://stackoverflow.com/help/closed-questions). "Thanks for vote down" -- I did not down-vote you. – CommonsWare Feb 24 '16 at 14:49
  • 1
    No, well, that wasn't really sarcasm. Just enforcing the site rules: specific questions only. For the downvote... how can you tell that HE was the downvoter? We can never know who downvotes a post. It copuld also have been me (I wasn't), for what you know. Or someone who just downvoded and left the page – Phantômaxx Feb 24 '16 at 14:49
  • @CommonsWare We were writing the same things in the same moment... ;) – Phantômaxx Feb 24 '16 at 14:50
  • @HrundiV.Bakshi I like your first comment, why? Because I need orientation and you gave me. My post was clear an specific "I do not have idea how to continue to manipulate the image. I dont know if I should use a TextureView or a Canvas or a Surface view." ---Maybe I do not understand whats means specific for stackoverflow people, probably because I speak spanish. But I always see comments like CommonsWare that not added value to stackoverflow users. Is not personal with him, but is an attitude I have noticed here. Thanks to all, I will try to be more "specific" the next time :) – AndroidRuntimeException Feb 24 '16 at 15:20
  • @CommonsWare thanks you too. – AndroidRuntimeException Feb 24 '16 at 15:21
  • @AgustinSivoplás Specific means something like: "I have [this code]. But I get [this error]. After searching for 3 hours I came out with a solution which used [this technique]. But it doesn't fit my issue any more than a bare 45% (so to speak). How could I fix this error?" [this to be replaced with some code]. – Phantômaxx Feb 24 '16 at 16:04

1 Answers1

1

Capture your photo , save your image. Then in an ImageView you can apply all kind of effects that you want using Bitmap and ColorMatrix. Here I give a small sample to make an image grayscale

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

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

After applying the effects just save drawable to image file like this:

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;
}

There is a good library that will help you https://github.com/chrisbanes/PhotoView


To draw with a finger this question how to draw line on imageview along with finger in android should help you

Hope its helps!!

Community
  • 1
  • 1
Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57