Пример #1
0
        // http://stackoverflow.com/questions/17908452/c-sharp-webbrowser-control-doesnt-work-in-ie-10-after-emulation
        // This is the URL to configure WebControl with a specific IE version
        static void Main(string[] args)
        {
            //Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
            //byte[] img = new Uri("http://www.uol.com.br").ToImage();
            //using (var fs = new FileStream("test.bmp", FileMode.CreateNew))
            //{
            //    fs.Write(img, 0, img.Length);
            //    fs.Flush();
            //}

            //WebsiteToImage websiteToImage = new WebsiteToImage("http://stackoverflow.com/questions/2715385/convert-webpage-to-image-from-asp-net", @"Test2.jpg");
            //websiteToImage.Generate();
            //WebsiteToImage websiteToImage = new WebsiteToImage("https://github.com/jdavis?tab=repositories", @"Test3.jpg");
            //websiteToImage.Generate();
            //WebsiteToImage websiteToImage = new WebsiteToImage("http://www.bbc.co.uk/vietnamese/world/2014/08/140817_ukraine_russian_aid_arrives.shtml", @"Test4.jpg");
            //websiteToImage.Generate();
            WebsiteToImage websiteToImage = new WebsiteToImage("http://stackoverflow.com/questions/17908452/c-sharp-webbrowser-control-doesnt-work-in-ie-10-after-emulation", @"Test6.jpg");
            websiteToImage.Generate();
        }
Пример #2
0
 private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
 {
     if (axWindowsMediaPlayer1.currentMedia != null)
     {
         TagLib.File mediaNow = TagLib.File.Create(axWindowsMediaPlayer1.currentMedia.sourceURL);
         if (mediaNow.Tag.Performers.Length > 0 && mediaNow.Tag.Title != null)
         {
             listBoxSong.SelectedItem = (mediaNow.Tag.Performers[0].ToString() + " - " + mediaNow.Tag.Title.ToString());
             this.Text = mediaNow.Tag.Performers[0].ToString() + " - " + mediaNow.Tag.Title.ToString();
         }
         else
         {
             this.Text = axWindowsMediaPlayer1.currentMedia.name;
             listBoxSong.SelectedItem = axWindowsMediaPlayer1.currentMedia.name;
         }
         if (mediaNow.Tag.Pictures.Length > 0)
         {
             MemoryStream         ms    = new MemoryStream(mediaNow.Tag.Pictures[0].Data.Data);
             System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
             Bitmap bp = new Bitmap(image);
             int    a, r, g, b;
             a = 0; r = 0; g = 0; b = 0;
             for (int y = 1; y < bp.Height; y++)
             {
                 for (int x = 1; x < bp.Width; x++)
                 {
                     a += bp.GetPixel(x, y).A;
                     r += bp.GetPixel(x, y).R;
                     g += bp.GetPixel(x, y).G;
                     b += bp.GetPixel(x, y).B;
                 }
             }
             int   cc = bp.Height * bp.Width;
             Color cl = Color.FromArgb(255, r / cc, g / cc, b / cc);
             this.BackColor = cl;
         }
         else
         {
             this.BackColor = Color.AliceBlue;
         }
         if (checkBoxOutput.Checked)
         {
             if (File.Exists("output.html"))
             {
                 File.Delete("output.html");
             }
             if (File.Exists("output.txt"))
             {
                 File.Delete("output.txt");
             }
             string color = "#A7FFF0";
             if (mediaNow.Tag.Pictures.Length > 0)
             {
                 MemoryStream         ms    = new MemoryStream(mediaNow.Tag.Pictures[0].Data.Data);
                 System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
                 image.Save("output.jpg");
                 Bitmap bp = new Bitmap(image);
                 int    a, r, g, b;
                 a = 0; r = 0; g = 0; b = 0;
                 for (int y = 1; y < bp.Height; y++)
                 {
                     for (int x = 1; x < bp.Width; x++)
                     {
                         a += bp.GetPixel(x, y).A;
                         r += bp.GetPixel(x, y).R;
                         g += bp.GetPixel(x, y).G;
                         b += bp.GetPixel(x, y).B;
                     }
                 }
                 int   cc = bp.Height * bp.Width;
                 Color cl = Color.FromArgb(a / cc, r / cc, g / cc, b / cc);
                 color = ColorTranslator.ToHtml(cl).ToString();
                 if (checkBoxUpload.Checked)
                 {
                     uploadImageToServer("output.jpg", "output.jpg");
                 }
             }
             else
             {
                 Image img = Image.FromFile("notfound.png");
                 img.Save("output.jpg");
             }
             using (StreamWriter sw = File.CreateText("output.html"))
             {
                 sw.WriteLine("<html>");
                 sw.WriteLine("<head>");
                 sw.WriteLine("<meta charset='unicode' http-equiv='cache-control' content='no-cache'>");
                 sw.WriteLine("<link rel='stylesheet' href='stylesheet.css'>");
                 //sw.WriteLine("<script src=\"jquery-1.12.3.js\"></script>");
                 //sw.WriteLine("<script type='text/javascript'>"); sw.WriteLine("function refresh()");sw.WriteLine("{	setTimeout(function(){ $.ajax({");sw.WriteLine("    url : \"http://trivernis.byethost7.com/Music/index.html? \" + (new Date()).getMilliseconds(),");
                 //sw.WriteLine("dataType : \"text\",");sw.WriteLine("    ifModified : true,");sw.WriteLine("    success : function(data, textStatus) {");sw.WriteLine("      if (textStatus != \"notmodified\") {");sw.WriteLine("        location.href = location.href;");
                 //sw.WriteLine("}}});}, 1000);}");
                 //sw.WriteLine("</script>");
                 sw.WriteLine("</head>");
                 sw.WriteLine("<body style='background-color:" + color + "' onLoad='refresh()'>");
                 if (mediaNow.Tag.Pictures.Length > 0)
                 {
                     sw.WriteLine("<img class='art' src='output.jpg'/>");
                 }
                 else
                 {
                     sw.WriteLine("<img class='art' src='" + this.searchForImage(axWindowsMediaPlayer1.currentMedia.name) + "'/>");
                 }
                 if (mediaNow.Tag.Performers.Length > 0 && mediaNow.Tag.Title != null && mediaNow.Tag.Album != null)
                 {
                     sw.WriteLine("<p class='artist'>" + mediaNow.Tag.Performers[0] + "</p>");
                     sw.WriteLine("<p class='title'>" + mediaNow.Tag.Title + "</p>");
                     sw.WriteLine("<p class='album'>" + mediaNow.Tag.Album + "</p>");
                 }
                 else
                 {
                     sw.WriteLine("<p class='artist'>" + axWindowsMediaPlayer1.currentMedia.name + "</p>");
                 }
                 sw.WriteLine("</body>");
                 sw.WriteLine("</html>");
             }
             if (checkBoxUpload.Checked)
             {
                 uploadToServer("output.html", "index.html");
             }
             FileInfo       fih            = new FileInfo("output.html");
             WebsiteToImage websiteToImage = new WebsiteToImage("file:///" + fih.FullName, "weboutput.jpg");
             websiteToImage.Generate();
             using (StreamWriter sw = File.CreateText("background.html"))
             {
                 sw.WriteLine("<html>");
                 sw.WriteLine("<body style=\"background-color:" + color + "\">");
                 sw.WriteLine("</body>");
             }
             FileInfo       fib            = new FileInfo("background.html");
             WebsiteToImage websitetoImage = new WebsiteToImage("file:///" + fib.FullName, "background.jpg");
             websitetoImage.Generate();
             using (StreamWriter sw = File.CreateText("output.txt"))
             {
                 if (mediaNow.Tag.Performers.Length > 0 && mediaNow.Tag.Title != null && mediaNow.Tag.Album != null)
                 {
                     sw.WriteLine(mediaNow.Tag.Performers[0]);
                     sw.WriteLine(mediaNow.Tag.Title);
                     sw.WriteLine(mediaNow.Tag.Album);
                 }
                 else
                 {
                     sw.WriteLine(axWindowsMediaPlayer1.currentMedia.name);
                 }
             }
         }
     }
 }