I don't know whether this is your main problem, but you are closing the
fileDescriptor before you are actually using it Alan Cassar, Software
Engineer | Tel: +356 21334457 | Fax: +356 21 334156 email: alan.cas...@ricston.com | web:ricston.com
Samuh wrote: 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 appropriateI 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 -~----------~----~----~----~------~----~------~--~--- |
- [android-beginners] Creating sub sampled Bitmap Objects for im... Samuh
- [android-beginners] Re: Creating sub sampled Bitmap Objec... Alan Cassar
- [android-beginners] Re: Creating sub sampled Bitmap Objec... zhen guo