如何从Android相机获取缩略图和图像路径?

Kha*_*han 2 android android-intent

通过这种方式

Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)

我通过这种方式在 onActivityResult 中获得位图形式意图,而不是路径!

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(intent, REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)

我可以从意图中获取路径,而不是位图!!,我怎样才能从android相机获取位图(缩略图)和路径?

kal*_*pvs 5

从那里你可以获取图像路径并使用该路径创建一个像这样的缩略图

/**
 * 
 * Returns the given size of the bitmap
 * 
 * @param path
 * @return {@link Bitmap}
 */
private Bitmap getThumbnailBitmap(String path, int thumbnailSize) {
    BitmapFactory.Options bounds = new BitmapFactory.Options();
    bounds.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, 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 / thumbnailSize;
    return BitmapFactory.decodeFile(path, opts);
}
Run Code Online (Sandbox Code Playgroud)

给出你想要的尺寸