I need help solving the following basic problem. I want to create an app that displays an image when loaded and a button, which, when pressed, will display the modified image with an 'X' drawn over it.
I took the following approach. I have the image as a png file stored in resources. In my layout, I have an ImageView to display the image. In my Activity class, when the button is pressed, I have the code as follows:
- Code: Select all
Canvas canvas = new Canvas(mybmp); //mybmp iis the Bitmap obtained from applying BitmapFactory on my resource image
//drawing 'X' over the image
mImageView.setImageBitmap(mybmp);//mImageView is the ImageView object used to display my image
I also tried calling setContentView after the image source has been modified, but the program crashed. I'm confused about when I can call setContentView, Canvas, Bitmap, and Drawable. If you could provide any info as to how those elements fit together when rendering an image on the screen, it would be extremely helpful.
Thanks for your help.