Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在不复制完整图像的情况下,从连接到android的USB OTG存储中获取图像的缩略图_Android_Android 6.0 Marshmallow_Usb Otg_Nexus6 - Fatal编程技术网

有没有办法在不复制完整图像的情况下,从连接到android的USB OTG存储中获取图像的缩略图

有没有办法在不复制完整图像的情况下,从连接到android的USB OTG存储中获取图像的缩略图,android,android-6.0-marshmallow,usb-otg,nexus6,Android,Android 6.0 Marshmallow,Usb Otg,Nexus6,我正在尝试从连接到手机(Nexus 6)的usb驱动器导入所选图像,该手机未将pendrive显示为外部存储目录。我使用了这个图书馆: 使用此库时,我必须首先将所有图像从USB复制到本地缓存,然后从那里我可以显示缩略图以选择要导入的图像。我不想复制所有图像,我只想获取缩略图并仅复制选定的图像。那么有没有办法从USB存储中获取缩略图呢。我觉得,ES file explorer和其他浏览器(无论哪个)能够检测usb pendrive,它们不是复制文件来显示缩略图。是的,你可以 Bitmap getT

我正在尝试从连接到手机(Nexus 6)的usb驱动器导入所选图像,该手机未将pendrive显示为外部存储目录。我使用了这个图书馆: 使用此库时,我必须首先将所有图像从USB复制到本地缓存,然后从那里我可以显示缩略图以选择要导入的图像。我不想复制所有图像,我只想获取缩略图并仅复制选定的图像。那么有没有办法从USB存储中获取缩略图呢。我觉得,ES file explorer和其他浏览器(无论哪个)能够检测usb pendrive,它们不是复制文件来显示缩略图。

是的,你可以

Bitmap getThumbnail(UsbFile file,int targetWidth,int targetHeight){

        InputStream is = UsbFileStreamFactory.createBufferedInputStream(file,mSelectedDevice.getPartitions().get(0).getFileSystem());
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;

        BitmapFactory.decodeStream(is, null, options);

        Boolean scaleByHeight = Math.abs(options.outHeight - targetHeight) >= Math.abs(options.outWidth - targetWidth);

        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 / targetHeight
                    : options.outWidth / targetWidth;
            options.inSampleSize =
                    (int)Math.pow(2d, Math.floor(
                            Math.log(sampleSize)/Math.log(2d)));
        }

        // Do the actual decoding
        options.inJustDecodeBounds = false;

        // Let's load just the part of the image necessary for creating the thumbnail, not the whole image
        Bitmap thumbnail = BitmapFactory.decodeStream(is, null, options);
        return thumbnail;
    }
位图获取缩略图(UsbFile文件,int-targetWidth,int-targetLight){ InputStream=UsbFileStreamFactory.createBufferedInputStream(文件,mSelectedDevice.getPartitions().get(0.getFileSystem()); BitmapFactory.Options=new-BitmapFactory.Options(); options.inJustDecodeBounds=true; 解码流(is,null,options); 布尔scaleByHeight=Math.abs(options.outHeight-targetHeight)>=Math.abs(options.outWidth-targetWidth); 如果(options.outHeight*options.outHeight*2>=200*200*2){ //加载,缩放到最小的2次方即可