How to store image retrieved from url in a SQLite database?

前端 未结 3 1625
借酒劲吻你
借酒劲吻你 2020-11-29 10:38

I am retrieving images from a url. Instead of caching the images, would it by any chance be possible to store it in a SQLite database?

                /**          


        
3条回答
  •  悲&欢浪女
    2020-11-29 11:12

    protected Drawable Imagehandler(String url) {
            try {
                url=url.replaceAll(" ", "%20");
                InputStream is = (InputStream)this.fetch(url);
                Drawable d = Drawable.createFromStream(is, "src");
                return d;
            } catch (MalformedURLException e)
            {   
                System.out.println(url);
                System.out.println("error at URI"+e);
                return null;
            } 
            catch (IOException e) 
            {
                System.out.println("io exception: "+e);
                System.out.println("Image NOT FOUND");
                return null;
            } 
        }
    
        protected Object fetch(String address) throws MalformedURLException,IOException {
            URL url = new URL(address);
            Object content = url.getContent();
            return content;
        }   
    

    this will convert your imageUrl to Drawble at runtime, then set the Drawble to Imageview of Gallery

提交回复
热议问题