close
private byte[] GetScreen() { int Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;//抓取桌面的高度 int Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;//抓取桌面的寬度 Bitmap screenshot = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics graph = Graphics.FromImage(screenshot); graph.CopyFromScreen(0, 0, 0, 0, new Size(Width, Height), CopyPixelOperation.SourceCopy); int FixWidth = 800; //設定新圖檔的解晰度,寬度 int FixHeight = Convert.ToInt16((Decimal.Parse(FixWidth.ToString()) / Decimal.Parse(Width.ToString())) * Height); //計算高度 Bitmap bmp = new Bitmap(screenshot, new Size(FixWidth, FixHeight)); MemoryStream ms = new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); //把圖檔用新的解晰度去儲存 screenshot.Dispose(); graph.Dispose(); bmp.Dispose(); return ms.GetBuffer(); }
全站熱搜