logo
down
shadow

Image captured from camera not displaying in imageview android


Image captured from camera not displaying in imageview android

By : Habimana Olivier
Date : November 29 2020, 09:01 AM
seems to work fine I have a problem, that when i have taken an image from camera, image not displaying in imageview. , this works for me:
code :
Bitmap myBitmap = BitmapFactory.decodeFile(imagePath);
image.setImageBitmap(myBitmap);


Share : facebook icon twitter icon
Android Saving Captured Image As Android Camera Captured

Android Saving Captured Image As Android Camera Captured


By : RichG
Date : March 29 2020, 07:55 AM
wish helps you Your stack trace seems self-explantory: you are accessing a closed Cursor from indexingForImageMediaStore().
Imageview not displaying image from Camera in Activity

Imageview not displaying image from Camera in Activity


By : user4183
Date : March 29 2020, 07:55 AM
I wish this helpful for you I think you are doing too many things at the same time and not knowing what fails. First try to display the image in the first activity. Once you know how to display the image correctly, you can pass the file path to the second activity. I tried to use your code but it didn't even go the the second activity because mFileUri is always null. Also in your onActivityResult method you should filter the request code not only the resultcode.
I edited your code, remove unused stuff and it works.
code :
public class MainActivity extends Activity {

private String mFileUri;
private final Context mContext = this;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button btnbutton1 = (Button) findViewById(R.id.button1);
    btnbutton1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Uri uri = createPictureFile();
            mFileUri = uri.getEncodedPath();
            Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            startActivityForResult(intent, 100);
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 100 && resultCode == RESULT_OK) {
        if (mFileUri != null) {
            Intent intent = new Intent(mContext, SecondActivity.class);
            intent.putExtra("filepath", mFileUri);
            startActivity(intent);
        }
    }
}

private static File getOutputMediaFile(int type) {

    File mediaStorageDir = new File(Environment.getExternalStorageDirectory(), "DCIM/Camera");

    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            return null;
        }
    }

    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
    File mediaFile;
    if (type == 1) { // image
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
    } else if (type == 2) { // video
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".mp4");
    } else {
        return null;
    }

    return mediaFile;
}

public Uri createPictureFile() {
    String storageState = Environment.getExternalStorageState();
    if (storageState.equals(Environment.MEDIA_MOUNTED)) {
        File pictureDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        pictureDir = new File(pictureDir, "MyApp");

        // Create the storage directory if it does not exist
        if (!pictureDir.exists()) {
            if (!pictureDir.mkdirs()) {
                Log.d("user", "failed to create directory");
                return null;
            }
        }

        //Create a media file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String fileName = pictureDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg";
        File imageFile = new File(fileName);

        // Convert to URI and return
        return Uri.fromFile(imageFile);
    } else {
        Log.d("user", "No media mounted");
        return null;
    }
}
}
public class SecondActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);

    Intent intent = getIntent();
    String filepath = intent.getStringExtra("filepath");

    ImageView imageView = (ImageView) findViewById(R.id.imageView1);

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inSampleSize = 6;
    Bitmap bm = BitmapFactory.decodeFile(filepath, opts);
    imageView.setImageBitmap(bm);
}
}
public class ExifUtil {
/**
 * @see http://sylvana.net/jpegcrop/exif_orientation.html
 */
public static Bitmap rotateBitmap(String src, Bitmap bitmap) {
    try {
        int orientation = getExifOrientation(src);

        if (orientation == 1) {
            return bitmap;
        }

        Matrix matrix = new Matrix();
        switch (orientation) {
            case 2:
                matrix.setScale(-1, 1);
                break;
            case 3:
                matrix.setRotate(180);
                break;
            case 4:
                matrix.setRotate(180);
                matrix.postScale(-1, 1);
                break;
            case 5:
                matrix.setRotate(90);
                matrix.postScale(-1, 1);
                break;
            case 6:
                matrix.setRotate(90);
                break;
            case 7:
                matrix.setRotate(-90);
                matrix.postScale(-1, 1);
                break;
            case 8:
                matrix.setRotate(-90);
                break;
            default:
                return bitmap;
        }

        try {
            Bitmap oriented = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
            bitmap.recycle();
            return oriented;
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
            return bitmap;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return bitmap;
}

private static int getExifOrientation(String src) throws IOException {
    int orientation = 1;

    try {
        /**
         * if your are targeting only api level >= 5
         * ExifInterface exif = new ExifInterface(src);
         * orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
         */
        if (Build.VERSION.SDK_INT >= 5) {
            Class<?> exifClass = Class.forName("android.media.ExifInterface");
            Constructor<?> exifConstructor = exifClass.getConstructor(new Class[] { String.class });
            Object exifInstance = exifConstructor.newInstance(new Object[] { src });
            Method getAttributeInt = exifClass.getMethod("getAttributeInt", new Class[] { String.class, int.class });
            Field tagOrientationField = exifClass.getField("TAG_ORIENTATION");
            String tagOrientation = (String) tagOrientationField.get(null);
            orientation = (Integer) getAttributeInt.invoke(exifInstance, new Object[] { tagOrientation, 1});
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }

    return orientation;
}
Save the image from an ImageView(captured from camera) in my custom defined folder in the INTERNAL MEMORY

Save the image from an ImageView(captured from camera) in my custom defined folder in the INTERNAL MEMORY


By : Hüseyin Çakanlı
Date : March 29 2020, 07:55 AM
wish of those help I have been referring various posts and sites and I have been trying this since 3 days and I cannot figure this out! , Got it working:
Code for saving:
code :
    FileOutputStream outStream = null;
    File sdCard = Environment.getExternalStorageDirectory();
    File dir = new File(sdCard.getAbsolutePath() + "/camtest");
    dir.mkdirs();
    String fileName = String.format("%d.jpg", System.currentTimeMillis());
    File outFile = new File(dir, fileName);
    outStream = new FileOutputStream(outFile);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
    outStream.flush();
    outStream.close();
    refreshGallery(outFile);
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
ImageView is not showing captured Image using Camera in android

ImageView is not showing captured Image using Camera in android


By : SurfBoy Steve
Date : March 29 2020, 07:55 AM
this will help I am trying to choose an image for registration. When clicking the ImageView, the user will be given a choice between taking a picture or choosing from his/her gallery. When the user chooses the gallery option, it will display the selected image. When the user chooses the camera option, the ImageView does not display the image. Below is my code for the OnActivityResult , I think it should be like this
code :
    Bitmap imageBitmap = (Bitmap) extras.get("data");
    mImageView.setImageBitmap(imageBitmap);
android selected camera image through gallery intent is not displaying in imageview

android selected camera image through gallery intent is not displaying in imageview


By : Amith Mandula
Date : October 08 2020, 03:00 AM
Related Posts Related Posts :
  • Save and Retrieve location inside JPEG image
  • Intent share is not able to attach image
  • Search specific nearby places using google places api web services for android
  • How to update app?
  • Is It possible to develop app with react native and make changes in android studio?
  • How to create Motion Splash Screen in Android?
  • Build Gradle Android studio Build Slow
  • Using Android DownloadManager,how do i get file name?
  • Android - How to Load More then 20mb Image in Imageview
  • Notification is not cancelled after calling notification.cancel
  • How to implement the smart-crop feature
  • Null Pointer exception on reading SMS stored in SIM in Android
  • remove google text from google maps in android
  • kivy: My screenmanager code is not working with scrollview
  • Dynamic MpAndroidChart Not Working
  • Yandex Maps return 403 Forbidden using retrofit
  • how set selected spinner item in android studio?
  • Does Picasso library for Android handle image loading while network connectivity is off?
  • colorAccent in Holo Theme
  • Android: animation on layout after button clicked for minimum SDK version of 14
  • Are static variable truly "global" (system-wide) in Android?
  • How to create android snackbar with custom layout
  • Animate a car(Marker) along a path in google map android
  • Default to "compass" (gyroscope) mode when viewing a photosphere
  • Gradle - finished with non-zero exit value 1
  • Android Studio 2.0 Application crash on unmodified Application class
  • Android Studio cursor display error
  • Creating Dagger 2 component to be shared between src/test and src/androidTest
  • Android losing state when screen is OFF and ON again
  • Android Notification.Builder addAction PendingIntent Fragment
  • Use another button instead of back button
  • Android Studio Send string over socket after taking a picture [Google Glass]
  • Realm `access from incorrect thread` error when using shared code between IntentService and AsyncTask (Android)
  • osmdroid plotting current location offline
  • GifAnimationDrawable(Gif file) not playing in ListView
  • Controlling emission of Observable items in unit tests
  • android: Log in Button
  • Gradle github and facebook dependencies can't resolve
  • How can you animate a view back and forth between two states on Android, while supporting backpressure?
  • $(LOCAL_PATH) not returning the path to current directory correctly
  • Error:Cause: com.android.sdklib.repository.FullRevision
  • How to get an offset in RecyclerView ItemDecorator
  • Android toolbar home button not showing
  • TextView keeps popping up
  • Toolbar overlaps below status bar
  • Inflated view not updating
  • Errors of the Manifest
  • How to perform the same operation on several elements in array in doInBackground()
  • see error when use getSupportActionBar().setDisplayHomeAsUpEnabled(true)
  • What the heck is going on with this animation?
  • How to set the color of the counter on a TextInputLayout?
  • Cannot resolve symbol 'GeoJsonLayer '
  • Font file not loading on Libgdx Android
  • Simulate GCM push notifications on Android
  • Google maps provider, Wifi, 3g and GPS
  • Textview animation error
  • I want my FAB to stay at the bottom of the screen
  • How to attach multiple Images with a note taking app in android?
  • How to share xml layout using Intent.ACTION_SEND
  • Is there a default selector for the RecyclerView
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co