2017-02-10 8 views
0

これは撮影した画像のカメラを保存して保存するSDcardですが、今このコードを5秒ごとに撮影したいと考えています。これを共有してください。Androidで大量の画像をキャプチャして保存する

public class MainActivity extends ActionBarActivity { 


    private final int requestCode = 20; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     int pictureCounter = 10; 

     imageHolder = (ImageView)findViewById(R.id.captured_photo); 
     Button capturedImageButton = (Button)findViewById(R.id.photo_button); 
     capturedImageButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       Intent photoCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
       startActivityForResult(photoCaptureIntent, requestCode); 
      } 
     }); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if(this.requestCode == requestCode && resultCode == RESULT_OK){ 
      Bitmap bitmap = (Bitmap)data.getExtras().get("data"); 

      String partFilename = currentDateFormat(); 
      storeCameraPhotoInSDCard(bitmap, partFilename); 


     } 
    } 

    private String currentDateFormat(){ 
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HH_mm_ss"); 
     String currentTimeStamp = dateFormat.format(new Date()); 
     return currentTimeStamp; 
    } 

    private void storeCameraPhotoInSDCard(Bitmap bitmap, String currentDate){ 
     File outputFile = new File(Environment.getExternalStorageDirectory(), "photo_" + currentDate + ".jpg"); 
     try { 
      FileOutputStream fileOutputStream = new FileOutputStream(outputFile); 
      bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream); 
      fileOutputStream.flush(); 
      fileOutputStream.close(); 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

答えて

0

スレッドを使用する実行可能なインターフェイスを実装する必要があります。このようにして、OnClickメソッドで関数を呼び出してから、Thread.sleep(timeinmilliseconds)を呼び出してから、必要に応じてonClickメソッド内の関数を再度呼び出すことができます。ここで

は、スレッドを使用する方法の例です:

http://www.wideskills.com/java-tutorial/java-threads-tutorial

+0

応答に感謝しかし、どのようにこのすべてを行うには! :/ – rheema

+0

1.クラスの先頭に、実装の実行可能ファイルを追加します。 2.スレッドを作成します。 3.callメソッド4.call thread.sleep()5.再度メソッド呼び出し – JordanH

+0

これは、私が提供したリンクではっきりと説明されています。 – JordanH

関連する問題