public static byte[] getScreenImage(int monitorIndex, int quality) { MonitorCenter.Monitor monitor = Ground.i.monitorCenter.get(monitorIndex); int l = monitor.l; int t = monitor.t; int w = monitor.w; int h = monitor.h; Bitmap bmp = new Bitmap(w, h); using (Graphics g = Graphics.FromImage(bmp)) { g.CopyFromScreen(new Point(l, t), new Point(0, 0), new Size(w, h)); } MemoryStream ms = new MemoryStream(); if (quality <= 100) { EncoderParameters eps = new EncoderParameters(1); eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality); bmp.Save(ms, getImageCodecInfo(ImageFormat.Jpeg), eps); } else { bmp.Save(ms, ImageFormat.Png); } byte[] ret = ms.ToArray(); GC.Collect(); return(ret); }
private void 画質QToolStripMenuItem_Click(object sender, EventArgs e) { this.mtEnabled = false; this.Visible = false; Bitmap imgSample = null; { MonitorCenter.Monitor m = Ground.i.monitorCenter.get(0); int l = m.l; int t = m.t; int w = m.w; int h = m.h; // QualityDlg.pbSample のサイズに合わせる。 { w = Math.Min(w, 700); h = Math.Min(h, 400); } UnshownBusyDlg.perform(delegate { Thread.Sleep(500); // MainWin が完全に隠れるのを待つ。 imgSample = CaptureScreen.getRectangle(l, t, w, h); }); } this.Visible = true; using (QualityDlg f = new QualityDlg(imgSample)) { f.ShowDialog(); } this.mtEnabled = true; }
public void eachTimerTick() { try { for (; ;) { ObjectList ol = (ObjectList)_frtwv.recv(0); if (ol == null) { break; } byte[] recvData = (byte[])ol[0]; string recvLine = StringTools.ENCODING_SJIS.GetString(recvData); List <string> prms = StringTools.tokenize(recvLine, " "); int c = 0; string command = prms[c++]; // 受信コマンド処理 > if (command == "SENDER-IDLING") { _frtwv.send(Utils.toOL( "SEND-TO-CLIENT", Utils.getScreenImage(monitorIndex, quality), "" )); } else if (command == "MONITOR-INDEX") { monitorIndex = int.Parse(prms[c++]); monitorIndex = IntTools.toRange(monitorIndex, 0, IntTools.IMAX); monitorIndex %= Ground.i.monitorCenter.getCount(); MonitorCenter.Monitor monitor = Ground.i.monitorCenter.get(monitorIndex); _frtwv.send(Utils.toOL( "MOUSE_LTRB " + monitor.l + " " + monitor.t + " " + monitor.r + " " + monitor.b )); } else if (command == "QUALITY") { quality = int.Parse(prms[c++]); quality = IntTools.toRange(quality, 0, 101); } else if (command == "DISCONNECTED") { if (Ground.i.disconnectAndShiftKeysUp) { _frtwv.send(Utils.toOL("SHIFT-KEYS-UP")); } } else if (command == "SET-CLIP-BOARD-TEXT") { byte[] bText = StringTools.decodeBase64(prms[c++]); string text = JString.toJString(bText, true, true, true, true); Clipboard.SetText(text); } else if (command == "GET-CLIP-BOARD-TEXT") { string text = Clipboard.GetText(); if (string.IsNullOrEmpty(text)) { text = "(クリップボードにテキストはありません[S])"; } if (Consts.CLIPBOARD_TEXT_LEN_MAX < text.Length) { text = "(クリップボードのテキストは長すぎます[S])"; } _frtwv.send(Utils.toOL( "SEND-TO-CLIENT", "", text )); } else { Utils.WriteLog("不明なコマンド:" + command); } // < 受信コマンド処理 } } catch (Exception e) { Utils.WriteLog("Service each-timer error: " + e); GC.Collect(); } }