开发者

How to show a pic saved in SD on a view?

开发者 https://www.devze.com 2023-02-22 04:24 出处:网络
I\'m trying to show a pic t开发者_运维问答hat I\'m generated before with the camera and I would like to show that pic in another activity but I don\'t know how to retrieve the image and show it on the

I'm trying to show a pic t开发者_运维问答hat I'm generated before with the camera and I would like to show that pic in another activity but I don't know how to retrieve the image and show it on the view.


Take a look at this . This would help you in locating the root of sdcard and also check if its accessible. If you are developing on a device, make sure your sdcard is not mounted on your pc.


Try to save the location that where you will save it, before actually save.

String path= Environment.getExternalStorageDirectory()+"/folderYouWant/";
            File file = new  File(path);
            if (! file.exists()) 
                file.mkdirs();

Then, define a name for the image, and concat it on path, like this:

String fullAddres=path+imageName+".jpg";
File out = new File(file,imageName+".jpg");
Uri output = Uri.fromFile(out);

Then, just use the camera Intent

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT , output);              
            startActivityForResult(intent, 2);

Now you know where you saved your file, and it´s very simple to load the image.

Like this:

Bitmap bitmap = BitmapFactory.decodeFile(fullAdress); 
            imageWidget.setBackgroundDrawable(null);
            imageWidget.setImageBitmap(bitmap);

If the image is much larger than the widget, take a look here:

0

精彩评论

暂无评论...
验证码 换一张
取 消