2012-04-10 109 views
0

當相機加載時,我只想打開相機的特定區域。不需要全屏打開。 enter image description here安卓相機的屏幕尺寸

在這裏,黑色區域只顯示相機視圖。我該如何做到這一點?

我寫了這樣的代碼..

public class CameraActivity extends Activity{ 

private static final int CAMERA_PIC_REQUEST = 15; 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    getParent().getParent().setTitle("Image Capture"); 

    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); 
    onActivityResult(15, 0, cameraIntent); 



} 

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
     if (resultCode == CAMERA_PIC_REQUEST) { 
     } 
} 

請人幫助我從這個問題。

在此先感謝..

+2

這裏是[相機API演示(HTTP:// marakana.com/forums/android/examples/39.html) – 2012-04-10 11:33:47

回答

3

試試這臺相機的活動代碼在你的應用程序

protected void startCameraActivity() { 
     selectedImagePath = Environment.getExternalStorageDirectory() + "/default" + image_count+ ".jpg"; 
     image_count++; 
     File file = new File(selectedImagePath); 
     Uri outputFileUri = Uri.fromFile(file); 
     Intent intent = new Intent (android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
     intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 
     startActivityForResult(intent, 0); 
     } 
     @Override 
     protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     switch (resultCode) { 
     case -1: 
     onPhotoTaken(); 
     break; 
     } 
     } 
     protected void onPhotoTaken() { 
     _taken = true; 
     bitmap = decodeFile(); 
     img_logo.setImageBitmap(bitmap); 

     } 
     @Override 
     protected void onRestoreInstanceState(Bundle savedInstanceState) { 
     if (savedInstanceState.getBoolean(PHOTO_TAKEN)) { 
     onPhotoTaken(); 
     } 
     } 
     @Override 
     protected void onSaveInstanceState(Bundle outState) { 
     outState.putBoolean(PHOTO_TAKEN, _taken); 
     } 
     private Bitmap decodeFile() { 
     try { 
     // decode image size 
     BitmapFactory.Options o = new BitmapFactory.Options(); 
     o.inJustDecodeBounds = true; 
     BitmapFactory.decodeStream(new FileInputStream(selectedImagePath), null, o); 
     final int REQUIRED_SIZE = 70; 
     int width_tmp = o.outWidth, height_tmp = o.outHeight; 
     int scale = 1; 
     while (true) { 
     if (width_tmp/2 < REQUIRED_SIZE 
     || height_tmp/2 < REQUIRED_SIZE) 
     break; 
     width_tmp /= 2; 
     height_tmp /= 2; 
     scale++; 
     } 
     // decode with inSampleSize 
     BitmapFactory.Options o2 = new BitmapFactory.Options(); 
     o2.inSampleSize = scale; 
     return BitmapFactory.decodeStream(new FileInputStream(selectedImagePath), null, o2); 
     } catch (FileNotFoundException e) { 
     } 
     return null; 
     } 
     public boolean onKeyDown(int keyCode, KeyEvent event) { 
      if(keyCode==KeyEvent.KEYCODE_BACK) 
      { 
       finish(); 
      } 
      return super.onKeyDown(keyCode, event); 
     } 

我希望這可以幫助ü