gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 08:03:09 25 4
gpt4 key购买 nike

通过这种方式

Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, REQUEST_CODE);

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

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(intent, REQUEST_CODE);

我可以从 intent 获取路径,而不是位图 !!,我如何从 android 相机获取位图(缩略图)和路径?

最佳答案

从那里你可以得到图像路径,使用该路径创建一个像这样的缩略图

/**
*
* 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);
}

给你想要的尺寸

关于android - 如何从android相机获取缩略图和图像路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18183490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com