I need to draw shapes on an image in my layout. This image needs to be able to change to another image programically, and I also need to draw shapes (rectangles and circles) over top of this image programically. The shapes will also change. I have an existing xml layout and would like to use this layout with the programmed image view in it. What’s the easiest way to do this? Would it be possible to see a short example?
Share
I figured out how to do this:
Here’s how:
Explanation: The first line gets the
ImageViewfrom the layout. I then grab the new image I want displayed usingBitmapFactory.decodeFile, whereimageFileStringis the file location of the new image I want to display. After that I create a new canvas using the bitmap and draw on it. I then display the bitmap to theImageViewusingimage.setImageBitmap(bMap);.