0

I want to open an image from SD card, while image is on display I want to draw on it using touch and motion events and save the image back. Any help or pointer to any sample code would be of great help.

1 Answers1

1

I'm sure there are many ways, and many ways better than this but this is how I would do it:

Basically in my understanding you need to open the image from an SD card to a bitmap to a imageview in your activity. http://www.higherpass.com/Android/Tutorials/Working-With-Images-In-Android/2/

Then you need to go pixel by pixel and get each value for the color so you can change it in an onTouchEvent. http://developer.android.com/reference/android/graphics/Bitmap.html See getPixel() and setPixel()

The user gets to draw stuff on it. You need some way to capture the motion event, and change your data model of the image you just got by getting all of the pixels. You could use a surfaceview or something similar. Android: creating a Bitmap with SurfaceView content

Finally you need to save the picture to the SD card. Android write to sd card folder

Hopefully this helped

Community
  • 1
  • 1
AJcodez
  • 31,780
  • 20
  • 84
  • 118
  • I am able to open image from SD card to bitmap to imageview. While I see image on screen, I touch the screen and get motion event. On motion event what should be done. Should I get do setPixel on existing bitmap and then draw this bitmap. How to translate position of touch to pixels of the bitmap to be modified. When I do setpixel on the X and Y co-ordinates of the touch event I get excetion. Is there any other way to draw on existing picture. – new to Android Mar 15 '12 at 12:09
  • Yeah draw on a canvas over it, and change the pixel in your data structure, not the actual picture. Then create a new picture when the user wants to save it. – AJcodez Mar 16 '12 at 23:50
  • Can you show me a sample code how to do that. I am doing following on motion event – new to Android Mar 21 '12 at 17:46
  • Well position the canvas you are drawing on over the original photo with a RelativeLayout and make the canvas transparent at first. Then put the data for each pixel in a 2D array from the surfaceview and the original picture, and overwrite it when there is something in the surface view. Just how I would do it. – AJcodez Mar 22 '12 at 18:59