Search code examples
javaandroidxamarinjbossiconic

Place frame when taking photo Android Studio


I want to develop an application that takes a photograph and allows you to select a frame for photography.

I already have developed the interfaces, like taking the photo and storing it.

But I put a frame to the photo taken I could not.

Any recommendation?


Solution

  • In what format do you store taken photos and your frame images? If you plan to insert your picture into a simple frame, I'd suggest to first draw your taken picture on a Canvas, and then draw your frame over it. Keep in mind the sizing - you don't want your picture be too small or too big.

    I'm providing an example snippet here:

    public Bitmap Output(Bitmap takenPhoto, Bitmap frameImage)
    {        
        int width, height, x, y;
        height = ### // your desired height of the whole output image 
        width = ### // your desired width of the whole output image
        x = ### // specify indentation for the picture
        y = ###
    
        Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(result);
        Paint paint = new Paint();
    
        c.drawBitmap(takenPhoto, x, y, paint); // draw your photo over canvas, keep indentation in mind (x and y)
        c.drawBitmap(frameImage, 0, 0, paint); // now draw your frame on top of the image
    
        return result;
    }
    

    Keep in mind that I have not tested the code and you might (actually, you'll have to) apply corrections.