title: Saving image to SD card then displaying in imageview
body: <p><strong>UPDATE!!</strong></p>
  
  <p>So Lokesh put me on the right path, and showed me that the problem was the size of the file being too large to show in the imageview. I was able to fix the imageview preview problem with the following code under my onActivityResult:</p>
  
  <pre><code>try {
                      Bitmap picture = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getPath()+"/td01.png");
                      int nh = (int) ( picture.getHeight() * (512.0 / picture.getWidth()) );
                      Bitmap scaled = Bitmap.createScaledBitmap(picture, 512, nh, true);
                      Log.v("Path", Environment.getExternalStorageDirectory().getPath()+"/td01.png");    
                      pic1.setImageBitmap(scaled);
                  } catch (Exception e) {
                      Log.e("Error reading file", e.toString());
                  }
  </code></pre>
  
  <p>Thanks Lokesh!</p>
  
  <p>----------------- ORIGINAL ISSUE BELOW THIS LINE -------------------</p>
  
  <p>So I'm trying to both save an image to the SD card for use later, AND display the saved image in an imageview which also serves as the button which takes the photo. Here's the code:</p>
  
  <pre><code>  pic1.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                        Intent camera_intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                        File image1 = new File(Environment.getExternalStorageDirectory(),"td01.png");
                        camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image1));
                        startActivityForResult(camera_intent, CAMERA_PIC_REQUEST1);
                                }
                  });
  </code></pre>
  
  <p>followed by:</p>
  
  <pre><code>    @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          switch(requestCode){
          case 1:
              if(resultCode==RESULT_OK){
                    Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
                    pic1.setImageBitmap(thumbnail);
                  }
          }
  </code></pre>
  
  <p>Now, if I remove the following code from the onclick, it shows the thumbnail as I expect it to:</p>
  
  <pre><code>File image1 = new File(Environment.getExternalStorageDirectory(),"td01.png");
  camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image1));
  </code></pre>
  
  <p>...but without that code, it doesn't save the file to my sd card.</p>
  
  <p>The problem is, if I don't remove that code, it saves the image to my SD Card but immediately crashes before returning to the activity after tapping SAVE in the camera activity, unless I remove the following code from my onActivityResult:</p>
  
  <pre><code>Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
  pic1.setImageBitmap(thumbnail);
  </code></pre>
  
  <p>I've also tried many variations of the following code in my onActivityResult, hoping to display it from the actual file in a different way, but it never works and only shows a blank imageview, but at least in that case the crash doesn't occur, because I removed the get extras get data code:</p>
  
  <pre><code>Bitmap photo1 = BitmapFactory.decodeFile("/sdcard/td01.png");
  pic1.setImageBitmap(photo1);
  </code></pre>
  
  <p>I've been struggling with this for days and am at a loss here. Hope someone can show me what stupid thing I'm doing wrong and explain why this isn't working.</p>
  
  <p>Thanks!</p>