skia : --- SkImageDecoder::Factory returned null

本文详细介绍了在使用Android从URI读取文件进行图片重新解码时遇到的问题,以及如何通过重新获取InputStream来解决错误。提供了代码示例,并讨论了使用InputStream.markSupported()与reset()的方法,但作者分享的是另一种成功解决该问题的方法。

写一个从uri load图片到imageView的功能,在从uri读取文件进行重新decode的时候出现了这个错误,困惑了半天,发现原来是inputStream引起的

	public static Bitmap decodeUri(Context context, Uri uri, int reqWidth, int reqHeight) {
		InputStream input = null;
		Bitmap bitmap = null;
		try {
			input = context.getContentResolver().openInputStream(uri);
			BitmapFactory.Options o = new BitmapFactory.Options();
			o.inJustDecodeBounds = true;
			BitmapFactory.decodeStream(input, null, o);
			input.close();
			input = null;
			
			o.inSampleSize = calculateInSampleSize(o, reqWidth, reqHeight);

			// Decode bitmap with inSampleSize set
			o.inJustDecodeBounds = false;
			input = context.getContentResolver().openInputStream(uri);// 这个地方需要重新获取inputstream,不然就会出现如上错
			bitmap = BitmapFactory.decodeStream(input, null, o);
			input.close();
			input = null;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			try {
				if(input != null) {
					input.close();
				}
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
		return bitmap;
	}


网上有说inputStream.markSupported() 和 inputStream.reset() 搭配使用解决的,但是我没有成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值