/// <summary> /// /// </summary> public void func_按下esc() { //如果圖片窗口處於開啟,或input text有焦點,就不執行返回 String s_允許關閉 = (String)web01.Document.InvokeScript("fun_aeropic按下返回鍵"); if (s_允許關閉 == "t") { //退出全螢幕模式 if (M.bool_全螢幕) { new Thread(() => { Thread.Sleep(10); C_adapter.fun_UI執行緒(() => { M.func_全螢幕(false); }); }).Start(); return; } //延遲10毫秒在關閉大量瀏覽模式,直接關閉的話,會整個程式被關掉 new Thread(() => { Thread.Sleep(10); C_adapter.fun_UI執行緒(() => { fun_關閉大量瀏覽(); }); }).Start(); } }
/// <summary> /// /// </summary> private int fun_取得延遲(int int_目前) { int int_de = 60; bool bool_固定 = false; C_adapter.fun_UI執行緒(() => { bool_固定 = M.check_固定.IsChecked.Value; }); if (bool_固定) //固定轉換的延遲 { C_adapter.fun_UI執行緒(() => { try { int_de = Int32.Parse(M.text_延遲.Text); } catch { } }); if (int_de < 10) //最低切換延遲 { int_de = 10; } if (int_de > 5000) //最高切換延遲 { int_de = 5000; } return(int_de); } else //直接回傳從Json的延遲 //取得上一針的延遲 { int xxx = int_目前 - 1; if (xxx >= ar_img_delay.Count) { xxx = ar_img_delay.Count - 1; } if (xxx < 0) { xxx = ar_img_delay.Count - 1; } if (xxx == -1) { xxx = 0; } if (ar_img_delay.Count > 0) { return(ar_img_delay[xxx]); } else { return(60); } } }
public C_按鈕選單_其他程式開啟(MainWindow m) { this.M = m; u_menu_用外部程式開啟 = new U_menu(m); // // // //使用執行緒讀取名單,加快啟用程式的速度 new Thread(() => { var ar = fun_處理名單(); C_adapter.fun_UI執行緒(() => { event_其他程式啟動_選單(ar); }); }).Start(); }
/// <summary> /// /// </summary> void ResponseThread() { while (bool_執行中) { HttpListenerContext context = null; try { context = _httpListener.GetContext(); // get a context } catch (System.Net.HttpListenerException) { //程式結束後立即停止伺服器 return; } HttpListenerRequest request = context.Request; //取得輸入的網址 // Now, you'll find the request URL in context.Request.Url //byte[] _responseArray = Encoding.UTF8.GetBytes("<html><head><title>Localhost server -- port 5000</title></head>" + //"<body>Welcome to the <strong>Localhost server</strong> -- <em>port 5000!<h1>" + request.Url.ToString() + "</h1></em></body></html>"); // get the bytes to response String s_localhost = "http://localhost:" + port + "/"; //s_localhost = "/"; String path = request.RawUrl.ToString(); byte[] _responseArray = new byte[0]; String img_path = ""; //System.Console.WriteLine("/////// " + Uri.UnescapeDataString(request.RawUrl)); Console.WriteLine(path); var ac_回傳錯誤 = new Action(() => { if (M == null) { return; } try { //直接回傳圖示 if (File.Exists(img_path)) { using (System.Drawing.Bitmap bit = M.c_影像.func_作業系統圖示(img_path)) { MemoryStream ms = new MemoryStream(); bit.Save(ms, ImageFormat.Png); ms.Position = 0; _responseArray = new byte[ms.Length]; ms.Read(_responseArray, 0, _responseArray.Length); ms.Close(); } } else //找不到檔案 //回傳錯誤圖片 { using (FileStream fs = new FileStream(M.fun_執行檔路徑() + "/data/imgs/error.png", FileMode.Open, FileAccess.Read)) { _responseArray = new byte[fs.Length]; fs.Read(_responseArray, 0, _responseArray.Length); fs.Close(); } } } catch { //回傳錯誤圖片 using (FileStream fs = new FileStream(M.fun_執行檔路徑() + "/data/imgs/error.png", FileMode.Open, FileAccess.Read)) { _responseArray = new byte[fs.Length]; fs.Read(_responseArray, 0, _responseArray.Length); fs.Close(); } } }); /// /// /// var ac_回傳圖片 = new Action(() => { if (M == null) { return; } if (File.Exists(img_path)) { String s_附檔名 = ""; //s_附檔名 = M.c_影像.fun_取得附檔名(img_path); if (img_path.IndexOf('.') > 0) { s_附檔名 = img_path.Substring(img_path.LastIndexOf('.') + 1).ToUpper(); } //如果是 RWA 圖片 if (M.c_影像.func_判斷_RAW(s_附檔名)) { var img_raw = M.c_影像.func_dcraw(img_path, s_附檔名); if (img_raw != null) { //設定Headers var header = new System.Collections.Specialized.NameValueCollection(); header.Add("Content-Type", "image/png"); context.Response.Headers.Add(header); //回傳檔案 //BitmapSource bs_img = M.fun_get_BitmapImage_s(img_path, false); var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(img_raw)); using (MemoryStream memoryStream = new MemoryStream()) { encoder.Save(memoryStream); _responseArray = memoryStream.ToArray(); } } else { ac_回傳錯誤(); } } else if (s_附檔名 == "SVG") //SVG //設定Headers { var header = new System.Collections.Specialized.NameValueCollection(); header.Add("Access-Control-Allow-Origin", "*"); header.Add("Access-Control-Allow-Methods", "GET,POST"); header.Add("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With"); header.Add("Access-Control-Max-Age", "1728000"); header.Add("Content-Type", "image/svg+xml"); header.Add("Vary", "Accept-Encoding"); context.Response.Headers.Add(header); //回傳檔案 using (FileStream fs = new FileStream(img_path, FileMode.Open, FileAccess.Read)) { _responseArray = new byte[fs.Length]; fs.Read(_responseArray, 0, _responseArray.Length); fs.Close(); } } else if (s_附檔名 == "JPG" || s_附檔名 == "JPEG" || s_附檔名 == "PNG" || s_附檔名 == "GIF" || s_附檔名 == "BMP") //一般圖片(jpg、png、gif) //回傳檔案 { using (FileStream fs = new FileStream(img_path, FileMode.Open, FileAccess.Read)) { _responseArray = new byte[fs.Length]; fs.Read(_responseArray, 0, _responseArray.Length); fs.Close(); } } else if (s_附檔名 == "WEBM") //webm 影片 //設定Headers { var header = new System.Collections.Specialized.NameValueCollection(); //header.Add("Content-Type", "video/x-matroska"); header.Add("Content-Type", "video/webm"); //header.Add("Content-Disposition", "form-data"); //header.Add("name", "fieldName"); header.Add("filename", "aaa.mkv"); context.Response.Headers.Add(header); //回傳檔案 using (FileStream fs = new FileStream(img_path, FileMode.Open, FileAccess.Read)) { _responseArray = new byte[fs.Length]; fs.Read(_responseArray, 0, _responseArray.Length); fs.Close(); } } else if (s_附檔名 == "EXE" || s_附檔名 == "LNK") { BitmapSource bs_img = M.c_P網.fun_取得exe圖示(img_path, s_附檔名); var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bs_img)); using (MemoryStream memoryStream = new MemoryStream()) { encoder.Save(memoryStream); memoryStream.Position = 0; _responseArray = memoryStream.ToArray(); } } else if (s_附檔名 == "ICO") { BitmapSource bs_img = M.c_P網.fun_取得ICO圖示(img_path); var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bs_img)); using (MemoryStream memoryStream = new MemoryStream()) { encoder.Save(memoryStream); _responseArray = memoryStream.ToArray(); } } else /*if (s_附檔名 == "PSD" || s_附檔名 == "PSB" || s_附檔名 == "WEBP" || s_附檔名 == "TIF" || s_附檔名 == "TIFF" || * s_附檔名 == "PDF" || s_附檔名 == "AI" || s_附檔名 == "JP2" || s_附檔名 == "PBM" || s_附檔名 == "PGM" || s_附檔名 == "PCX" || * s_附檔名 == "TGA" || s_附檔名 == "PPM" || s_附檔名 == "PSB" || s_附檔名 == "DDS") */{ //設定Headers var header = new System.Collections.Specialized.NameValueCollection(); header.Add("Content-Type", "image/png"); context.Response.Headers.Add(header); //回傳檔案 //BitmapSource bs_img = M.fun_get_BitmapImage_s(img_path, false); using (var im = M.c_影像.c_Magick.getImg(img_path, s_附檔名)) { BitmapSource bs_img = im.ToBitmapSource(); var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bs_img)); using (MemoryStream memoryStream = new MemoryStream()) { encoder.Save(memoryStream); _responseArray = memoryStream.ToArray(); } } } } else //如果檔案不存在 { ac_回傳錯誤(); } }); try { if (path.IndexOf("/new_window/") > -1) //快速啟動 - { path = path.Substring("/new_window/".Length); img_path = Uri.UnescapeDataString(path);// C_adapter.fun_UI執行緒(() => { MainWindow.func_新視窗開啟圖片(img_path); }); } else if (path.IndexOf("/get_memory") > -1) //取得目前記憶體用量 //回傳檔案 { String sss = MainWindow.fun_取得記憶體用量() + ""; _responseArray = System.Text.Encoding.ASCII.GetBytes(sss); } else if (path.IndexOf("/img_path/") > -1) //大量瀏覽模式-直接在程式內部開啟圖片 { path = path.Substring("/img_path/".Length); img_path = Uri.UnescapeDataString(path); if (img_path.IndexOf(":") < 0) { img_path = "\\\\" + img_path;//避免某些不是從硬碟取得圖片的特殊路徑,例如:『\\vmware-host\Shared Folders\D\圖片』 } ac_回傳圖片(); } else if (path.IndexOf("/open_img") > -1) //外部瀏覽器、新開圖片視窗 //path = path.Replace(s_localhost, ""); { path = path.Substring(1); String[] ars = path.Split('/'); String s1 = ars[0]; String s2 = ars[1]; if (dic_圖片路徑.ContainsKey(s1)) { img_path = dic_圖片路徑[s1][Int32.Parse(s2)]; } img_path = img_path.Replace(s_localhost + "img_path/", ""); img_path = Uri.UnescapeDataString(img_path); if (File.Exists(img_path)) { C_adapter.fun_UI執行緒(() => { M.func_新視窗開啟圖片_大量瀏覽模式(img_path); }); } } else //外部瀏覽器、顯示圖片 //path = path.Replace(s_localhost, ""); { path = path.Substring(1); //根據網址來取得相對應的圖片路徑 String[] ars = path.Split('/'); String s1 = ars[0]; String s2 = ars[1]; if (dic_圖片路徑.ContainsKey(s1)) { img_path = dic_圖片路徑[s1][Int32.Parse(s2)]; } img_path = img_path.Replace(s_localhost + "img_path/", ""); img_path = Uri.UnescapeDataString(img_path); ac_回傳圖片(); } } catch (Exception e2) { ac_回傳錯誤(); } try { context.Response.OutputStream.Write(_responseArray, 0, _responseArray.Length); // write bytes to the output stream context.Response.KeepAlive = false; // set the KeepAlive bool to false context.Response.Close(); // close the connection } catch (System.Net.HttpListenerException) { } } func_刪除記錄用post(); }
/// <summary> /// thread /// </summary> private void fun_P網動圖() { while (M.bool_程式運行中) { if (bool_暫停 == false && bool_開始動作) { C_adapter.fun_UI執行緒(() => { if (ar_img.Length == 0) { } else if (ar_img.Length == 1) { M.img.Source = ar_img[0]; } else if (bool_循環) { if (bool_暫停 == false && ar_img.Length > 0) { if (x >= ar_img.Length) { x = ar_img.Length - 2; bool_循環播放方向 = -1; } if (x < 0) { x = 1; bool_循環播放方向 = 1; } M.img.Source = ar_img[x]; fun_顯示目前圖片張數(); x += bool_循環播放方向; } } else { if (bool_暫停 == false && ar_img.Length > 0) { if (x >= ar_img.Length) { x = 0; } if (x < 0) { x = 0; } M.img.Source = ar_img[x]; fun_顯示目前圖片張數(); x++; } } }); } Thread.Sleep(fun_取得延遲(x)); }//while }