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

标签 android android-intent

这样

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/

相关文章:

android - getTargetContext() 和 getContext(在 InstrumentationRegistry 上)有什么区别?

java - HttpURLconnection 持续返回错误 - Android

android - 如何在android中的asynctask中使用glide

android - 通过 Facebook 应用程序打开 Facebook 网络个人资料并不总是有效

android - 相机 Intent 捕获的图片文件在onActivityResult中暂时为空

Java,计算 azure 数据库表中的行数

android - 如何使用设备键盘

android - 以编程方式停用 Android 中的设备管理员?

java - Android:当所有应用程序都发送到后台时如何关闭从我的应用程序打开的应用程序

Android 在 QuickOffice 崩溃中通过 ContentResolver 打开 .docx 文件