Android Bitmap.decodeStream返回null
我试图在我的应用程序中显示图像,但在某些情况下,当我面对Android Bitmap.decodeStream返回null,android,bitmap,decode,Android,Bitmap,Decode,我试图在我的应用程序中显示图像,但在某些情况下,当我面对OutOfMemory异常时,我决定使用inJustDecodeBounds缩放位图。但是当我使用这个代码解码流时,返回null。 你知道为什么吗 File bufferFile = new File(ids.get(position)); FileInputStream fis = new FileInputStream(bufferFile); Cipher cipher = Cipher.getI
OutOfMemory
异常时,我决定使用inJustDecodeBounds
缩放位图。但是当我使用这个代码解码流时,返回null。
你知道为什么吗
File bufferFile = new File(ids.get(position));
FileInputStream fis = new FileInputStream(bufferFile);
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
SecretKeySpec keySpec = new SecretKeySpec("01234567890abcde".getBytes(), "AES");
IvParameterSpec ivSpec = new IvParameterSpec("fedcba9876543210".getBytes());
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
CipherInputStream cis = new CipherInputStream(fis, cipher);
Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(cis, null, options);
Boolean scaleByHeight = Math.abs(options.outHeight - Cards.height) >= Math.abs(options.outWidth - Cards.width);
if(options.outHeight * options.outWidth * 2 >= 200*200*2){
// Load, scaling to smallest power of 2 that'll get it <= desired dimensions
double sampleSize = scaleByHeight
? options.outHeight / Cards.height
: options.outWidth / Cards.width;
options.inSampleSize =
(int)Math.pow(2d, Math.floor(
Math.log(sampleSize)/Math.log(2d)));
}
// Do the actual decoding
options.inJustDecodeBounds = false;
//cis.close();
cis = new CipherInputStream(fis, cipher);
Bitmap img = BitmapFactory.decodeStream(cis, null, options);
cis.close();
((ImageView) convertView.findViewById(R.id.imgView)).setImageBitmap(img);
fis.close();
Runtime.getRuntime().gc();
File bufferFile=新文件(id.get(position));
FileInputStream fis=新的FileInputStream(缓冲文件);
Cipher Cipher=Cipher.getInstance(“AES/CBC/NoPadding”);
SecretKeySpec keySpec=新的SecretKeySpec(“01234567890abcde”.getBytes(),“AES”);
IvParameterSpec ivSpec=新的IvParameterSpec(“fedcba9876543210.getBytes());
cipher.init(cipher.DECRYPT_模式,keySpec,ivSpec);
CipherInputStream cis=新的CipherInputStream(fis,密码);
Options=new-BitmapFactory.Options();
options.inJustDecodeBounds=true;
解码流(cis,null,选项);
布尔scaleByHeight=Math.abs(options.outHeight-Cards.height)>=Math.abs(options.outWidth-Cards.width);
如果(options.outHeight*options.outHeight*2>=200*200*2){
//负载,缩放到最小的2次方,这将得到它也许是你的问题?
bugreport还包含一个您可以尝试的解决方法。我们可以知道ID包含什么吗?图像的路径,例如:“mnt/sdcard/myfolder/images/image.png”