开发者

How to scale larger images in android?

开发者 https://www.devze.com 2023-04-13 00:48 出处:网络
i am using following code to download and display images in android its works many time but some times it gives me error for larger images any one guide me what is the solutions to this problem?

i am using following code to download and display images in android

its works many time but some times it gives me error for larger images any one guide me what is the solutions to this problem?

LogCat

10-12 18:55:52.283: ERROR/AndroidRuntime(434): FATAL EXCEPTION: Thread-30
10-12 18:55:52.283: ERROR/AndroidRuntime(434): java.lang.NullPointerException
10-12 18:55:52.283: ERROR/AndroidRuntime(434):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:344)
10-12 18:55:52.283: ERROR/AndroidRuntime(434):     at com.Utils.ImageLoader.loadImageFromUrl(ImageLoader.java:83)
10-12 18:55:52.283: ERROR/AndroidRuntime(434):     at com.Utils.ImageLoader$2.run(ImageLoader.java:44)

ImageLoading Code

public static Bitmap loadImageFromUrl(String url) {

        Bitmap bm;
        try {  

                URL aURL = new URL(url);  
                URLConnection conn = aURL.openConnection(); 

                conn.connect();  
                InputStream is = null;
                try
                {
                 is= conn.getInputStream();  
                }catch(IOException e)
                {
                     return null;
                }

                BufferedInputStream bis = new BufferedInputStream(is);  
                BitmapFactory.Options options=new BitmapFactory.Options();
                options.inSampleSize = 8;
                bm = BitmapFactory.decodeStream(bis,null,options);

           开发者_Python百科     bis.close();  
                is.close();  

           } catch (IOException e) {  
            return null;
           }  
        return  Bitmap.createScaledBitmap(bm,100,100,true);  // error here

    }

any help would be appreciated.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号