I have following requirement i have a image in my android phone. now i want to edit this image in such a way that it becomes the part of my image for e.g., say i want to write text on the image like date when it is edited and write a name on the image which i will give. now save that image and now if i open that image again the text which i have written will also be shown because now it becomes the part of my image.(This something like what we do it in photoshop) i hope my requirement is very clear. i searched on the stackoverflow but didnt get any proper working way to do. i only found the image with text overlayed on that not actual image edited. thank you all who will try to solve my query.
-
i think that you need to capture image after changes and replace it then may be this will help you : http://stackoverflow.com/questions/3582603/programmatic-screencapture-on-mobile-device – Nikunj Patel Sep 12 '11 at 06:51
2 Answers
You should open the image as a Bitmap
and edit it with a canvas
then just save it to the SDcard.
in = new FileInputStream("/sdcard/test2.png");
buf = new BufferedInputStream(in);
Bitmap bMap = BitmapFactory.decodeStream(buf);
Then assign it to a canvas:
Canvas myCanvas = new Canvas(bMap);
Edit! Apparently you have to make a copy of the bitmap before changing it: Look at this question for more informations: Loading a resource to a mutable bitmap
To draw text or anything else on a canvas you need a paint.
Paint myPaint = new Paint();
myPaint.setColor(Color.Black);
myPaint.setTextSize(25);
myCanvas.drawText("Your text", positionX, positionY, myPaint); //Set the position where you like
Then you save your image
try {
FileOutputStream out = new FileOutputStream("Your filename");
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
References:

- 1
- 1

- 1,913
- 1
- 18
- 30
-
Thanks for the reply. could you please eloberate more on that as i am new to graphics. just give me the way to wirte on the imgae. – School Boy Sep 12 '11 at 07:34
-
Thanks for the help jDourlens i want to add something here that when i do this Canvas myCanvas = new Canvas(bMap); it is giving me exception (continue...) – School Boy Sep 12 '11 at 08:41
-
09-12 14:22:58.756: ERROR/AndroidRuntime(1399): FATAL EXCEPTION: main 09-12 14:22:58.756: ERROR/AndroidRuntime(1399): java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor 09-12 14:22:58.756: ERROR/AndroidRuntime(1399): at android.graphics.Canvas.
(Canvas.java:83) 09-12 14:22:58.756: ERROR/AndroidRuntime(1399): at com.marico.editimage.EditingImageActivity$1.onClick(EditingImageActivity.java:52) 09-12 14:22:58.756: ERROR/AndroidRuntime(1399): at android.view.View.per – School Boy Sep 12 '11 at 08:45 -
It's because you can't modify directly the bitmap you loaded. You have to work on a copy of it. Sorry, I thought it would work.. Try looking at this: http://stackoverflow.com/questions/3693060/loading-a-resource-to-a-mutable-bitmap – GrandMarquis Sep 12 '11 at 08:52
-
Thats true. i did and it worked. Thanks for such great support you stackoverflow really doing well. i liked the way you work. may be i can work like that any way great thanks from our Team. – School Boy Sep 12 '11 at 09:06
-
As soon as you want, just participate asnwering questions. Asking questions is also a way to improve the site content for future programmers that will have the same problems. Have a good day! – GrandMarquis Sep 12 '11 at 09:10
You should add this image as background of relative layout and add a textView over this layout . Additionally you can move text over the relative layout. When you save this action you please note position, text value, text size, font etc of textView and then you need to take an invisible relative layout in background which is similar in actual image size and put a textView in proportion of earlier noted dimension so it will not loose image quality and textView action. Finally you need to take a snapshot of this invisible relative layout and convert this into jpeg or as suitable to you. It works and real use of taking screenshot programmatically. if you are willing to implement this i can provide code as well.

- 1,826
- 22
- 41