2012-07-06 50 views
0

我正在做一個攝像頭應用程序,從相機中挑選照片我正在與下面的代碼工作在三星galaxy王牌,但在Android操作系統2.2 Htc慾望它不工作,請幫助我任何人解決它,在此先感謝。在HTC Desire中從相機捕捉圖像Android設備不工作?

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

回答

0

如果傳遞圖片的烏里開始然後相機獲得的圖像作爲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); 
    }  
    } 
} 
+0

imran如何處理這些多屏幕支持應用程序在andorid從你的任何幫助? – srinu 2012-07-06 05:38:28

+0

@srinu:對不起,親愛的,我不知道。但如果你張貼它作爲一個問題,那麼我相信你會很快得到正確的答案。謝謝朋友!!! :) – 2012-07-06 05:41:33

+0

@srinu:如果這個答案幫助你,你可以標記它爲他人提供幫助的答案。謝謝 – 2012-07-06 05:45:44

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

0

由於all.i解決這個問題,我做我的代碼中的微小變化,我使用 文件mydirectory中=新的文件(Environment.getExternalStorageDirectory()+「/ DCIM創建在SD卡中的文件/相機/」);

沒有命名爲HTC的DCIM/Camera文件夾只是改變了線低於其做工精細

文件mydirectory中=新的文件(Environment.getExternalStorageDirectory()+ 「/ DCIM /」);

相關問題