How to display a time and date like below image. I have a code for capturing image. But how can i display time and date in capturing image. Here is the code for launching camera application
My Code:
public class MyCameraActivity extends Activity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.imageView = (ImageView)this.findViewById(R.id.imageView1);
Button photoButton = (Button) this.findViewById(R.id.button1);
photoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}
check these links link1 and link2
Here the image you are having is taken onto a canvas. Now the canvas is used to modify the image by writing something on it using something like
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setStyle(Style.FILL);
canvas.drawPaint(paint);
paint.setColor(Color.BLACK);
paint.setTextSize(20);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String currentDateandTime = sdf.format(new Date());
canvas.drawText(currentDateandTime , 10, 25, paint);
This may help you to draw the text onto the image.
Give it a try.
imagename = String.valueOf(System.currentTimeMillis());
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String path = Environment.getExternalStorageDirectory() + "/Pictures/" + "pic_" + imagename + ".jpg";
File file = new File(path);
imageUri = Uri.fromFile(file);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
//on activity Result
Canvas canvas = new Canvas(drawableBitmap);
canvas.drawBitmap(drawableBitmap, 0, 0, null);
Paint paint = new Paint();
paint.setColor(getResources().getColor(R.color.Orange));
paint.setTextSize(22);
DateFormat dateFormatter1 = new SimpleDateFormat("dd-MM-yyyy");
DateFormat dateFormatter2 = new SimpleDateFormat("hh:mm:ss");
dateFormatter1.setLenient(false);
dateFormatter2.setLenient(false);
java.util.Date today = new java.util.Date();
// java.util.Timer;
String d = dateFormatter1.format(today);
String t = dateFormatter2.format(today);
canvas.drawText("" + d + ", " + t, 20f , loadedBitmap.getHeight() - 24, paint);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
drawableBitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
String path = Environment.getExternalStorageDirectory()+ "/Pictures/" + "pic_" + imagename + ".jpg";
File file = new File(path);
file.createNewFile();
FileOutputStream fo = new FileOutputStream(file);
fo.write(bytes.toByteArray());
fo.close();