小编Don*_*ing的帖子

在zipentry java中查找文件

我试图在一个zip文件中找到一个文件并将其作为一个文件InputStream.所以这就是我到目前为止所做的事情,我不确定我是否正确地做到了.

这是一个样本,因为原件略长,但这是主要组件......

public InputStream Search_Image(String file_located, ZipInputStream zip) 
    throws IOException {
    for (ZipEntry zip_e = zip.getNextEntry(); zip_e != null ; zip_e = zip.getNextEntry()) {
        if (file_located.equals(zip_e.getName())) {
            return zip;
        }
        if (zip_e.isDirectory()) {
            Search_Image(file_located, zip); 
        }
    }
    return null;
}
Run Code Online (Sandbox Code Playgroud)

现在我面临的主要问题是,ZipInputStreamin Search_Image与原始组件相同ZipInputStream......

if(zip_e.isDirectory()) {
    //"zip" is the same as the original I need a change here to find folders again.
    Search_Image(file_located, zip); 
}
Run Code Online (Sandbox Code Playgroud)

现在问题是,如何获得ZipInputStream新的zip_entry?如果我在我的方法中做了任何错误,请加入,因为我仍然缺乏这个类的逻辑.

java zipinputstream

4
推荐指数
2
解决办法
1万
查看次数

获取图像输入流的大小

我需要获得输入流中找到的图像的高度和宽度.这是我做的:

private Boolean testSize(InputStream inputStream){
        BitmapFactory.Options Bitmp_Options = new BitmapFactory.Options();
        Bitmp_Options.inJustDecodeBounds = true;
        BitmapFactory.decodeResourceStream(getResources(), new TypedValue(), inputStream, new Rect(), Bitmp_Options);
        int currentImageHeight = Bitmp_Options.outHeight;
        int currentImageWidth = Bitmp_Options.outWidth;
        Bitmp_Options.inJustDecodeBounds = false;
    if(currentImageHeight < 200 || currentImageWidth < 200){
        Object obj = map.remove(pageCounter);
        Log.i("Page recycled", obj.toString());
        return true;
    }
    return false;}
Run Code Online (Sandbox Code Playgroud)

跳到问题点:

即使我在下面的第二个方法计算后强制它为false,它也会更改BitmapFactory.Options.

private Bitmap getBitmap(InputStream InpStream){
    Bitmap originalBitmap = BitmapFactory.decodeStream(InpStream);//Null.
    return originalBitmap;
}
Run Code Online (Sandbox Code Playgroud)

现在我的问题是有另一种方法从输入流获取图像的大小和宽度?我真的需要帮助,非常感谢任何帮助.

                ZipInputStream zip = null;
                zip = new ZipInputStream(new FileInputStream(getFileLocation()));
                for(ZipEntry zip_e = zip.getNextEntry(); zip_e != null …
Run Code Online (Sandbox Code Playgroud)

android inputstream bitmap bitmapfactory

4
推荐指数
1
解决办法
3999
查看次数

使用BitmapFactory.Options会导致BitmapFactory中的更改

我想要实现的是能够从输入流计算位图的高度和宽度,而无需实际更改BitmapFactory.Options

这就是我做的:

private Boolean testSize(InputStream inputStream){
    BitmapFactory.Options Bitmp_Options = new BitmapFactory.Options();
    Bitmp_Options.inJustDecodeBounds = true;
    BitmapFactory.decodeResourceStream(getResources(), new TypedValue(), inputStream, new Rect(), Bitmp_Options);
    int currentImageHeight = Bitmp_Options.outHeight;
    int currentImageWidth = Bitmp_Options.outWidth;
    if(currentImageHeight > 200 || currentImageWidth > 200){
        Object obj = map.remove(pageCounter);
        Log.i("Page recycled", obj.toString());
        return true;
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

现在这里的主要问题是它将BitmapFactory.Options更改为无法正确解码的状态.

我的问题是有另一种重置BitmapFactory.Options的方法吗?或其他可能的解决方案

另一种方法:(注意:当应用top方法时,originalBitmap为null)

这是我原来的代码:

Bitmap originalBitmap = BitmapFactory.decodeStream(InpStream);
Run Code Online (Sandbox Code Playgroud)

应用Deev和Nobu Game的建议:(没有变化)

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    Bitmap originalBitmap = BitmapFactory.decodeStream(InpStream,null,options);
Run Code Online (Sandbox Code Playgroud)

android bitmap bitmapfactory

0
推荐指数
1
解决办法
1291
查看次数