setImageBitmap not displaying












1















On click, my app gives choice between camera and gallery and that picture is then displayed in an ImageView. I originally tried to display the full image and then tried to use the bitmap way but nothing works. I just get a blank ImageView. Please give me some guidance as to what I'm doing wrong and ask for clarifications if necessary:



Camera/gallery photo code:



Uri outputFileUri;
private void openImageIntent() {
// Determine Uri of camera image to save.
final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MyDir" + File.separator);
root.mkdirs();
final String fname = "img_" + System.currentTimeMillis() + ".jpg";
final File sdImageMainDirectory = new File(root, fname);
outputFileUri = Uri.fromFile(sdImageMainDirectory);
// Camera.
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for(ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
cameraIntents.add(intent);
}
// Filesystem.
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");
// Add the camera options.
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable{}));
startActivityForResult(chooserIntent, 0);
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent returnIntent) {
super.onActivityResult(resultCode, requestCode, returnIntent);
if(requestCode == 0) {
if(resultCode == RESULT_OK) {
final boolean isCamera;
if(returnIntent == null) {
isCamera = true;
}
else
{
final String action = returnIntent.getAction();
if(action == null) {
isCamera = false;
}
else {
isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
}
}
Uri selectedImageUri;
if(isCamera) {
selectedImageUri = outputFileUri;
mainImage.setImageURI(selectedImageUri); //trying full image
}
else {
selectedImageUri = returnIntent == null ? null : returnIntent.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
mainImage.setImageBitmap(bitmap); //trying bitmap
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}









share|improve this question



























    1















    On click, my app gives choice between camera and gallery and that picture is then displayed in an ImageView. I originally tried to display the full image and then tried to use the bitmap way but nothing works. I just get a blank ImageView. Please give me some guidance as to what I'm doing wrong and ask for clarifications if necessary:



    Camera/gallery photo code:



    Uri outputFileUri;
    private void openImageIntent() {
    // Determine Uri of camera image to save.
    final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MyDir" + File.separator);
    root.mkdirs();
    final String fname = "img_" + System.currentTimeMillis() + ".jpg";
    final File sdImageMainDirectory = new File(root, fname);
    outputFileUri = Uri.fromFile(sdImageMainDirectory);
    // Camera.
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for(ResolveInfo res : listCam) {
    final String packageName = res.activityInfo.packageName;
    final Intent intent = new Intent(captureIntent);
    intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
    intent.setPackage(packageName);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    cameraIntents.add(intent);
    }
    // Filesystem.
    final Intent galleryIntent = new Intent();
    galleryIntent.setType("image/*");
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
    // Chooser of filesystem options.
    final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");
    // Add the camera options.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable{}));
    startActivityForResult(chooserIntent, 0);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent returnIntent) {
    super.onActivityResult(resultCode, requestCode, returnIntent);
    if(requestCode == 0) {
    if(resultCode == RESULT_OK) {
    final boolean isCamera;
    if(returnIntent == null) {
    isCamera = true;
    }
    else
    {
    final String action = returnIntent.getAction();
    if(action == null) {
    isCamera = false;
    }
    else {
    isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    }
    }
    Uri selectedImageUri;
    if(isCamera) {
    selectedImageUri = outputFileUri;
    mainImage.setImageURI(selectedImageUri); //trying full image
    }
    else {
    selectedImageUri = returnIntent == null ? null : returnIntent.getData();
    try {
    Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
    mainImage.setImageBitmap(bitmap); //trying bitmap
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    }
    }









    share|improve this question

























      1












      1








      1


      1






      On click, my app gives choice between camera and gallery and that picture is then displayed in an ImageView. I originally tried to display the full image and then tried to use the bitmap way but nothing works. I just get a blank ImageView. Please give me some guidance as to what I'm doing wrong and ask for clarifications if necessary:



      Camera/gallery photo code:



      Uri outputFileUri;
      private void openImageIntent() {
      // Determine Uri of camera image to save.
      final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MyDir" + File.separator);
      root.mkdirs();
      final String fname = "img_" + System.currentTimeMillis() + ".jpg";
      final File sdImageMainDirectory = new File(root, fname);
      outputFileUri = Uri.fromFile(sdImageMainDirectory);
      // Camera.
      final List<Intent> cameraIntents = new ArrayList<Intent>();
      final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      final PackageManager packageManager = getPackageManager();
      final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
      for(ResolveInfo res : listCam) {
      final String packageName = res.activityInfo.packageName;
      final Intent intent = new Intent(captureIntent);
      intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
      intent.setPackage(packageName);
      intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
      cameraIntents.add(intent);
      }
      // Filesystem.
      final Intent galleryIntent = new Intent();
      galleryIntent.setType("image/*");
      galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
      // Chooser of filesystem options.
      final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");
      // Add the camera options.
      chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable{}));
      startActivityForResult(chooserIntent, 0);
      }


      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent returnIntent) {
      super.onActivityResult(resultCode, requestCode, returnIntent);
      if(requestCode == 0) {
      if(resultCode == RESULT_OK) {
      final boolean isCamera;
      if(returnIntent == null) {
      isCamera = true;
      }
      else
      {
      final String action = returnIntent.getAction();
      if(action == null) {
      isCamera = false;
      }
      else {
      isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      }
      }
      Uri selectedImageUri;
      if(isCamera) {
      selectedImageUri = outputFileUri;
      mainImage.setImageURI(selectedImageUri); //trying full image
      }
      else {
      selectedImageUri = returnIntent == null ? null : returnIntent.getData();
      try {
      Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
      mainImage.setImageBitmap(bitmap); //trying bitmap
      } catch (IOException e) {
      e.printStackTrace();
      }
      }
      }
      }
      }









      share|improve this question














      On click, my app gives choice between camera and gallery and that picture is then displayed in an ImageView. I originally tried to display the full image and then tried to use the bitmap way but nothing works. I just get a blank ImageView. Please give me some guidance as to what I'm doing wrong and ask for clarifications if necessary:



      Camera/gallery photo code:



      Uri outputFileUri;
      private void openImageIntent() {
      // Determine Uri of camera image to save.
      final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MyDir" + File.separator);
      root.mkdirs();
      final String fname = "img_" + System.currentTimeMillis() + ".jpg";
      final File sdImageMainDirectory = new File(root, fname);
      outputFileUri = Uri.fromFile(sdImageMainDirectory);
      // Camera.
      final List<Intent> cameraIntents = new ArrayList<Intent>();
      final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      final PackageManager packageManager = getPackageManager();
      final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
      for(ResolveInfo res : listCam) {
      final String packageName = res.activityInfo.packageName;
      final Intent intent = new Intent(captureIntent);
      intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
      intent.setPackage(packageName);
      intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
      cameraIntents.add(intent);
      }
      // Filesystem.
      final Intent galleryIntent = new Intent();
      galleryIntent.setType("image/*");
      galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
      // Chooser of filesystem options.
      final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");
      // Add the camera options.
      chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable{}));
      startActivityForResult(chooserIntent, 0);
      }


      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent returnIntent) {
      super.onActivityResult(resultCode, requestCode, returnIntent);
      if(requestCode == 0) {
      if(resultCode == RESULT_OK) {
      final boolean isCamera;
      if(returnIntent == null) {
      isCamera = true;
      }
      else
      {
      final String action = returnIntent.getAction();
      if(action == null) {
      isCamera = false;
      }
      else {
      isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      }
      }
      Uri selectedImageUri;
      if(isCamera) {
      selectedImageUri = outputFileUri;
      mainImage.setImageURI(selectedImageUri); //trying full image
      }
      else {
      selectedImageUri = returnIntent == null ? null : returnIntent.getData();
      try {
      Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
      mainImage.setImageBitmap(bitmap); //trying bitmap
      } catch (IOException e) {
      e.printStackTrace();
      }
      }
      }
      }
      }






      android android-layout imageview






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 20 '16 at 3:45









      rafvasqrafvasq

      5291725




      5291725
























          4 Answers
          4






          active

          oldest

          votes


















          1














          If you want to take image from camera you can go with this process:



          public void fromCamera(){

          String path= Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera/";
          File file = new File(path,"IMG_"+System.currentTimeMillis()+".jpg");
          file.getParentFile().mkdirs();
          try {
          file.createNewFile();
          }catch (IOException e) {
          e.printStackTrace();
          }
          mPicCaptureUri = Uri.fromFile(file);
          Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
          intent.putExtra(MediaStore.EXTRA_OUTPUT, mPicCaptureUri);
          startActivityForResult(intent, REQUEST_CAMERA);

          }


          And if you want image from gallery then :



          Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
          intent.setType("image/*");
          startActivityForResult(Intent.createChooser(intent, getString(R.string.select_file)), REQUEST_GALLERY);


          On your onActivityResult you can get the image path of selected one and set image in image view....



          @Override
          public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);

          if(resultCode == RESULT_OK){
          if (requestCode == REQUEST_GALLERY && data != null && data.getData() != null) {

          Uri selectedImageUri = data.getData();

          //do set your image here


          }else if(requestCode == REQUEST_CAMERA){

          if(mPicCaptureUri!=null){
          //do try to set image here
          }
          }
          }
          }


          don't forgrt to define mPicCaptureUri at the top as:



          private Uri mPicCaptureUri = null;


          You can take idea from above code ..it might help you






          share|improve this answer































            1














            your code is 2000000000000000% ok i test it myself



            Your problem is your ImageView can't show image because of image size. I try this code with ImageView like this



                <ImageView
            android:id="@+id/mainImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/abc_ab_bottom_solid_dark_holo" />


            If you use height and width with dp like this



                android:layout_width="100dp"
            android:layout_height="100dp"


            You need to compress the Bitmap to show it in ImageView.
            Edit your code to conversion



            if(isCamera) {
            selectedImageUri = outputFileUri;
            try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);//You can use this bitmap if need full image to further use
            Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, 600 ,600, true);//this bitmap2 you can use only for display
            mainImage.setImageBitmap(bitmap2); //trying full image
            } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            }

            }
            else {
            selectedImageUri = returnIntent == null ? null : returnIntent.getData();
            try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
            bitmap = Bitmap.createScaledBitmap(bitmap, 600 ,600, true);
            mainImage.setImageBitmap(bitmap); //trying bitmap
            } catch (IOException e) {
            e.printStackTrace();
            }
            }





            share|improve this answer

































              0














              Now you could use Picasso Library :D



              Picasso.with(context)
              .load(item.getPhotoUri())
              .resize(512,512)
              .placeholder(R.drawable.noimage)
              .error(R.drawable.error_image)
              .into(photo);





              share|improve this answer

































                0














                This mostly happens due to image being too big to be rendered by bitmap within that span of nano second during runtime, so you won't see it. Use a library called Glide. It solved all my image issues in Android including performance when there are hundreds of images to be displayed in a single list or grid.






                share|improve this answer























                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38471963%2fsetimagebitmap-not-displaying%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  1














                  If you want to take image from camera you can go with this process:



                  public void fromCamera(){

                  String path= Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera/";
                  File file = new File(path,"IMG_"+System.currentTimeMillis()+".jpg");
                  file.getParentFile().mkdirs();
                  try {
                  file.createNewFile();
                  }catch (IOException e) {
                  e.printStackTrace();
                  }
                  mPicCaptureUri = Uri.fromFile(file);
                  Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                  intent.putExtra(MediaStore.EXTRA_OUTPUT, mPicCaptureUri);
                  startActivityForResult(intent, REQUEST_CAMERA);

                  }


                  And if you want image from gallery then :



                  Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                  intent.setType("image/*");
                  startActivityForResult(Intent.createChooser(intent, getString(R.string.select_file)), REQUEST_GALLERY);


                  On your onActivityResult you can get the image path of selected one and set image in image view....



                  @Override
                  public void onActivityResult(int requestCode, int resultCode, Intent data) {
                  super.onActivityResult(requestCode, resultCode, data);

                  if(resultCode == RESULT_OK){
                  if (requestCode == REQUEST_GALLERY && data != null && data.getData() != null) {

                  Uri selectedImageUri = data.getData();

                  //do set your image here


                  }else if(requestCode == REQUEST_CAMERA){

                  if(mPicCaptureUri!=null){
                  //do try to set image here
                  }
                  }
                  }
                  }


                  don't forgrt to define mPicCaptureUri at the top as:



                  private Uri mPicCaptureUri = null;


                  You can take idea from above code ..it might help you






                  share|improve this answer




























                    1














                    If you want to take image from camera you can go with this process:



                    public void fromCamera(){

                    String path= Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera/";
                    File file = new File(path,"IMG_"+System.currentTimeMillis()+".jpg");
                    file.getParentFile().mkdirs();
                    try {
                    file.createNewFile();
                    }catch (IOException e) {
                    e.printStackTrace();
                    }
                    mPicCaptureUri = Uri.fromFile(file);
                    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, mPicCaptureUri);
                    startActivityForResult(intent, REQUEST_CAMERA);

                    }


                    And if you want image from gallery then :



                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType("image/*");
                    startActivityForResult(Intent.createChooser(intent, getString(R.string.select_file)), REQUEST_GALLERY);


                    On your onActivityResult you can get the image path of selected one and set image in image view....



                    @Override
                    public void onActivityResult(int requestCode, int resultCode, Intent data) {
                    super.onActivityResult(requestCode, resultCode, data);

                    if(resultCode == RESULT_OK){
                    if (requestCode == REQUEST_GALLERY && data != null && data.getData() != null) {

                    Uri selectedImageUri = data.getData();

                    //do set your image here


                    }else if(requestCode == REQUEST_CAMERA){

                    if(mPicCaptureUri!=null){
                    //do try to set image here
                    }
                    }
                    }
                    }


                    don't forgrt to define mPicCaptureUri at the top as:



                    private Uri mPicCaptureUri = null;


                    You can take idea from above code ..it might help you






                    share|improve this answer


























                      1












                      1








                      1







                      If you want to take image from camera you can go with this process:



                      public void fromCamera(){

                      String path= Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera/";
                      File file = new File(path,"IMG_"+System.currentTimeMillis()+".jpg");
                      file.getParentFile().mkdirs();
                      try {
                      file.createNewFile();
                      }catch (IOException e) {
                      e.printStackTrace();
                      }
                      mPicCaptureUri = Uri.fromFile(file);
                      Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                      intent.putExtra(MediaStore.EXTRA_OUTPUT, mPicCaptureUri);
                      startActivityForResult(intent, REQUEST_CAMERA);

                      }


                      And if you want image from gallery then :



                      Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                      intent.setType("image/*");
                      startActivityForResult(Intent.createChooser(intent, getString(R.string.select_file)), REQUEST_GALLERY);


                      On your onActivityResult you can get the image path of selected one and set image in image view....



                      @Override
                      public void onActivityResult(int requestCode, int resultCode, Intent data) {
                      super.onActivityResult(requestCode, resultCode, data);

                      if(resultCode == RESULT_OK){
                      if (requestCode == REQUEST_GALLERY && data != null && data.getData() != null) {

                      Uri selectedImageUri = data.getData();

                      //do set your image here


                      }else if(requestCode == REQUEST_CAMERA){

                      if(mPicCaptureUri!=null){
                      //do try to set image here
                      }
                      }
                      }
                      }


                      don't forgrt to define mPicCaptureUri at the top as:



                      private Uri mPicCaptureUri = null;


                      You can take idea from above code ..it might help you






                      share|improve this answer













                      If you want to take image from camera you can go with this process:



                      public void fromCamera(){

                      String path= Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera/";
                      File file = new File(path,"IMG_"+System.currentTimeMillis()+".jpg");
                      file.getParentFile().mkdirs();
                      try {
                      file.createNewFile();
                      }catch (IOException e) {
                      e.printStackTrace();
                      }
                      mPicCaptureUri = Uri.fromFile(file);
                      Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                      intent.putExtra(MediaStore.EXTRA_OUTPUT, mPicCaptureUri);
                      startActivityForResult(intent, REQUEST_CAMERA);

                      }


                      And if you want image from gallery then :



                      Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                      intent.setType("image/*");
                      startActivityForResult(Intent.createChooser(intent, getString(R.string.select_file)), REQUEST_GALLERY);


                      On your onActivityResult you can get the image path of selected one and set image in image view....



                      @Override
                      public void onActivityResult(int requestCode, int resultCode, Intent data) {
                      super.onActivityResult(requestCode, resultCode, data);

                      if(resultCode == RESULT_OK){
                      if (requestCode == REQUEST_GALLERY && data != null && data.getData() != null) {

                      Uri selectedImageUri = data.getData();

                      //do set your image here


                      }else if(requestCode == REQUEST_CAMERA){

                      if(mPicCaptureUri!=null){
                      //do try to set image here
                      }
                      }
                      }
                      }


                      don't forgrt to define mPicCaptureUri at the top as:



                      private Uri mPicCaptureUri = null;


                      You can take idea from above code ..it might help you







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jul 20 '16 at 4:08









                      RitenRiten

                      1,66611423




                      1,66611423

























                          1














                          your code is 2000000000000000% ok i test it myself



                          Your problem is your ImageView can't show image because of image size. I try this code with ImageView like this



                              <ImageView
                          android:id="@+id/mainImage"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_alignParentTop="true"
                          android:layout_centerHorizontal="true"
                          android:src="@drawable/abc_ab_bottom_solid_dark_holo" />


                          If you use height and width with dp like this



                              android:layout_width="100dp"
                          android:layout_height="100dp"


                          You need to compress the Bitmap to show it in ImageView.
                          Edit your code to conversion



                          if(isCamera) {
                          selectedImageUri = outputFileUri;
                          try {
                          Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);//You can use this bitmap if need full image to further use
                          Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, 600 ,600, true);//this bitmap2 you can use only for display
                          mainImage.setImageBitmap(bitmap2); //trying full image
                          } catch (Exception e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                          }

                          }
                          else {
                          selectedImageUri = returnIntent == null ? null : returnIntent.getData();
                          try {
                          Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
                          bitmap = Bitmap.createScaledBitmap(bitmap, 600 ,600, true);
                          mainImage.setImageBitmap(bitmap); //trying bitmap
                          } catch (IOException e) {
                          e.printStackTrace();
                          }
                          }





                          share|improve this answer






























                            1














                            your code is 2000000000000000% ok i test it myself



                            Your problem is your ImageView can't show image because of image size. I try this code with ImageView like this



                                <ImageView
                            android:id="@+id/mainImage"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentTop="true"
                            android:layout_centerHorizontal="true"
                            android:src="@drawable/abc_ab_bottom_solid_dark_holo" />


                            If you use height and width with dp like this



                                android:layout_width="100dp"
                            android:layout_height="100dp"


                            You need to compress the Bitmap to show it in ImageView.
                            Edit your code to conversion



                            if(isCamera) {
                            selectedImageUri = outputFileUri;
                            try {
                            Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);//You can use this bitmap if need full image to further use
                            Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, 600 ,600, true);//this bitmap2 you can use only for display
                            mainImage.setImageBitmap(bitmap2); //trying full image
                            } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            }

                            }
                            else {
                            selectedImageUri = returnIntent == null ? null : returnIntent.getData();
                            try {
                            Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
                            bitmap = Bitmap.createScaledBitmap(bitmap, 600 ,600, true);
                            mainImage.setImageBitmap(bitmap); //trying bitmap
                            } catch (IOException e) {
                            e.printStackTrace();
                            }
                            }





                            share|improve this answer




























                              1












                              1








                              1







                              your code is 2000000000000000% ok i test it myself



                              Your problem is your ImageView can't show image because of image size. I try this code with ImageView like this



                                  <ImageView
                              android:id="@+id/mainImage"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_alignParentTop="true"
                              android:layout_centerHorizontal="true"
                              android:src="@drawable/abc_ab_bottom_solid_dark_holo" />


                              If you use height and width with dp like this



                                  android:layout_width="100dp"
                              android:layout_height="100dp"


                              You need to compress the Bitmap to show it in ImageView.
                              Edit your code to conversion



                              if(isCamera) {
                              selectedImageUri = outputFileUri;
                              try {
                              Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);//You can use this bitmap if need full image to further use
                              Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, 600 ,600, true);//this bitmap2 you can use only for display
                              mainImage.setImageBitmap(bitmap2); //trying full image
                              } catch (Exception e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                              }

                              }
                              else {
                              selectedImageUri = returnIntent == null ? null : returnIntent.getData();
                              try {
                              Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
                              bitmap = Bitmap.createScaledBitmap(bitmap, 600 ,600, true);
                              mainImage.setImageBitmap(bitmap); //trying bitmap
                              } catch (IOException e) {
                              e.printStackTrace();
                              }
                              }





                              share|improve this answer















                              your code is 2000000000000000% ok i test it myself



                              Your problem is your ImageView can't show image because of image size. I try this code with ImageView like this



                                  <ImageView
                              android:id="@+id/mainImage"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_alignParentTop="true"
                              android:layout_centerHorizontal="true"
                              android:src="@drawable/abc_ab_bottom_solid_dark_holo" />


                              If you use height and width with dp like this



                                  android:layout_width="100dp"
                              android:layout_height="100dp"


                              You need to compress the Bitmap to show it in ImageView.
                              Edit your code to conversion



                              if(isCamera) {
                              selectedImageUri = outputFileUri;
                              try {
                              Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);//You can use this bitmap if need full image to further use
                              Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, 600 ,600, true);//this bitmap2 you can use only for display
                              mainImage.setImageBitmap(bitmap2); //trying full image
                              } catch (Exception e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                              }

                              }
                              else {
                              selectedImageUri = returnIntent == null ? null : returnIntent.getData();
                              try {
                              Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
                              bitmap = Bitmap.createScaledBitmap(bitmap, 600 ,600, true);
                              mainImage.setImageBitmap(bitmap); //trying bitmap
                              } catch (IOException e) {
                              e.printStackTrace();
                              }
                              }






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jul 20 '16 at 5:10

























                              answered Jul 20 '16 at 4:38







                              user4696837






























                                  0














                                  Now you could use Picasso Library :D



                                  Picasso.with(context)
                                  .load(item.getPhotoUri())
                                  .resize(512,512)
                                  .placeholder(R.drawable.noimage)
                                  .error(R.drawable.error_image)
                                  .into(photo);





                                  share|improve this answer






























                                    0














                                    Now you could use Picasso Library :D



                                    Picasso.with(context)
                                    .load(item.getPhotoUri())
                                    .resize(512,512)
                                    .placeholder(R.drawable.noimage)
                                    .error(R.drawable.error_image)
                                    .into(photo);





                                    share|improve this answer




























                                      0












                                      0








                                      0







                                      Now you could use Picasso Library :D



                                      Picasso.with(context)
                                      .load(item.getPhotoUri())
                                      .resize(512,512)
                                      .placeholder(R.drawable.noimage)
                                      .error(R.drawable.error_image)
                                      .into(photo);





                                      share|improve this answer















                                      Now you could use Picasso Library :D



                                      Picasso.with(context)
                                      .load(item.getPhotoUri())
                                      .resize(512,512)
                                      .placeholder(R.drawable.noimage)
                                      .error(R.drawable.error_image)
                                      .into(photo);






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Sep 6 '17 at 16:38









                                      BakaWaii

                                      3,63321631




                                      3,63321631










                                      answered Sep 6 '17 at 15:50









                                      Omar Alejandro CervantesOmar Alejandro Cervantes

                                      1




                                      1























                                          0














                                          This mostly happens due to image being too big to be rendered by bitmap within that span of nano second during runtime, so you won't see it. Use a library called Glide. It solved all my image issues in Android including performance when there are hundreds of images to be displayed in a single list or grid.






                                          share|improve this answer




























                                            0














                                            This mostly happens due to image being too big to be rendered by bitmap within that span of nano second during runtime, so you won't see it. Use a library called Glide. It solved all my image issues in Android including performance when there are hundreds of images to be displayed in a single list or grid.






                                            share|improve this answer


























                                              0












                                              0








                                              0







                                              This mostly happens due to image being too big to be rendered by bitmap within that span of nano second during runtime, so you won't see it. Use a library called Glide. It solved all my image issues in Android including performance when there are hundreds of images to be displayed in a single list or grid.






                                              share|improve this answer













                                              This mostly happens due to image being too big to be rendered by bitmap within that span of nano second during runtime, so you won't see it. Use a library called Glide. It solved all my image issues in Android including performance when there are hundreds of images to be displayed in a single list or grid.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Nov 21 '18 at 2:18









                                              Vijay Kumar KantaVijay Kumar Kanta

                                              4271616




                                              4271616






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38471963%2fsetimagebitmap-not-displaying%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  鏡平學校

                                                  ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                                                  Guess what letter conforming each word