title: Decode large base64 string
body: <p>I have created a base64 string from a picture on the SD card using this(below) code, and it works but when I try to decode it (even further below) I get a <code>java.lang.outOfMemoryException</code>, presumably because I am not splitting the string into a reasonable size before I decode it as I am before I encode it. </p>
  
  <pre><code>byte fileContent[] = new byte[3000];
  StringBuilder b = new StringBuilder();
  try{
       FileInputStream fin = new FileInputStream(sel);
       while(fin.read(fileContent) &gt;= 0) {
      b.append(Base64.encodeToString(fileContent, Base64.DEFAULT));
       }
  }catch(IOException e){
  
  }
  </code></pre>
  
  <p>The above code works well, but the problem comes when I try to decode the image with the following code;</p>
  
  <pre><code>byte[] imageAsBytes = Base64.decode(img.getBytes(), Base64.DEFAULT);
  ImageView image = (ImageView)this.findViewById(R.id.ImageView);
  image.setImageBitmap(
      BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)
  );
  </code></pre>
  
  <p>I have tried this way too</p>
  
  <pre><code>byte[] b = Base64.decode(img, Base64.DEFAULT);
  Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
  image.setImageBitmap(bitmap);
  </code></pre>
  
  <p>Now I assume that I need to split the string up into sections like my image encoding code, but I have no clue how to go about doing it.</p>