How do I write text over a picture in Android and save it?

前端 未结 4 614
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 00:32

How can I write text on an image and then save it in Android?

Basically I want to let user write something on the images which my camera app will click for them. I c

4条回答
  •  青春惊慌失措
    2020-11-29 00:56

    You can put an EditText and write into it, and after writing, you first convert it to Bitmap like:

    Bitmap bmp = Bitmap.createBitmap(mEditText.getDrawingCache());
    

    Now you can add created image bmp to your original image like this:

    Call: Bitmap combined = combineImages(bgBitmap,bmp);

    public Bitmap combineImages(Bitmap background, Bitmap foreground) { 
    
            int width = 0, height = 0;
            Bitmap cs;
    
            width = getWindowManager().getDefaultDisplay().getWidth();
            height = getWindowManager().getDefaultDisplay().getHeight();
    
            cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            Canvas comboImage = new Canvas(cs);
            background = Bitmap.createScaledBitmap(background, width, height, true);
            comboImage.drawBitmap(background, 0, 0, null);
            comboImage.drawBitmap(foreground, matrix, null);
    
            return cs;
        }
    

提交回复
热议问题