I am working on a small program that is supposed to :
1. Display images on the SD card
2. Get the image chosen by the User and display it on Canvas.
3. Since the image can be large, sub sample it/ scale it or something
appropriate

I got the first two parts done using the following snippets:

1. By launching an intent such as:
Intent photoPickerIntent = new Intent(
                Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, RQST_CODE);

2. The chosen image URI is received in onActivityResult(..):
Uri chosenImageUri = data.getData();

Now, I can create a Bitmap object from this URI :
Media.getBitmap(this.getContentResolver(),chosenImageUri);

The problem is: I want to resize/sub sample this bitmap. I did a bit
of reading and found a certain
BitmapFactory.Options class that has parameters whereby one can
specify the sample size. This "options" instance can be passed to one
of several overloaded BitmapFactory.decodeXX(..) methods, but none of
these methods take a URI as parameter.

Is there a way to do this?

I even tried this:
BitmapFactory.Options options = new BitmapFactory.Options();
                                options.inSampleSize = 2;

AssetFileDescriptor fileDescriptor =null;
        try {
                fileDescriptor = 
this.getContentResolver().openAssetFileDescriptor
(chosenImageUri,"r");
        } catch (FileNotFoundException e) {
        e.printStackTrace();
        }
        finally{
        try {
        fileDescriptor.close();
                } catch (IOException e) {
                e.printStackTrace();
                }
        }

        mBitmap = BitmapFactory.decodeFileDescriptor
(fileDescriptor.getFileDescriptor(),
                                                null,
                                                options);

But i am still getting null in mBitmap.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to