Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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 2.2设备上处理的图像大于6 mb,BitmapFactory.decodeStream将返回null_Android - Fatal编程技术网

如果Android 2.2设备上处理的图像大于6 mb,BitmapFactory.decodeStream将返回null

如果Android 2.2设备上处理的图像大于6 mb,BitmapFactory.decodeStream将返回null,android,Android,在我的应用程序中,我需要缩放一幅图像,这可以正常工作。但是当一张大照片出现的时候 然后,decodeStream方法返回null。当前,当映像大于6MB(5616x3744)时,它不工作 有人知道为什么会发生这种情况吗?我能做些什么来解决这个问题 public static Bitmap scaleImage(final String filepath, int height, int width) throws IOException{ if (filepath == null){

在我的应用程序中,我需要缩放一幅图像,这可以正常工作。但是当一张大照片出现的时候 然后,decodeStream方法返回null。当前,当映像大于6MB(5616x3744)时,它不工作

有人知道为什么会发生这种情况吗?我能做些什么来解决这个问题

public static Bitmap scaleImage(final String filepath, int height, int width) throws IOException{

    if (filepath == null){
        Log.e(TAG, "cannot create Thumbnail without file");
        return null;
    }

    File f = new File(filepath);
    InputStream is = new FileInputStream(f); 
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(is, null, options);
    is.close();
    final int imageHeight = options.outHeight;
    final int imageWidth = options.outWidth;
    String imageType = options.outMimeType;

    final int thumbnailHeight = height;
    final int thumbnailWidth = width;

    int heightRatio = Math.round((float) imageHeight) / Math.round((float) thumbnailHeight);
    int widthRatio = Math.round((float) imageWidth) / Math.round((float) thumbnailWidth);
    int inSampleSize = 0;
    if (heightRatio < widthRatio){
        inSampleSize =  heightRatio ;
    }
    else{
        inSampleSize =  widthRatio;
    }

    options.inSampleSize = inSampleSize;
    // Decode bitmap with inSampleSize set
    int retrySteps = 0;
    InputStream is2 = new FileInputStream(f);
    Bitmap bmp = null;
    for (int i = 0; i < 5; i++){
        options.inJustDecodeBounds = false;
        try {
            bmp = BitmapFactory.decodeStream(is2, null, options);
            if (bmp != null){
                i = 10;             
            }
            else{
                System.gc();    
                SystemClock.sleep(i * 1000);
                options.inSampleSize = inSampleSize + 1;
            }

        } catch (OutOfMemoryError e) {
            System.gc();    
            SystemClock.sleep(i * 1000);

        }

    }
    is2.close();        
    return bmp;
public static Bitmap scaleImage(最终字符串文件路径、整数高度、整数宽度)引发IOException{
if(filepath==null){
Log.e(标记“无法创建没有文件的缩略图”);
返回null;
}
文件f=新文件(文件路径);
InputStream is=新文件InputStream(f);
BitmapFactory.Options=new-BitmapFactory.Options();
options.inJustDecodeBounds=true;
解码流(is,null,options);
is.close();
最终int imageHeight=options.outHeight;
最终int imageWidth=options.outWidth;
字符串imageType=options.outMimeType;
最终int thumbnailHeight=高度;
最终int thumbnailWidth=宽度;
int-heightRatio=Math.round((float)imageHeight)/Math.round((float)thumbnailHeight);
int-widthRatio=Math.round((float)imageWidth)/Math.round((float)thumbnailWidth);
int inSampleSize=0;
if(高度比<宽度比){
inSampleSize=高度比;
}
否则{
inSampleSize=宽度比;
}
options.inSampleSize=inSampleSize;
//使用inSampleSize集合解码位图
int-retrySteps=0;
InputStream为2=新文件InputStream(f);
位图bmp=null;
对于(int i=0;i<5;i++){
options.inJustDecodeBounds=false;
试一试{
bmp=BitmapFactory.decodeStream(is2,null,选项);
如果(bmp!=null){
i=10;
}
否则{
gc();
系统时钟睡眠(i*1000);
options.inSampleSize=inSampleSize+1;
}
}捕获(OutOfMemory错误){
gc();
系统时钟睡眠(i*1000);
}
}
is2.close();
返回bmp;

谢谢

为什么您要将
inJustDecodeBounds
设置为false?这似乎正是使用它的正确时机,与
inSampleSize
@Geobits结合使用,我在上一步计算了inSampleSize。在第二步中,我需要将其设置为false,这样它就可以解码了。您为什么不向我们展示f然后是完整的代码?也许有什么。然后,它是一个超过80MB的位图数据,所以它可能只是在尝试缩放时翻转过来。