title: Set the dimensions of image captured in android
body: <p>In my application, I have an activity where we can capture the image from camera on button click using intent and set the captured image into imageview. Its working absolutely fine. </p>
  
  <p>But now i want the image in  specific dimensions. For example, in my case the dimensions of my image view is 150dp * 150dp. So i want that the dimensions of image captured by camera should also always be 150dp * 150dp in order to fit perfectly. How can i do this?</p>
  
  <p>Here's my main activity.</p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener {
  
      Button btnTackPic;
      TextView tvHasCamera, tvHasCameraApp;
      ImageView ivThumbnailPhoto;
      Bitmap bitMap;
      static int TAKE_PICTURE = 1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          // Get reference to views
          tvHasCamera = (TextView) findViewById(R.id.tvHasCamera);
          tvHasCameraApp = (TextView) findViewById(R.id.tvHasCameraApp);
          btnTackPic = (Button) findViewById(R.id.btnTakePic);
          ivThumbnailPhoto = (ImageView) findViewById(R.id.ivThumbnailPhoto);
  
          // Does your device have a camera?
          if(hasCamera()){
              tvHasCamera.setBackgroundColor(0xFF00CC00);
              tvHasCamera.setText("You have Camera");
          }
  
          // Do you have Camera Apps?
          if(hasDefualtCameraApp(MediaStore.ACTION_IMAGE_CAPTURE)){
              tvHasCameraApp.setBackgroundColor(0xFF00CC00);
              tvHasCameraApp.setText("You have Camera Apps");
          }
  
          // add onclick listener to the button
          btnTackPic.setOnClickListener(this);
  
      }
  
      // on button "btnTackPic" is clicked
      @Override
      public void onClick(View view) {
  
          // create intent with ACTION_IMAGE_CAPTURE action 
          Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  
          //Edit to save picture      
        File file = new File(Environment.getExternalStorageDirectory(), "my-photo.jpg"); 
        Uri photoPath = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, photoPath);
  
          // start camera activity
          startActivityForResult(intent, TAKE_PICTURE);
  
      }
  
      // The Android Camera application encodes the photo in the return Intent delivered to onActivityResult() 
      // as a small Bitmap in the extras, under the key "data"
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  
          if (requestCode == TAKE_PICTURE &amp;&amp; resultCode== RESULT_OK &amp;&amp; intent != null){
              // get bundle
              Bundle extras = intent.getExtras();
  
              // get 
              bitMap = (Bitmap) extras.get("data");
  
              ivThumbnailPhoto.setImageBitmap(bitMap);
  
          }
      }
  
      // method to check you have a Camera
      private boolean hasCamera(){
          return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
      }
  
      // method to check you have Camera Apps
      private boolean hasDefualtCameraApp(String action){
          final PackageManager packageManager = getPackageManager();
          final Intent intent = new Intent(action);
          List&lt;ResolveInfo&gt; list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
  
          return list.size() &gt; 0;
  
      }
  }
  </code></pre>
  
  <p>Thanks in advance.</p>