I am working on Android application development. My intention is to capture an image using device camera and add the current date and time as text on the captured image. and make the entire thing as single image to upload on server.
Asked
Active
Viewed 987 times
0
-
To draw text on an image read my post here: http://stackoverflow.com/a/12332941/1306012 and use "drawText" Method on canvas. – Bruno Bieri Oct 31 '12 at 09:42
-
@Ganesh do you get any code for write current date time with in a image??? – krrr25 Aug 21 '13 at 10:09
2 Answers
1
read here
Edit:
Bitmap photo = (Bitmap) data.getExtras().get("data");
//create bitmap with a canvas
Bitmap newPhoto = Bitmap.createBitmap(photo.getWidth(),photo.getHeight());
Canvas canvas = new Canvas(newPhoto);
canvas.drawBitmap(photo,0,0,null);
//draw the text
Paint paint = new Paint();
//paint.setColor(Color.BLACK);
canvas.drawText("write bla bla bla",x,y,paint);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
newPhoto.compress(Bitmap.CompressFormat.PNG, 100, stream);
//get bytes from stream and send to your server

Community
- 1
- 1

Trần Sĩ Long
- 457
- 3
- 15
-
-
Its fine , but My intention is to keep the text on captured image, then it looks as single image with both text on image. – Ganesh Oct 31 '12 at 09:46
-
Thank you, I have done that. But its working some devices and not working some devices.Do you know any other method to work for all devices. – Ganesh Oct 31 '12 at 09:56
-
What's the problem? If we get Bitmap from Bundle correct, we always create image with Canvas – Trần Sĩ Long Oct 31 '12 at 10:22
0
Extend a View, for example ImageView:
public class MyImageView extends ImageView{}
Override the onDraw()
@Override
public void onDraw(Canvas canvas){
// draw the image you got from the camera
canvas.drawBitmap(cameraImage, 0, 0, paint);
// draw the date
canvas.drawText("Date string", x, y, paint);
}
When you want to send the image:
myImageView.buildDrawingCache();
Bitmap bmp = myImageView.getDrawingCache();
For sending to the server, that's another question and many examples here on SO. Good luck.

Simon
- 14,407
- 8
- 46
- 61
-
Thank you for the reply. Its helped me to think another way of programing. – Ganesh Oct 31 '12 at 10:08