0

I have this code to get bitmaps from the user external storage

    /**
 * Get bitmap from input stream
 * @param is
 * @param reqWidth
 * @param reqHeight
 * @return Bitmap
 */
public static Bitmap decodeSampleBitmapFromStream(InputStream is, int reqWidth,
        int reqHeight) {

    BufferedInputStream bis = new BufferedInputStream(is);

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(bis, null, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth,
            reqHeight);

    try {
        bis.reset();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeStream(bis, null, options);
}

It works fine on most of supports but on some I have this warning

07-23 21:06:32.355: D/PowerManagerService(2687): onSensorChanged: light value: 10
07-23 21:06:32.510: W/System.err(26270): java.io.IOException: Mark has been invalidated.
07-23 21:06:32.510: W/System.err(26270):          at java.io.BufferedInputStream.reset(BufferedInputStream.java:371)
07-23 21:06:32.510: W/System.err(26270):          at ant.fileExplorer.FileExplorerAdapter.decodeSampleBitmapFromStream(FileExplorerAdapter.java:168)

This is about this part

try {
        bis.reset();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

And I don't realy understand can't be executed.

Thanks for your help

Ajouve
  • 9,735
  • 26
  • 90
  • 137

1 Answers1

1
public static Bitmap decodeSampleBitmapFromFile(String filePath, int reqWidth,
        int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath,options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth,reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(filePath,options);
}

use the above static method to get bitmap from the external storage

Give the filePath ..... correctly

Venkatesh S
  • 5,466
  • 1
  • 25
  • 30