獲取股票的瞬時圖C#

獲取時時線。歡迎轉載啊。 

private void getnewpic(string num)

        {

            try

            {

                string url = @"http://image2.sinajs.cn/newchart/min/n/sh" + num + ".gif";

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);



                System.IO.Stream s = request.GetResponse().GetResponseStream();

                Image img2 = System.Drawing.Bitmap.FromStream(s);

                s.Close();

                //生成Bitmap對像

                Bitmap img = new Bitmap(img2, 545, 300);

                //生成繪圖對像

                Graphics g = Graphics.FromImage(img);

                //定義黑色畫筆

                Pen Bp = new Pen(Color.Black);

                LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.Blue, 1.2F, true);

                LinearGradientBrush Transpentbrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Form1.DefaultBackColor, Form1.DefaultBackColor, 1.2F, true);

                //string info = " 曲線圖生成時間:" + DateTime.Now.ToString();

                Font Tfont = new Font("Arial", 9);

                //g.DrawString(info, Tfont, Bluebrush, 40, 25);

                g.FillRectangle(Transpentbrush, 5, 287, 535, 15);

                g.FillRectangle(Transpentbrush, 497, 228, 35, 30);



                //保存繪製的圖片

                MemoryStream stream = new MemoryStream();

                img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);

                this.pictureBox1.Image = img;

            }

            catch (Exception ex)

            { 

            }

        }




獲取日K線。

private void getKpic(string num)

        {

            try

            {

                string url = @"http://image2.sinajs.cn/newchart/daily/n/sh" + num + ".gif";

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);



                System.IO.Stream s = request.GetResponse().GetResponseStream();

                Image img2 = System.Drawing.Bitmap.FromStream(s);

                s.Close();

                //生成Bitmap對像

                Bitmap img = new Bitmap(img2,545, 300);

                //生成繪圖對像

                Graphics g = Graphics.FromImage(img);

                //定義黑色畫筆

                Pen Bp = new Pen(Color.Black);

                LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.Blue, 1.2F, true);

                LinearGradientBrush Transpentbrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Form1.DefaultBackColor, Form1.DefaultBackColor, 1.2F, true);

                //string info = " 曲線圖生成時間:" + DateTime.Now.ToString();

                Font Tfont = new Font("Arial", 9);

                //g.DrawString(info, Tfont, Bluebrush, 40, 25);

                g.FillRectangle(Transpentbrush, 5, 287, 535, 15);



                //保存繪製的圖片

                MemoryStream stream = new MemoryStream();

                img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);



                this.pictureBox1.Image = img;

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章