【问题标题】:How to view images in an app from a server?如何从服务器查看应用程序中的图像?
【发布时间】:2011-02-14 02:16:42
【问题描述】:

我正在制作一个包含图像的应用程序。当用户点击下一个按钮时,应用将显示下一张图片。

这是否可以通过将托管图像的服务器来完成,并且当点击下一个按钮时,该服务器中的图像将转到应用程序,

我该怎么做。

APP IDEA 示例...

应用程序1

Button1 = 上一个

Button2 = 下一个

服务器/主机

图片1

图片2

图片3

图片4


当 button2 (NEXT) 被点击时,它将显示来自服务器的 Image2

当再次点击 Button2 (NEXT) 时,它将显示来自服务器的 Image3

-但是-

当Button1(Previous)被点击时,它会显示上一张图片(例如Image2)

-

此致,

IntelSoftApps

intelsoftandroid@gmail.com

IntelSoftApps.com

【问题讨论】:

    标签: android


    【解决方案1】:
        /***********************************************************
         * This method will return the image from a URL. We will input 
         * the item image URL.
         ***********************************************************/
        public Drawable getRemoteImage(final URL aURL) {
            try {
                 final URLConnection conn = aURL.openConnection();
                 conn.connect();
                 final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
                 final Drawable d = Drawable.createFromStream(bis, "src");
                 bis.close();
                 return d;
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
       }
    

    您应该从单独的线程中调用此方法,以免在获取图片时冻结 ui。将图像作为 Drawable 后,您只需设置一个 ImageView 即可显示它。

    imageView.setImageDrawable(myImage); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-04
      • 2018-04-22
      • 2020-12-25
      • 1970-01-01
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多