Reputation: 863
I have saved a image in internal memory. For example I saved it as test.jpg. Now I want to show it in a imageview. I have tried this:
ImageView img = (ImageView)findViewById(R.id.imageView1);
try {
img.setImageDrawable(Drawable.createFromPath("test.jpg"));
} catch (Exception e) {
Log.e(e.toString());
}
And get the following message in LogCat:
SD Card is available for read and write truetrue
Any help or reference please?
Upvotes: 1
Views: 12606
Reputation: 28389
Take a look at the doc..
You don't need to "know" where the image is stored. You just need to hold on to what you saved it as, and then you can read it back again.
The question is... did you save the file there? Or are you confusing this with images that you have compiled into the application? If it's the latter, the documentation also talks about how to read those, they are not the same as files that you have written to the device, they're part of the app package.
Welcome to Stack! If you find answers useful don't forget to upvote them and mark them as "correct" if they solve your problems.
Cheers.
Upvotes: 0
Reputation: 6954
public class AndroidBitmap extends Activity {
private final String imageInSD = "/sdcard/er.PNG";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
ImageView myImageView = (ImageView)findViewById(R.id.imageview);
myImageView.setImageBitmap(bitmap);
}
}
or
final Bitmap bm = BitmapFactory.decodeStream( ..some image.. );
// The openfileOutput() method creates a file on the phone/internal storage in the context of your application
final FileOutputStream fos = openFileOutput("my_new_image.jpg", Context.MODE_PRIVATE); // Use the compress method on the BitMap object to write image to the OutputStream
bm.compress(CompressFormat.JPEG, 90, fos);
hope it works...
Upvotes: 6