2

在此处输入图像描述

如何显示如下图所示的时间和日期。我有一个捕获图像的代码。但是我如何在捕获图像时显示时间和日期。这是启动相机应用程序的代码

我的代码:

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);
        }  
    } 
}
4

2 回答 2

2

检查这些链接link1link2

在这里,您拥有的图像被带到画布上。现在画布用于修改图像,方法是使用类似的东西在上面写一些东西

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);

这可以帮助您将文本绘制到图像上。试试看。

于 2012-10-29T16:54:20.947 回答
0
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();
于 2015-09-14T05:42:55.637 回答