本文整理汇总了C#中System.Drawing.Graphics.CopyFromScreen方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.CopyFromScreen方法的具体用法?C# Graphics.CopyFromScreen怎么用?C# Graphics.CopyFromScreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Graphics
的用法示例。
在下文中一共展示了Graphics.CopyFromScreen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button1_Click
private void button1_Click(object sender, EventArgs e)
{
try
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
this.Hide();
// This gives time to the Form to hide before it takes the screenshot. 500 miliseconds are enough.
Thread.Sleep(500);
// Set the image to the size of the screen.
bt = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
// Creates the graphic object for the image (bt).
screenShot = Graphics.FromImage(bt);
// Takes the screenshot.
screenShot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
switch (saveFileDialog1.FilterIndex)
{
case 0: img = ImageFormat.Bmp; break;
case 1: img = ImageFormat.Png; break;
case 2: img = ImageFormat.Jpeg; break;
}
// Saves the image.
bt.Save(saveFileDialog1.FileName, img);
// After the screenshot is taken the Form reappears.
this.Show();
}
}
catch (Exception i)
{
MessageBox.Show("Error: "+i.Message);
}
}
示例2: timer1_Tick
private void timer1_Tick(object sender, EventArgs e)
{
bmp = new Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
gr = Graphics.FromImage(bmp);
gr.CopyFromScreen(0, 0, 0, 0,new Size(bmp.Width, bmp.Height));
pictureBox1.Image = bmp;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
示例3: CaptureScreenArea
private void CaptureScreenArea(Graphics g, Point srcPos, Point destPos, Size area)
{
try
{
//lock (ScreenSnap)
g.CopyFromScreen(srcPos.X, srcPos.Y, destPos.X, destPos.Y, area, CopyPixelOperation.SourceCopy);
}
catch (Exception e)
{
}
}
示例4: button1_Click
private void button1_Click(object sender, EventArgs e)
{
// Screenshot
this.Hide();
// Deixa o bitmap do tamanho da tela
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
// Cria o objeto a partir do bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
// Salva a screen
bmpScreenshot.Save("C:\\Users\\gubat_000\\Documents\\Visual Studio 2013\\Projects\\TesteBrowser\\TesteBrowser\\bin\\Debug\\teste.png", ImageFormat.Png);
this.Show();
label1.Text = color;
}
示例5: CaptureVideo
public void CaptureVideo()
{
b = new Bitmap(ScreenWidth, ScreenHeight);
g = Graphics.FromImage(b);
g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
//auto set options for video recording
//(description for each option availible at http://msdn.microsoft.com/en-us/library/windows/desktop/dd756832(v=vs.85).aspx)
Avi.AVICOMPRESSOPTIONS aviOptions = new Avi.AVICOMPRESSOPTIONS();
aviOptions.fccType = (uint)Avi.streamtypeVIDEO;
//codec to use MSVC = Microsoft Video 1
aviOptions.fccHandler = (uint)Avi.mmioStringToFOURCC("MSVC", 0);
//quality option go from 0-10000
aviOptions.dwQuality = 5000;
//change aviOptions to "true" to enable the popup window asking for codec options eg. aviStream = aviManager.AddVideoStream(true, 4, b);
aviStream = aviManager.AddVideoStream(aviOptions, 4, b);
Bitmap tempBmp;
while (!pause)
{
tempBmp = new Bitmap(ScreenWidth, ScreenHeight);
g = Graphics.FromImage(tempBmp);
g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
g.FillEllipse(fillBrush, currentPoint.X, currentPoint.Y, 10, 10);
g.FillRectangle(new SolidBrush(Color.Black), ScreenWidth - 100, ScreenHeight - 30, 100, 30);
g.DrawString(elapsedTime, new Font("Arial", 12), new SolidBrush(Color.White), new PointF(ScreenWidth-95, ScreenHeight-25));
if (tempBmp != null)
{
try
{
aviStream.AddFrame(tempBmp);
}
catch
{
Bitmap bmp2 = tempBmp;
tempBmp.Dispose();
tempBmp = new Bitmap((Image)bmp2);
aviStream.AddFrame(tempBmp);
}
}
tempBmp.Dispose();
Thread.Sleep(50);
}
aviManager.Close();
}
示例6: Graph
public Graph(PictureBox picture)
{
rnd = new Random();
col = Color.FromArgb(rnd.Next(20, 255), rnd.Next(20, 255), rnd.Next(20, 255));
this.picture = picture;
bmp = new Bitmap(picture.Width, picture.Height);
bmpN = new Bitmap(picture.Width, picture.Height);
fullsize = Screen.PrimaryScreen.Bounds;
graph = Graphics.FromImage(bmp);
graphN = Graphics.FromImage(bmpN);
graph.CopyFromScreen(fullsize.Left, fullsize.Top, 0, 0, fullsize.Size);
graphN.CopyFromScreen(fullsize.Left, fullsize.Top, 0, 0, fullsize.Size);
// graph.Clear(Color.White);
penForge = new Pen(col, 2.0f);
PenBack = new Pen(Color.White, 2.0f);
}
示例7: ClientBackgroundWorker_DoWork
private void ClientBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
if (Directory.Exists(path))
{
while (true)
{
if (_performCapturing)
{
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
switch (i)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
bmpScreenshot.Save(path + "0" + i + ".png");
ClientService.SendFile(path +"0" + i + ".png");
break;
default:
bmpScreenshot.Save(path + i + ".png");
ClientService.SendFile(path + i + ".png");
break;
}
//ClientService.DeleteFile( i);
i++;
}
}
}
}
示例8: our_Server
void our_Server()
{
try
{
mytcpl = new TcpListener(23);
mytcpl.Start();
mysocket = mytcpl.AcceptSocket();
myns = new NetworkStream(mysocket);
byte[] buffer = new byte[1024];
myns.Read(buffer, 0, 1024);
MemoryStream ms = new MemoryStream(buffer);
DateTime dt = DateTime.Now;
string s = new StreamReader(ms).ReadToEnd();
if (s.IndexOf("<Message>") == 0)
{
s = s.Replace("<Message>","");
Match m_caption = Regex.Match(s, "<StartCaption>.*<EndCaption>", RegexOptions.Singleline);
Match m_text = Regex.Match(s, "<StartText>.*<EndText>", RegexOptions.Singleline);
string s_caption = m_caption.ToString().Replace("<StartCaption>", "").Replace("<EndCaption>", "");
string s_text = m_text.ToString().Replace("<StartText>", "").Replace("<EndText>", "");
string str = dt + " " + host + " (" + ip.ToString() + ") message (" + s_caption + ", " + s_text + ") sent ok";
sent_report(str);
MessageBox.Show(s_text, s_caption);
}
if (s.IndexOf("<Update>") == 0)
{
string str = dt + " " + host + " (" + ip.ToString() + ") update ok";
sent_report(str);
Process process_run_program = new Process();
process_run_program.StartInfo.FileName = Application.StartupPath + @"\update.exe";
process_run_program.Start();
this.Close();
}
if (s.IndexOf("<PrimaryInternet>") == 0)
{
SetGateway("192.168.8.234");
string str = dt + " " + host + " (" + ip.ToString() + ") Gateway Primary Internet Update";
sent_report(str);
}
if (s.IndexOf("<ReserveInternet>") == 0)
{
SetGateway("192.168.8.230");
string str = dt + " " + host + " (" + ip.ToString() + ") Gateway Reserve Internet Update";
sent_report(str);
}
if (s.IndexOf("<Check>") == 0)
{
string str = dt + " " + host + " (" + ip.ToString() + ") version " + fvi.FileVersion + " on-line";
sent_report(str);
}
if (s.IndexOf("<Screen>") == 0)
{
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
// Save the screenshot to the specified path that the user has chosen
bmpScreenshot.Save("screen\\" + dt.ToString("HHmmss_ddMMyyyy") + ".png", ImageFormat.Png);
// Show the form again
string str = dt + " " + host + " (" + ip.ToString() + ") screenshot ok";
sent_report(str);
}
mytcpl.Stop();
if (mysocket.Connected == true)
{
while (true)
{
our_Server();
}
}
}
catch (Exception)
{
}
}
示例9: ScreenFull
private void ScreenFull()
{
//Conceal this form while the screen capture takes place
this.Hide();
//Allow 250 milliseconds for the screen to repaint itself
System.Threading.Thread.Sleep(250);
// Set the bitmap object to the size of the screen
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
picSave.Image = bmpScreenshot;
picSave.Enabled = true;
btnPreview.Enabled = true;
btnUpload.Enabled = true;
btnCancel.Enabled = true;
//Show Form Again
this.Show();
this.WindowState = FormWindowState.Normal;
tabControl1.SelectedTab = tabPage6;
}
示例10: Form1_MouseUp
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (down)
{
if (notrunnedyet)
{
string temp = "";
try
{
notrunnedyet = false;
Opacity = 0.0;
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(this.Width, this.Height);
gfxScreenshot = Graphics.FromImage(bmp);
gfxScreenshot.CopyFromScreen((MousePosition.X - this.Size.Width), (MousePosition.Y - this.Size.Height), 0, 0, this.Size, CopyPixelOperation.SourceCopy);
temp = Core.UserDir + "\\" + Path.GetRandomFileName();
bmp.Save(temp, System.Drawing.Imaging.ImageFormat.Png);
LE_DERPDERP_FILE = temp;
if (!imgur)
{
wc = new WebClient();
wc.UploadProgressChanged += new UploadProgressChangedEventHandler(wc_UploadProgressChanged);
wc.UploadValuesCompleted += new UploadValuesCompletedEventHandler(wc_UploadValuesCompleted);
ThreadPool.QueueUserWorkItem(new WaitCallback(checkProgress));
NameValueCollection nvc = new NameValueCollection();
nvc.Add("type", "image");
nvc.Add("content", Convert.ToBase64String(File.ReadAllBytes(temp)));
string key = Core.Settings.IniReadValue("MISC", "userkey");
string ukey = "";
if (key != string.Empty)
ukey = "?userkey=" + Crypto.DecryptStringAES(key, Core.Secret);
wc.UploadValuesAsync(new Uri("http://upload.easycaptu.re/"+Application.ProductVersion+ukey), nvc);
}
else
{
wc = new WebClient();
wc.UploadProgressChanged += new UploadProgressChangedEventHandler(wc_UploadProgressChanged);
wc.UploadValuesCompleted += new UploadValuesCompletedEventHandler(wc_UploadValuesCompleted);
NameValueCollection values = new NameValueCollection();
values.Add("key", Core.ApiKeys.Imgur.DevKey);
values.Add("image", Convert.ToBase64String(File.ReadAllBytes(temp)));
values.Add("caption", "Uploaded with http://easycaptu.re/ - Capture media from your computer with just a keypress and share it instantly!");
string url = "http://api.imgur.com/2/upload";
ThreadPool.QueueUserWorkItem(new WaitCallback(checkProgress));
string key = Core.Settings.IniReadValue("ScreenCapture", "user_key");
if (key != string.Empty)
{
wc.Headers.Add("Cookie", Crypto.DecryptStringAES(key, Core.Secret));
/*OAuth.Manager oauth = new OAuth.Manager();
string[] s = key.Split(new string[] { "|" }, StringSplitOptions.None);
OAuthBase obase = new OAuthBase();
string nurl;
string nreq;
string sig = obase.GenerateSignature(new Uri("http://api.imgur.com/2/account/images"), Core.ApiKeys.Imgur.Key, Core.ApiKeys.Imgur.Secret, s[0], s[1], "GET", obase.GenerateTimeStamp(), obase.GenerateNonce(), OAuthBase.SignatureTypes.HMACSHA1, out nurl, out nreq);
url = nurl + "/?" + nreq + "&oauth_signature=" + sig;
/*oauth["consumer_key"] = Core.ApiKeys.Imgur.Key;
oauth["consumer_secret"] = Core.ApiKeys.Imgur.Secret;
oauth["token"] = s[0];
oauth["token_secret"] = s[1];
oauth["callback"] = "http://easycaptu.re/";
url = "http://api.imgur.com/2/account/images";
oauth.GenerateAuthzHeader(url, "POST");
foreach (KeyValuePair<string,string> param in oauth._params)
{
Out.WriteDebug(param.Key + ": "+param.Value);
//if(param.Key == "token" || param.Key == "callback")
//values.Add("oauth_"+param.Key, param.Value);
}*/
//Out.WriteDebug("AuthzHeader: " + wc.Headers["Authorization"]);
}
//if (Core.Imgur_FakeStatus) url += "?_fake_status=200";
wc.UploadValuesAsync(new Uri(url), "POST", values);
}
}
catch (Exception z)
{
Out.WriteError("Something went wrong: " + z.ToString());
}
}
else Out.WriteDebug("[warning] Screencapture called more then once!!11");
}
}
示例11: OnRender
/// <summary>
/// Called when the overlay is redrawn
/// </summary>
/// <param name="g">Graphics g</param>
public static void OnRender(Graphics g)
{
//Transparent background
g.CopyFromScreen(MyOverlay.Boundings.Location, Point.Empty, MyOverlay.Boundings.Size, CopyPixelOperation.SourceCopy);
// Background rectangle. Added RoundedCorner to height to hide the top corner.
Rectangle background = new Rectangle(0, -RoundedCorner, MyOverlay.Size.Width - 2, MyOverlay.Size.Height- 2 + RoundedCorner);
// abgerundetes Rechteck mit Farbverlauf zeichnen
DrawRoundedRectangle(g, background, RoundedCorner, Color.Black, new SolidBrush(_colorBackground));
//draw progressbar
DrawProgressBar(g);
//draw hotkeys
DrawHotKeys(g);
}
示例12: capture
private void capture()
{
printscreen = new Bitmap(intWidth, intHeight);
gfx = Graphics.FromImage(printscreen as Image);
gfx.CopyFromScreen(intTop, intleft, 0, 0, printscreen.Size);
}
示例13: AverageColor
/// <summary>
/// Returns the average Color of the set CaptureScreen. Uses one
/// of two methods to determine average color.
/// </summary>
/// <returns></returns>
public Color AverageColor()
{
// Temporary variable for the found color.
Color color;
// Create an array to store the retrieved colors based on
// selected Screen and Gridsize.
var pixels = new Color[PixelAmount];
// Capture the screen and store the required pixels in the array
using (screen = new Bitmap(CaptureScreen.Bounds.Width, CaptureScreen.Bounds.Height)) {
// Create a graphics object to capture the screen
graphics = Graphics.FromImage(screen);
graphics.CopyFromScreen(CaptureScreen.Bounds.X, CaptureScreen.Bounds.Y,
0, 0, CaptureScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
// Fill the array with the required pixels
int pixelcounter = 0;
for (int x = Gridsize; x < CaptureScreen.Bounds.Width; x += Gridsize) {
for (int y = Gridsize; y < CaptureScreen.Bounds.Height; y += Gridsize) {
pixels[pixelcounter] = screen.GetPixel(x, y);
pixelcounter++;
}
}
// Tames the hungry, hungry RAM hippo
screen.Dispose();
graphics.Dispose();
}
// Determine average color based on selected CaptureMethod
color = (Method == CaptureMethod.Ambuino) ? AverageAmbuino(pixels) : AverageRGB(pixels);
// Apply smoothing if set
if (Smoothing) {
color = Color.FromArgb(
(color.R + lastcolor.R) / 2,
(color.G + lastcolor.G) / 2,
(color.B + lastcolor.B) / 2
);
lastcolor = color;
}
return color;
}
示例14: DeskCapture
private void DeskCapture()
{
int redL = 0, greenL = 0, blueL = 0;
int redR = 0, greenR = 0, blueR = 0;
int redT = 0, greenT = 0, blueT = 0;
int CounterL = 0, CounterR = 0, CounterT = 0;
bool read = false;
bool CaptureScreen = false;
Color c = Color.Black;
Screen MyScreen = Screen.AllScreens[GlobalVariables.SelectedDisplay];
if ((CaptureEvery.Checked == false) || (CaptureEvery.Checked == true && CyclesInt == 0))
{
CaptureScreen = true;
}
if (CaptureEvery.Checked == true)
{
CyclesInt = CyclesInt + 1;
}
if (CaptureScreen == true)
{
b = new Bitmap(MyScreen.Bounds.Width, MyScreen.Bounds.Height);
g = Graphics.FromImage(b);
g.CopyFromScreen(MyScreen.Bounds.Left, MyScreen.Bounds.Top, 0, 0, new Size(MyScreen.Bounds.Width, MyScreen.Bounds.Height));
}
// b.Save("temp.jpg", ImageFormat.Jpeg);
swidth = b.Width;
sheight = b.Height;
// b.Save("temp.jpg", ImageFormat.Jpeg);
int divide = (int)DivideLevel.Value;
GlobalVariables.Offset = (int)OffsetLevel.Value;
if (GlobalVariables.mode == 1)
{
divide = 32;
GlobalVariables.Offset = 0;
}
int dx = swidth / divide;
int dy = sheight / divide;
int offsetx = dx / 3 * GlobalVariables.Offset;
int offsety = dy / 3 * GlobalVariables.Offset;
if (this.WindowState != FormWindowState.Minimized)
{
label36.Text = MyScreen.Bounds.Width + "x" + MyScreen.Bounds.Height + " (" + MyScreen.Bounds.Left + ", " + MyScreen.Bounds.Top + ")";
label60.Text = dx.ToString();
label62.Text = dy.ToString();
label66.Text = swidth.ToString();
label69.Text = sheight.ToString();
label64.Text = "~" + divide.ToString();
label65.Text = "~" + divide.ToString();
label74.Text = offsetx.ToString();
label72.Text = offsety.ToString();
}
for (int PixelY = offsety; PixelY < sheight; PixelY += dy)
{
for (int PixelX = offsetx; PixelX < swidth; PixelX += swidth / divide)
{
{
read = false;
if (PixelX >= swidth * LeftBegin.Value / 100 && PixelX <= swidth * LeftEnd.Value / 100)
{
if (read == false)
{
c = b.GetPixel(PixelX, PixelY);
read = true;
}
redL += c.R;
greenL += c.G;
blueL += c.B;
CounterL++;
}
if (PixelX >= swidth * RightBegin.Value / 100 && PixelX <= swidth * RightEnd.Value / 100)
{
if (read == false)
{
c = b.GetPixel(PixelX, PixelY);
read = true;
}
redR += c.R;
greenR += c.G;
blueR += c.B;
CounterR++;
}
//.........这里部分代码省略.........
示例15: CaptureArea
/// <summary>
/// Capture the specified area of the screen
/// </summary>
/// <param name="Width">Width of area to capture</param>
/// <param name="Height">Height of area to capture</param>
/// <param name="xOffset">X-coordinate of screen offset</param>
/// <param name="yOffset">Y-coordinate of screen offset</param>
private void CaptureArea(int Width, int Height, int xOffset, int yOffset)
{
img = new Bitmap(Width, Height);
gfx = Graphics.FromImage(img);
gfx.CopyFromScreen(xOffset, yOffset, 0, 0, new Size(Width, Height), CopyPixelOperation.SourceCopy);
SaveImage();
}