我分两个步骤解码jpeg.
>检查边界,必要时确定比例.
>在屏幕限制内解码.
public static Bitmap decodeSampledBitmapFrominputStream(inputStream data, int reqWIDth, int reqHeight){ // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(data, null, options); // Calculate inSampleSize options.inSampleSize = Util.getExactSampleSize(options, reqWIDth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; try { // Todo: This works, but is there a better way? if (data instanceof fileinputStream) ((fileinputStream)data).getChannel().position(0); else data.reset(); } catch (IOException e) { e.printstacktrace(); return null; } return BitmapFactory.decodeStream(data, null, options);}
当基础流是fileinputStream时,它将在reset()上崩溃,并带有:
java.io.IOException: Mark has been invalIDated.
因此,我添加了instanceof部分以手动重置fileinputStreams的位置,但这似乎是一个很尴尬的解决方案.有没有办法正确重置封装fileinputStream的BufferedinputStream?
解决方法:
使用inputStream.reset之前,必须先调用inputStream.mark,以标记要稍后返回的位置.
总结以上是内存溢出为你收集整理的java-重置BufferedInputStream保留一个FileInputStream全部内容,希望文章能够帮你解决java-重置BufferedInputStream保留一个FileInputStream所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)