3

我有一个 if-else 场景,其中 if-path 使用此代码:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inPurgeable = true;
options.inInputShareable = true;
bitmap = BitmapFactory.decodeResource(getResources(), resourceId, options);

else-path 使用以下代码:

InputStream is = getContentResolver().openInputStream(Uri.fromFile(file));
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inPurgeable = true;
options.inInputShareable = true;
bitmap = BitmapFactory.decodeStream(is, null, options);

现在对我来说,阅读 API、测试和谷歌搜索的简短描述,我不太清楚其中的区别,但似乎有一个微妙的区别。

当应用于 ImageView(在 RelativeLayout 内,在 ScrollView 内)时,第一段代码会缩放以适应屏幕的宽度。第二段代码没有,这是我的问题。它似乎也以某种方式放松了它的纵横比,因为如果我申请:

imageView.setAdjustViewBounds(true);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);

它设法使其适合宽度,但弄乱了高度(使其比应有的短)。任何投入将不胜感激!

(我已经尝试更改第一段代码,看看我是否把其他东西搞砸了,但是这个 if-path 的重写给出了同样的错误:)

BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inPurgeable = true;
options.inInputShareable = true;
bitmap= BitmapFactory.decodeStream(getResources().openRawResource(resourceId), null, options);
4

0 回答 0