Android 如何获取sd卡中缩略图的路径

Android 如何获取sd卡中缩略图的路径,android,Android,我使用下面的代码来获取sd卡中的文件pathof图像 File[] f = (Environment.getExternalStorageDirectory()).listFiles(); int i; for(i = 0; i < f.length; i++) { if(f[i].isFile()) { if(isPhoto(f[i].getName())) { Filepath.add(f[i].getAbsolutePath()); } } else { //recursive }

我使用下面的代码来获取sd卡中的文件pathof图像

File[] f = (Environment.getExternalStorageDirectory()).listFiles();
int i;
for(i = 0; i < f.length; i++) {
if(f[i].isFile()) {
if(isPhoto(f[i].getName())) {
Filepath.add(f[i].getAbsolutePath());
}
}
else {
//recursive
}
}
File[]f=(Environment.getExternalStorageDirectory()).listFiles();
int i;
对于(i=0;i
我想通过知道原始图像路径来获得图像缩略图的路径。
如何操作?

您可以制作自己的缩略图:

byte[] imageData = null;

    try     
    {

        final int THUMBNAIL_SIZE = 64;

        FileInputStream fis = new FileInputStream(fileName);
        Bitmap imageBitmap = BitmapFactory.decodeStream(fis);

        imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();  
        imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        imageData = baos.toByteArray();

    }
    catch(Exception ex) {

    }

您可以制作自己的缩略图:

byte[] imageData = null;

    try     
    {

        final int THUMBNAIL_SIZE = 64;

        FileInputStream fis = new FileInputStream(fileName);
        Bitmap imageBitmap = BitmapFactory.decodeStream(fis);

        imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();  
        imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        imageData = baos.toByteArray();

    }
    catch(Exception ex) {

    }

您可以从如下文件中获取Uri:

Uri uri = Uri.fromFile(new File("/mnt/images/abc.jpg"));
Bitmap thumbnail = getPreview(uri);
And the following function gives you the thumbnail:

Bitmap getPreview(URI uri) {
    File image = new File(uri);

    BitmapFactory.Options bounds = new BitmapFactory.Options();
    bounds.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(image.getPath(), bounds);
    if ((bounds.outWidth == -1) || (bounds.outHeight == -1))
        return null;

    int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight
            : bounds.outWidth;

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inSampleSize = originalSize / THUMBNAIL_SIZE;
    return BitmapFactory.decodeFile(image.getPath(), opts);     
}

您可以从如下文件中获取Uri:

Uri uri = Uri.fromFile(new File("/mnt/images/abc.jpg"));
Bitmap thumbnail = getPreview(uri);
And the following function gives you the thumbnail:

Bitmap getPreview(URI uri) {
    File image = new File(uri);

    BitmapFactory.Options bounds = new BitmapFactory.Options();
    bounds.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(image.getPath(), bounds);
    if ((bounds.outWidth == -1) || (bounds.outHeight == -1))
        return null;

    int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight
            : bounds.outWidth;

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inSampleSize = originalSize / THUMBNAIL_SIZE;
    return BitmapFactory.decodeFile(image.getPath(), opts);     
}