title: How to reduce image size while taking from gallery through imagepath
body: <p>I want to take image from camera and also take from gallery that part i did .
  when i take images from one activity to other through image path it show memory out error on taking fourth image ,so i want to take image from  gallery and when i take image from gallery it should be compressed so it should not have out of memory error byte allocation.</p>
  
  <p>thanks.</p>
  
  <p>Here is my code can anybody help in this</p>
  
  <pre><code>imageview1=(ImageView) findViewById(R.id.image1);
      imageview2=(ImageView) findViewById(R.id.image2);
      imageview3=(ImageView) findViewById(R.id.image3);
      imageview4=(ImageView) findViewById(R.id.image4);
  
  
      Bitmap b = (Bitmap) getIntent().getParcelableExtra("data") ;
  
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
      locationname = preferences.getString("Location", "Location");
  
      SharedPreferences preferences1 = PreferenceManager.getDefaultSharedPreferences(this);
      categoryname = preferences1.getString("categoryname", "categoryname");
  
      SharedPreferences imagepath1 = PreferenceManager.getDefaultSharedPreferences(this);
      selectedImagePath1 = imagepath1.getString("picturePath1", "picturePath1");
  
  
      SharedPreferences imagepath2 = PreferenceManager.getDefaultSharedPreferences(this);
      selectedImagePath2 = imagepath2.getString("picturePath2", "picturePath2");
  
      SharedPreferences imagepath3 = PreferenceManager.getDefaultSharedPreferences(this);
      selectedImagePath3 = imagepath3.getString("picturePath3", "picturePath3");
  
      SharedPreferences imagepath4 = PreferenceManager.getDefaultSharedPreferences(this);
      selectedImagePath4 = imagepath4.getString("picturePath4", "picturePath4");
  
  
      Bitmap thumbnail1 = (BitmapFactory.decodeFile(selectedImagePath1));
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      thumbnail1.compress(Bitmap.CompressFormat.JPEG, 90, stream);
  
      Bitmap thumbnail2 = (BitmapFactory.decodeFile(selectedImagePath2));
      ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
      thumbnail2.compress(Bitmap.CompressFormat.JPEG, 90, stream1);
  
      Bitmap thumbnail3 = (BitmapFactory.decodeFile(selectedImagePath3));
      ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
      thumbnail2.compress(Bitmap.CompressFormat.JPEG, 90, stream2);
  
      Bitmap thumbnail4 = (BitmapFactory.decodeFile(selectedImagePath4));
      ByteArrayOutputStream stream3 = new ByteArrayOutputStream();
      thumbnail4.compress(Bitmap.CompressFormat.JPEG, 90, stream3);
  
  
      imageview1.setImageBitmap(thumbnail1);
      thumbnail1.recycle();
      imageview2.setImageBitmap(thumbnail2);
      imageview3.setImageBitmap(thumbnail3 );
      imageview4.setImageBitmap(thumbnail4);
  </code></pre>