誰かが私がこれを理解するのを手伝ってくれます。他のスレッドやAndroidチュートリアルで推奨されているように、Bitmap.optionsを使用してinSampleのサイズを把握しています。次のコードがスケーリングされたビットマップではなくnullビットマップになるという問題
private int determineCorrectScale(InputStream imageStream){
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(imageStream, null, o);
// The new size we want to scale to
final int REQUIRED_SIZE = 100;
// Find the correct scale value. It should be the power of 2.
int scale = 1;
while (o.outWidth / scale / 2 >= REQUIRED_SIZE && o.outHeight / scale / 2 >= REQUIRED_SIZE) {
scale *= 2;
}
return scale;
}
private String saveScaledBitmapToPhone(Uri imagUri){
InputStream imageStream;
try {
imageStream = getContentResolver().openInputStream(imagUri);
int scale= determineCorrectScale(imageStream);
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = scale;
Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream, null, options );
.
.
.
.
} catch (Exception e) {
return imagUri.toString(); //default
}
}
yourSelectedImageがnullであるという問題。しかし、私がその行をコメントアウトすると
int scale= determineCorrectScale(imageStream);
insampleSizeを8または16、あるいはその他の固定の手動番号に設定すると、すべてが正常に機能します。誰かがこの振る舞いやそれを修正する方法を説明できますか?私の感じでは、静的クラスの2つのOptionsオブジェクトを作成したためだと思いますが、それは単なる推測です。私はまだそれを修正することはできません:(助けてください