0

私はカメラから写真を選ぶカメラアプリをやっています.samsung galaxy aceで動作する以下のコードで作業していますが、Android OS 2.2のHtc Desireでは動作していません.

**capture button Onclick:**
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
String fileName = "IMG_" + simpleDateFormat.format(new Date()) + ".jpg";
File myDirectory = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/");
cameraImageFile = new File(myDirectory, fileName);
Uri imageUri = Uri.fromFile(cameraImageFile);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, CAMERA_PIC_REQUEST);

**OnActivityResult:**
switch (requestCode) {
case CAMERA_PIC_REQUEST:

ImageView.setImageBitmap(decodeFile(cameraImageFile.getAbsolutePath()));

}
break;
4

3 に答える 3

0

Cameraの起動時に画像のURIを渡す場合は、次のように画像を取得しますonActivityResult

     @Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
  super.onActivityResult(requestCode, resultCode, data); 

  if (CAMERA_PIC_REQUEST == resultCode) { 
     ImageView iv = (ImageView) findViewById(R.id.ReturnedImageView); 

      // Decode it for real 
     BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
                    bmpFactoryOptions.inJustDecodeBounds = false; 

     //imageFilePath image path which you pass with intent 
     Bitmap bmp = BitmapFactory.decodeFile(cameraImageFile, bmpFactoryOptions); 

      // Display it 
     iv.setImageBitmap(bmp); 
     }    
   } 
} 
于 2012-07-06T05:03:23.393 に答える
0

Calendar currentDate = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); String dateNow = formatter.format(currentDate.getTime());
imageName = dateNow + ".jpg";
//Create path to store image in SDCard path = Environment.getExternalStorageDirectory() + File.separator + imageName; startCameraActivity();

protected void startCameraActivity() { File file = new File(path); Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, Globals.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 100) {
switch (resultCode) {
case RESULT_CANCELED:
Log.i("MakeMachine", "User cancelled");
Toast.makeText(getBaseContext(), "User cancelled", Toast.LENGTH_LONG).show(); break;
case RESULT_OK:
BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4;
Bitmap bitmap = BitmapFactory.decodeFile(path, options); image.setImageBitmap(bitmap); }

于 2012-07-06T05:13:22.233 に答える
0

all.i のおかげで問題が解決しました。コードに小さな変更を加えました。File myDirectory = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/");

Htc には DCIM/Camera という名前のフォルダーはありません。

File myDirectory = new File(Environment.getExternalStorageDirectory() + "/DCIM/");

于 2012-07-06T05:27:47.407 に答える