当我在我的 android 应用程序中从图库中加载图像时,为啥位图返回较小的图像?

Posted

技术标签:

【中文标题】当我在我的 android 应用程序中从图库中加载图像时,为啥位图返回较小的图像?【英文标题】:When I load an image from gallery in my android application, why does the bitmap return a smaller image?当我在我的 android 应用程序中从图库中加载图像时,为什么位图返回较小的图像? 【发布时间】:2018-06-07 04:38:58 【问题描述】:

我正在从 android 手机的相机中捕捉图像并将其保存在图库中。当我从图库中加载图像时,生成的图像总是小于原始图像。谁能告诉我如何解决这个问题?

图库中的图片是:

从图库加载时android应用程序内部的图片是:

我正在使用以下代码将图像加载到 imageView 中:

BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 2;
    final Bitmap capturedimage1 = BitmapFactory.decodeFile(uri, options);
    BitmapDrawable ob = new BitmapDrawable(getResources(), capturedimage1);
    //capturedImg is the imageView and capturedimage1 is the bitmap image loaded from gallery
    capturedImg.setImageBitmap(capturedimage1);

【问题讨论】:

【参考方案1】:

因为你选择了inSampleSize=2。

【讨论】:

当我没有使用 inSampleSize=2 时,我得到了相同的结果 您的 capturedImg 如何在布局 XML 中声明?具体来说,你设置android:scaleType="centerCrop"吗? 不,我只是在线性布局中使用 imageView。布局的方向是垂直的。 imageView 的重心为中心和 (adjustViewBounds=true)

以上是关于当我在我的 android 应用程序中从图库中加载图像时,为啥位图返回较小的图像?的主要内容,如果未能解决你的问题,请参考以下文章

Android Recycler 视图使用异步任务从图库中加载图像

Android 相机和图库

Android Webview 不会在 webview 中加载我的 FPDF 链接

在 Android 中从内存中加载声音

在Android中加载大文本

当我在 swift 3 中从图库中获取照片时,为啥收藏视图为空?