gpt4 book ai didi

android - 如何将全高清图像设置为 ImageView

转载 作者:行者123 更新时间:2023-11-30 01:36:22 25 4
gpt4 key购买 nike

我想将全高清 (1080x1920) 图像设置到 ImageView。我已经搜索过但没有有效的方法。

public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {

// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);

// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}

public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
Log.d("DUE","Options height: " + height + " - width: " + width);
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {

final int halfHeight = height / 2;
final int halfWidth = width / 2;

// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}

return inSampleSize;
}

或者:

private Bitmap resize(int resId, int width, int height){

BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resId, bmpFactoryOptions);

int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)height);
int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)width);

if (heightRatio > 1 || widthRatio > 1)
{
if (heightRatio > widthRatio)
{
bmpFactoryOptions.inSampleSize = heightRatio;
} else {
bmpFactoryOptions.inSampleSize = widthRatio;
}
}else{
}

bmpFactoryOptions.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeResource(getResources(), resId, bmpFactoryOptions);
return bitmap;
}

我想显示原始图像大小,而不缩小图像大小

你能帮帮我吗?

谢谢大家!

最佳答案

You can use image loading libraries like Universal Image Loader, Fresco.
1) https://github.com/nostra13/Android-Universal-Image-Loader
2) https://github.com/facebook/fresco
3) https://guides.codepath.com/android/Displaying-Images-with-the-Fresco-Library

关于android - 如何将全高清图像设置为 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35054880/

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