2012-10-29 234 views
2

enter image description here顯示時間和日期

如何顯示像下面圖像的時間和日期。我有一個捕獲圖像的代碼。但是我如何在拍攝圖像時顯示時間和日期。下面是啓動相機應用程序

我的代碼代碼:

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); 
     } 
    } 
} 
+1

http://www.whathaveyoutried.com? – njzk2

回答

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

這可以幫助你繪製文本到圖像。 試一試。

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