0

I am developing an Android application using Java. I am doing some image manipulating in my application. First of all, I like to save I have no knowledge about image processing. But, I am trying to get into it. What I would like to do now is draw a simple image on a bitmap and save it as one bitmap.

I am loading an image from asset folder as a bitmap like this.

Bitmap rectBitmap = BitmapFactory.decodeStream(istr);

Let's say the photo is a just simple rectangle like this.

enter image description here

Then I would like to draw a bitmap (triangle shape) using coordinates point. The image would be some this.

enter image description here

My imagination of code would be like this.

rectBitmap.drawOnTop(coorPointOneValues, coorPointTwoValues, coorPointThreeValues);

Coordinate point values would be x and y value since I am working on the 2D coordinate system.

Then I would like to save the image something like this after drawing traingle

rectBitmap = rectBitmap.saveBitmap();

How can I do it? The scenario mentioned is a possible way that I can think of. If it is not possible, what would be the other way around?

halfer
  • 19,824
  • 17
  • 99
  • 186
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372
  • 1
    Possible duplicate of [Android: How to overlay-a-bitmap/draw-over a bitmap?](https://stackoverflow.com/questions/1540272/android-how-to-overlay-a-bitmap-draw-over-a-bitmap) – Bö macht Blau Mar 29 '18 at 16:17

1 Answers1

2

You can do it like this.

1, read or create your bitmap:

Bitmap rectBitmap = BitmapFactory.decodeStream(istr);
Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

2, create a canvas on the bitmap:

Canvas canvas = new Canvas(bitmap);

3, draw something:

canvas.drawColor(Color.RED)   
canvas.drawRect / canvas.drawLine / canvas.drawArc ...
//for triangle shape you can use drawPath

4, save the bitmap:

bitmap.compress(CompressFormat format, int quality, OutputStream stream)
L. Swifter
  • 3,179
  • 28
  • 52