安卓:SkImageDe codeR ::厂返回null [英] Android: SkImageDecoder:: Factory returned null

查看:103
本文介绍了安卓:SkImageDe codeR ::厂返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的本地主机获取图像,并查看了ImageView的。出于某种原因,我越来越厂返回null错误。我已经通过了code很多时候看了一下,我看不出有什么不对。任何帮助将是AP preciated!

GalleryZoom.java

 公共类变焦扩展了活动{

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        的setContentView(R.layout.gallery_zoom);

        串选择= getIntent()getExtras()的getString(图像)。;
        Toast.makeText(这一点,选择Toast.LENGTH_LONG).show();

        新backgroundLoader()执行();
    }


    私有类backgroundLoader扩展的AsyncTask<虚空,虚空,虚空> {
        BMP位图;

        @覆盖
        保护无效doInBackground(虚空...... PARAMS){

            BMP =德codeBitmapSampleSize(getIntent()getExtras()的getString(形象),48,64);
            返回null;
        }

        @覆盖
        保护无效onPostExecute(无效的结果){
            super.onPostExecute(结果);

            ImageView的形象=(ImageView的)findViewById(R.id.imageZoom);
            image.setImageBitmap(BMP);
        }

    }

    公共位图德codeBitmapSampleSize(字符串strURL,诠释reqWidth,诠释reqHeight){
        在的InputStream = NULL;
        BMP位= NULL;

        在= OpenHttpConnection(strURL);
        最后BitmapFactory.Options选项=新BitmapFactory.Options();
        options.inJustDe codeBounds = TRUE;
        BitmapFactory.de codeStream(在,空,期权);

        options.inSampleSize = calculateSampleSize(选项,reqWidth,reqHeight);

        options.inJustDe codeBounds = FALSE;
        BMP = BitmapFactory.de codeStream(在,空,期权);
                返回BMP;
    }

    私人的InputStream OpenHttpConnection(字符串strURL){

        尝试 {
            网址URL =新的URL(strURL);

            HttpURLConnection的连接=(HttpURLConnection类)url.openConnection();
            InputStream的时间=新的BufferedInputStream(connection.getInputStream());
            返回;
        }赶上(例外的例外){
            exception.printStackTrace();
            返回null;
        }
    }

    公共静态INT calculateSampleSize(BitmapFactory.Options选项,
            INT reqWidth,诠释reqHeight){

        最终诠释宽度= options.outWidth;
        最终诠释身高= options.outHeight;
        INT inSampleSize = 1;

        如果(宽> reqWidth ||高度> reqHeight){
            如果(宽>高度){
                inSampleSize = Math.round((浮动)的高度/(浮点)reqHeight);
            } 其他 {
                inSampleSize = Math.round((浮点)宽/(浮点)reqWidth);
            }
        }
        返回inSampleSize;
    }

}
 

LogCat中登录

  08-13 21:55:19.578:我/的MemoryCache(3197):的MemoryCache最大限制是6MB
08-13 21:55:19.658:我/的MemoryCache(3197):缓存大小= 24600,长度= 1
08-13 21:55:19.688:我/的MemoryCache(3197):缓存大小= 24600,长度= 1
08-13 21:55:19.708:我/的MemoryCache(3197):缓存大小= 24600,长度= 1
08-13 21:55:19.708:我/的MemoryCache(3197):缓存大小= 24600,长度= 1
08-13 21:55:20.628:我/的MemoryCache(3197):缓存大小= 71600,长度= 2
08-13 21:55:20.678:我/的MemoryCache(3197):缓存大小= 101408,长度= 3
08-13 21:55:26.228:我/的MemoryCache(3197):的MemoryCache最大限制是6MB
08-13 21:55:26.228:我/的MemoryCache(3197):的MemoryCache最大限制是6MB
08-13 21:55:26.998:D / Skia的(3197):--- SkImageDe codeR ::厂返回null
 

解决方案

这也许可以帮助:

  

inJustDe codeBounds:如果设置为true,去codeR将返回null(没有位图),但出...领域仍将设置,允许调用者查询的位图,而不必分配的内存的像素。

问候,

I'm using my localhost to fetch images and to view in an ImageView. For some reason I'm getting Factory returned null error. I've looked through the code many times and I don't see what's wrong. Any help would be appreciated!

GalleryZoom.java

public class Zoom extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.gallery_zoom);

        String selection = getIntent().getExtras().getString("image");
        Toast.makeText(this, selection, Toast.LENGTH_LONG).show();

        new backgroundLoader().execute();       
    }


    private class backgroundLoader extends AsyncTask<Void, Void, Void> {
        Bitmap bmp;

        @Override
        protected Void doInBackground(Void... params) {

            bmp = DecodeBitmapSampleSize(getIntent().getExtras().getString("image"), 48, 64);
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            ImageView image = (ImageView) findViewById(R.id.imageZoom);
            image.setImageBitmap(bmp);
        }

    }

    public Bitmap DecodeBitmapSampleSize (String strURL, int reqWidth, int reqHeight) {
        InputStream in = null;
        Bitmap bmp = null;

        in = OpenHttpConnection(strURL);
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(in, null, options);

        options.inSampleSize = calculateSampleSize(options, reqWidth, reqHeight);

        options.inJustDecodeBounds = false;
        bmp = BitmapFactory.decodeStream(in, null, options);
                return bmp;
    }

    private InputStream OpenHttpConnection(String strURL) {

        try {
            URL url = new URL(strURL);

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            InputStream in = new BufferedInputStream(connection.getInputStream());
            return in;
        } catch (Exception exception) {
            exception.printStackTrace();
            return null;
        }
    }

    public static int calculateSampleSize(BitmapFactory.Options options,
            int reqWidth, int reqHeight) {

        final int width = options.outWidth;
        final int height = options.outHeight;
        int inSampleSize = 1;

        if (width > reqWidth || height > reqHeight) {
            if (width > height) {
                inSampleSize = Math.round((float) height / (float) reqHeight);
            } else {
                inSampleSize = Math.round((float) width / (float) reqWidth);
            }
        }
        return inSampleSize;
    }

}

LogCat Log

08-13 21:55:19.578: I/MemoryCache(3197): MemoryCache maximum limit is 6MB
08-13 21:55:19.658: I/MemoryCache(3197): cache size = 24600, length = 1
08-13 21:55:19.688: I/MemoryCache(3197): cache size = 24600, length = 1
08-13 21:55:19.708: I/MemoryCache(3197): cache size = 24600, length = 1
08-13 21:55:19.708: I/MemoryCache(3197): cache size = 24600, length = 1
08-13 21:55:20.628: I/MemoryCache(3197): cache size = 71600, length = 2
08-13 21:55:20.678: I/MemoryCache(3197): cache size = 101408, length = 3
08-13 21:55:26.228: I/MemoryCache(3197): MemoryCache maximum limit is 6MB
08-13 21:55:26.228: I/MemoryCache(3197): MemoryCache maximum limit is 6MB
08-13 21:55:26.998: D/skia(3197): --- SkImageDecoder::Factory returned null

解决方案

Maybe this can help:

inJustDecodeBounds: If set to true, the decoder will return null (no bitmap), but the out... fields will still be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.

Regards,

这篇关于安卓:SkImageDe codeR ::厂返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆