我的程序是C/S模式,图片的路径在数据表中存放,图片在文件服务器上存放,client端有一form,窗体里有一个图片显示的控件
我执行picControl.fileName="httP://10.10.101.234/filesystem/myFile.tif"
的时候很慢,有时图片显示不出来
执行这句话时,先要把myFile.tif下载到C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files
我每次访问的文件图片都不一样,请问高手,除了增加带宽,还有啥办法,能提高访问速度

解决方案 »

  1.   

    你使用HttpWebRequest来请求图片,HttpWebResponse将请求得到的图像流写入到Image,然后你的picturebox直接设置Image属性就可以了,你还可以进行多线程来读取设置。给你个小例子看看吧 using System;
    using System.Net;
    using System.Collections.Generic;namespace myNet
    {       
    class Setting
        {
            #region 代理相关
            private static bool _UseProxy=false;        public static bool UseProxy
            {
                get { return _UseProxy; }
                set { _UseProxy = value; }
            }        private static bool _IEProxy = false;        public static bool IEProxy
            {
                get { return _IEProxy; }
                set { _IEProxy = value; }
            }        private static string _ProxyServer="";        public static string ProxyServer
            {
                get { return _ProxyServer; }
                set { _ProxyServer = value; }
            }        private static string _ProxyPort = "";        public static string ProxyPort
            {
                get { return _ProxyPort; }
                set { _ProxyPort = value; }
            }
            private static string _ProxyUsername = "";        public static string ProxyUsername
            {
                get { return _ProxyUsername; }
                set { _ProxyUsername = value; }
            }        private static string _ProxyPassword = "";        public static string ProxyPassword
            {
                get { return _ProxyPassword; }
                set { _ProxyPassword = value; }
            }
            #endregion 代理相关
        }

     class Net
    {
    private CookieCollection _Cookies;
            /// <summary>
            /// 从服务端返回的cookie
            /// </summary>
            public CookieCollection Cookies
            {
                get { return _Cookies; }
                set { _Cookies = value; }
            }        private CookieContainer _ReqCookies=new CookieContainer();        public CookieContainer ReqCookies
            {
                get {
                    if (_ReqCookies == null)
                    {
                        _ReqCookies = new CookieContainer();
                    }
                    return _ReqCookies;
                }
                set { _ReqCookies = value; }
            }
            private string  _Referer="";        public string  Referer
            {
                get { return _Referer; }
                set { _Referer = value; }
            }

    public System.Drawing.Image GetImg(string URL)
            {
                System.Drawing.Image img = null;            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
                request.Accept = "*/*";
    if(String.IsNullOrEmpty(_Referer))    
                request.Referer = "";
    else
    request.Referer = _Referer;
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Maxthon)";
                request.CookieContainer = this.ReqCookies;            //设置代理
                if (Setting.UseProxy)
                {
                    if (!Setting.IEProxy)
                    {
                        WebProxy proxy = new WebProxy();
                        try
                        {
                            proxy.Address = new Uri(String.Format("http://{0}:{1}", Setting.ProxyServer, Setting.ProxyPort));
                            if (Setting.ProxyUsername.Length!=0 && Setting.ProxyPassword.Length!=0)
                            {
                                proxy.Credentials = new NetworkCredential(Setting.ProxyUsername, Setting.ProxyPassword);
                            }
                            request.Proxy = proxy;
                        }
                        catch
                        {
                           
                        }
                    }
                }
                else
                {
                    request.Proxy = null;
                }
                HttpWebResponse response = null;
                try
                {                response = (HttpWebResponse)request.GetResponse();                img = System.Drawing.Image.FromStream(response.GetResponseStream());            }
                catch 
                {
                    img = null;
                }
                finally
                {                
                    if (response != null) { response.Close(); }
                    response = null;
                    request = null;
                }            return img;
            }
    }
    class NewClass
    {
       public static void Main(string[] args)
       {
            Setting.UseProxy = true;
    Setting.ProxyServer = "10.0.1.14";
    Setting.ProxyPort = "8088";
    Net n = new Net();
    System.Drawing.Image img = n.GetImg("http://www.google.cn/intl/zh-CN/images/logo_cn.gif");
                System.Drawing.Bitmap bmap = new System.Drawing.Bitmap(img);
    bmap.Save("a.gif");
       }
    }
    }
      

  2.   

    楼上几位都提到了,把图片下载到本地
    问题是client端在处理图片的时候并不知道他要处理的是哪一张图片,client端处理的都是表里排序后的第一张,每个client端都处理的是不同的图片。我不知道该下载 保存哪一张。
      

  3.   

    我存放图片的表是有唯一的record_Id, 你的意思是说client端在每次处理这张图片之前都要进行下载图片?
      

  4.   

    你说的本地是指本地的这个目录么?
    C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files
    如果这个目录里有文件就不下载
    谢谢!
      

  5.   

    你也可以自己另外放個目錄,防止Internet臨時文件被刪除的情況。
    像QQ等軟件,也是把圖象本地存儲,否則不是每個圖片每次都要訪問網絡?
      

  6.   

    可以使用WebClient,參考下面.        private void button2_Click(object sender, EventArgs e)
            {
                System.Net.WebClient wc = new System.Net.WebClient();
                wc.DownloadDataCompleted += new System.Net.DownloadDataCompletedEventHandler(wc_DownloadDataCompleted);
                wc.DownloadDataAsync(new Uri("http://圖片url"));        }        void wc_DownloadDataCompleted(object sender, System.Net.DownloadDataCompletedEventArgs e)
            {
                MemoryStream ms=new MemoryStream(e.Result);
                this.cusomPictureBox1.Image = Image.FromStream(ms);
                ms.Close();
            }