title: java.lang.IllegalArgumentException: width and height must be > 0
body: <p>I am trying to open an Image from the gallery and place a random rectangle on it. But when I click the button to open the gallery, the following exception occurs.</p>
  
  <p>java.lang.IllegalArgumentException: width and height must be > 0</p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener {
   TextView textView;
   ImageView image1;
  Button get_image, save_image, read_image;
   String selectedImagePath;
  int SELECT_PICTURE = 1;
  String DB_NAME =  "test.db";
  String TABLE_NAME = "mytable";
  String pts_table="ptstable";
  Bitmap bmp;
  Intent intent;
  Canvas cnvs;
  Uri selectedImageUri;
  Random r;
  int x,y;
  Paint paint;
  
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      r=new Random();
  
      image1 = (ImageView) findViewById(R.id.imageView1);
      //image2 = (ImageView) findViewById(R.id.imageView2);
      textView = (TextView) findViewById(R.id.textView1);
  
      get_image = (Button) findViewById(R.id.get_image);
      get_image.setOnClickListener(this);
  
      save_image = (Button) findViewById(R.id.save_image);
      save_image.setOnClickListener(this);
  
      read_image = (Button) findViewById(R.id.read_image);
      read_image.setOnClickListener(this);
  
  }
  
  public void onClick(View v) {
  
      int id = v.getId();
      switch (id) {
  
      case R.id.get_image:
  
          intent = new Intent();
          intent.setType("image/*");
          intent.setAction(Intent.ACTION_GET_CONTENT);
          startActivityForResult(
                  Intent.createChooser(intent, "Select Picture"),
           SELECT_PICTURE);
          break;
      }
  
  }
  
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (resultCode == RESULT_OK) {
          if (requestCode == SELECT_PICTURE &amp;&amp; data!=null) {
  
              selectedImageUri = data.getData();
              selectedImagePath = getPath(selectedImageUri);
              System.out.println("Image Path : " + selectedImagePath);
  
              bmp=Bitmap.createBitmap(image1.getHeight(),image1.getWidth(),Bitmap.Config.RGB_565);
              cnvs=new Canvas(bmp);
              paint=new Paint();
              paint.setColor(Color.RED);
              cnvs.drawBitmap(BitmapFactory.decodeFile(selectedImagePath), 0,0,null);
              cnvs.drawRect(50, 50, 100, 100, paint);
              image1.setImageBitmap(bmp);
  
              //image1.setImageURI(selectedImageUri);
          }
      }
  }
  
  @SuppressWarnings("deprecation")
  public String getPath(Uri uri) {
      String[] projection = { MediaStore.Images.Media.DATA };
      Cursor cursor = managedQuery(uri, projection, null, null, null);
      int column_index = cursor
              .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      cursor.moveToFirst();
      return cursor.getString(column_index);
  } 
  </code></pre>
  
  <p>}</p>
  
  <p>This occurs inside onActivityResult() at </p>
  
  <pre><code>bmp=Bitmap.createBitmap(img.getHeight(),img.getWidth(),Bitmap.Config.RGB_565); 
  </code></pre>
  
  <p>Can somebody please help me? Thanks in advance</p>