I'm trying to read an image from my SD Card and I'm not sure if I'm doing it right or not. Need some help please
This is my code for reading it:
String imageInSD = "/sdcard/Hanud/" + c.getString(1) + ".PNG";
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
ImageView myImageView = (ImageView)findViewById(R.id.imageview);
myImageView.setImageBitmap(bitmap);
And this is my main file:
<?xml version="1.0" encoding="utf-8"?>
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- <ImageView
android:id="@+id/image"
android:scaleType="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>-->
<ImageView
android:id="@+id/imageview"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
/>
<TextView
android:id="@+id/myNameText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</WebView>
Most Android phones come preinstalled with at least one file manager app. A file manager app lets you view and work with the files sitting on both internal and SD card storage on your device. This app may be called File Manager, Files, or something similar and should be available in the app drawer of your device.
You can use the SD card reader to copy photo or video files to a computer for viewing. You can also go to Album on the mobile App to download the photo or video files to your phone and view it in the App under “Album.”
In order to fetch the images which are created by my application, we have to make a query on ContentResolver with the INTERNAL_CONTENT_URI. But if you want to get all images that are created by any application then make a query on ContentResolver with EXTERNAL_CONTENT_URI.
You can use the following code:
File sdCard = Environment.getExternalStorageDirectory();
File directory = new File (sdCard.getAbsolutePath() + "/Pictures");
File file = new File(directory, "image_name.jpg"); //or any other format supported
FileInputStream streamIn = new FileInputStream(file);
Bitmap bitmap = BitmapFactory.decodeStream(streamIn); //This gets the image
streamIn.close();
You would need to run FileInputStream in a try/catch block.
It should be:
String imageInSD = Environment.getExternalStorageDirectory().getAbsolutePath() +"/Hanud/" + c.getString(1) + ".PNG";
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
ImageView myImageView = (ImageView)findViewById(R.id.imageview);
myImageView.setImageBitmap(bitmap);
This will ensure you find the correct directory!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With