作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法在 Linux 下使用 mono 截取事件窗口的屏幕截图?
最佳答案
版权所有 (C) 2011 我。
您可以根据 LGPL 的条款使用我的代码。
通常,您可以使用以下代码:
public static void GetScreenshot(System.Windows.Forms.PictureBox pbThisPictureBox)
{
System.Drawing.Rectangle rectScreenBounds = System.Windows.Forms.Screen.GetBounds();
System.Drawing.Bitmap bmpScreenshot = new System.Drawing.Bitmap(rectScreenBounds.Width, rectScreenBounds.Height);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpScreenshot))
{
g.CopyFromScreen(System.Drawing.Point.Empty, System.Drawing.Point.Empty, rectScreenBounds.Size);
} // End Using g
pbThisPictureBox.Image = bmpScreenshot;
} // End Sub GetScreenshot
System.Windows.Forms.Screen.GetBounds(),
Tools.Graphics.ScreenShot.GetScreenshot(this.pictureBox1);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tools.Graphics
{
class ScreenShot
{
// http://www.eggheadcafe.com/tutorials/aspnet/064b41e4-60bc-4d35-9136-368603bcc27a/7zip-lzma-inmemory-com.aspx
protected static System.Drawing.Rectangle rectScreenBounds = GetScrBounds();
//protected System.Drawing.Rectangle rectScreenBounds = System.Windows.Forms.Screen.GetBounds(System.Drawing.Point.Empty);
protected static System.Drawing.Bitmap bmpScreenshot = new System.Drawing.Bitmap(1, 1);
protected static System.Drawing.Rectangle GetXorgScreen()
{
int screen_width = 0;
int screen_height = 0;
IntPtr display = Xorg.API.XOpenDisplay(System.IntPtr.Zero);
if (display == IntPtr.Zero)
{
Console.WriteLine("Error: Failed on XOpenDisplay.\n");
}
else
{
screen_width = Xorg.API.DisplayWidth(display, Xorg.API.XDefaultScreen(display));
screen_height = Xorg.API.DisplayHeight(display, Xorg.API.XDefaultScreen(display));
Xorg.API.XCloseDisplay(display);
Console.WriteLine("Width: " + screen_width.ToString() + " Height: " + screen_height.ToString());
} // End Else (display == IntPtr.Zero)
return new System.Drawing.Rectangle(0, 0, screen_width, screen_height);
} // End Function GetXorgScreen
protected static System.Drawing.Rectangle GetScrBounds()
{
// Wouldn't be necessary if GetBounds on mono wasn't buggy.
if (Environment.OSVersion.Platform == PlatformID.Unix)
return GetXorgScreen();
return System.Windows.Forms.Screen.GetBounds(System.Drawing.Point.Empty);
} // End Function GetScrBounds
// http://jalpesh.blogspot.com/2007/06/how-to-take-screenshot-in-c.html
// Tools.Graphics.ScreenShot.GetScreenshot();
public static System.Drawing.Bitmap GetScreenshot()
{
/*
if (this.pictureBox1.Image != null)
this.pictureBox1.Image.Dispose();
*/
bmpScreenshot.Dispose();
bmpScreenshot = new System.Drawing.Bitmap(rectScreenBounds.Width, rectScreenBounds.Height);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpScreenshot))
{
g.CopyFromScreen(System.Drawing.Point.Empty, System.Drawing.Point.Empty, rectScreenBounds.Size);
} // End Using g
return bmpScreenshot;
} // End Function GetScreenshotImage
// http://jalpesh.blogspot.com/2007/06/how-to-take-screenshot-in-c.html
// Tools.Graphics.ScreenShot.GetScreenshot(this.PictureBox1);
public static void GetScreenshot(System.Windows.Forms.PictureBox pbThisPictureBox)
{
/*
if (this.pictureBox1.Image != null)
this.pictureBox1.Image.Dispose();
*/
bmpScreenshot.Dispose();
bmpScreenshot = new System.Drawing.Bitmap(rectScreenBounds.Width, rectScreenBounds.Height);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpScreenshot))
{
g.CopyFromScreen(System.Drawing.Point.Empty, System.Drawing.Point.Empty, rectScreenBounds.Size);
} // End Using g
pbThisPictureBox.Image = bmpScreenshot;
} // End Sub GetScreenshot
// http://jalpesh.blogspot.com/2007/06/how-to-take-screenshot-in-c.html
// Tools.Graphics.ScreenShot.SaveScreenshot(@"C:\Users\Stefan.Steiger.COR\Desktop\test.jpg");
public static void SaveScreenshot(string strFileNameAndPath)
{
System.Drawing.Rectangle rectBounds = System.Windows.Forms.Screen.GetBounds(System.Drawing.Point.Empty);
using (System.Drawing.Bitmap bmpScreenshotBitmap = new System.Drawing.Bitmap(rectBounds.Width, rectBounds.Height))
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpScreenshotBitmap))
{
g.CopyFromScreen(System.Drawing.Point.Empty, System.Drawing.Point.Empty, rectBounds.Size);
} // End Using g
bmpScreenshotBitmap.Save(strFileNameAndPath, System.Drawing.Imaging.ImageFormat.Jpeg);
} // End Using
} // End Sub SaveScreenshot
} // End Class ScreenShot
} // End Namespace Tools.Graphics
using System;
using System.Runtime.InteropServices;
using Xorg.Structs;
// http://www.koders.com/csharp/fid5A7CBAABE4E399E1BED8C2C2FB6E1B36C289628D.aspx?s=zoom#L293
namespace Xorg
{
// http://www.koders.com/csharp/fidFC528FE04222FE631D31990CC4B30889DB6ACCA8.aspx?s=socket
public class API
{
[Flags]
internal enum EventMask
{
NoEventMask = 0,
KeyPressMask = 1<<0,
KeyReleaseMask = 1<<1,
ButtonPressMask = 1<<2,
ButtonReleaseMask = 1<<3,
EnterWindowMask = 1<<4,
LeaveWindowMask = 1<<5,
PointerMotionMask = 1<<6,
PointerMotionHintMask = 1<<7,
Button1MotionMask = 1<<8,
Button2MotionMask = 1<<9,
Button3MotionMask = 1<<10,
Button4MotionMask = 1<<11,
Button5MotionMask = 1<<12,
ButtonMotionMask = 1<<13,
KeymapStateMask = 1<<14,
ExposureMask = 1<<15,
VisibilityChangeMask = 1<<16,
StructureNotifyMask = 1<<17,
ResizeRedirectMask = 1<<18,
SubstructureNotifyMask = 1<<19,
SubstructureRedirectMask= 1<<20,
FocusChangeMask = 1<<21,
PropertyChangeMask = 1<<22,
ColormapChangeMask = 1<<23,
OwnerGrabButtonMask = 1<<24
}
protected const string m_strSharedObjectName = "libX11";
protected const string m_strSharedObjectName_Video = "libXxf86vm";
// For AIX shared object, use "dump -Tv /path/to/foo.o"
// For an ELF shared library, use "readelf -s /path/to/libfoo.so"
// or (if you have GNU nm) "nm -D /path/to/libfoo.so"
// For a Windows DLL, use "dumpbin /EXPORTS foo.dll".
// nm -D $(locate libX11 | sed '/\/usr\/lib/!d;' | grep ".so$")
// nm -D $(locate "libX11.so" | grep ".so$")
// nm -D $(locate "libX11.so" | grep ".so$") | grep "DisplayHeight"
[DllImport(m_strSharedObjectName, EntryPoint = "XOpenDisplay")]
internal extern static IntPtr XOpenDisplay(IntPtr display);
[DllImport(m_strSharedObjectName, EntryPoint = "XDefaultScreen")]
internal extern static int XDefaultScreen(IntPtr display);
[DllImport(m_strSharedObjectName, EntryPoint = "XDisplayHeight")]
internal extern static int DisplayHeight(IntPtr display, int screen_number);
[DllImport(m_strSharedObjectName, EntryPoint = "XDisplayWidth")]
internal extern static int DisplayWidth(IntPtr display, int screen_number);
[DllImport(m_strSharedObjectName, EntryPoint = "XRootWindow")]
internal extern static IntPtr XRootWindow(IntPtr display, int screen_number);
[DllImport(m_strSharedObjectName, EntryPoint = "XCloseDisplay")]
internal extern static int XCloseDisplay(IntPtr display);
[DllImport(m_strSharedObjectName, EntryPoint = "XSynchronize")]
internal extern static IntPtr XSynchronize(IntPtr display, bool onoff);
[DllImport(m_strSharedObjectName, EntryPoint = "XGrabServer")]
internal extern static void XGrabServer(IntPtr display);
[DllImport(m_strSharedObjectName, EntryPoint = "XUngrabServer")]
internal extern static void XUngrabServer(IntPtr display);
[DllImport(m_strSharedObjectName)]
internal extern static int XFlush(IntPtr display);
[DllImport(m_strSharedObjectName, EntryPoint = "XFree")]
internal extern static int XFree(IntPtr data);
//[DllImport(m_strSharedObjectName, EntryPoint = "XSendEvent")]
//internal extern static int XSendEvent(IntPtr display, IntPtr window, bool propagate, IntPtr event_mask, ref XEvent send_event);
[DllImport(m_strSharedObjectName, EntryPoint = "XSendEvent")]
internal extern static int XSendEvent(IntPtr display, IntPtr window, bool propagate, int event_mask, ref XEvent send_event);
//[DllImport (m_strSharedObjectName, EntryPoint="XSendEvent")]
//internal extern static int XSendEvent(IntPtr display, IntPtr window, bool propagate, EventMask event_mask, ref XEvent send_event);
//internal extern static int XSendEvent(IntPtr display, IntPtr window, bool propagate, EventMask event_mask, ref XClientMessageEvent send_event);
[DllImport(m_strSharedObjectName, EntryPoint = "XQueryPointer")]
internal extern static bool XQueryPointer(IntPtr display, IntPtr window, out IntPtr root, out IntPtr child, out int root_x, out int root_y, out int win_x, out int win_y, out int keys_buttons);
[DllImport(m_strSharedObjectName, EntryPoint = "XWarpPointer")]
internal extern static uint XWarpPointer(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, uint src_width, uint src_height, int dest_x, int dest_y);
[DllImport(m_strSharedObjectName, EntryPoint = "XGetWindowProperty")]
internal extern static int XGetWindowProperty(IntPtr display, IntPtr window, IntPtr atom, IntPtr long_offset, IntPtr long_length, bool delete, IntPtr req_type, out IntPtr actual_type, out int actual_format, out IntPtr nitems, out IntPtr bytes_after, ref IntPtr prop);
} // End Class Mouse
} // End Namespace Xorg
namespace Tao.Platform.X11
namespace Xorg.Structs
关于mono - 以单声道截取事件窗口的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3732486/
我想在我的 android 应用程序中播放 PCM 音频数据。网络上有很多示例,但仅用于单 channel ,我有 4 个 channel (如本问题标题所述)。 当我设置 AudioTrack au
我正在尝试通过 channelsplitter 将立体声音频路由到具有增益控制的 6 个 channel ,然后返回到 channelMerger,以控制 5.1 组的所有 6 个 channel .
我试图从 iPhone XS 的所谓立体声后置麦克风中获取两个 channel ,但在 AVAudioSession 的不同点上只能看到一个 channel 。和 AVAudioSessionPort
我是一名优秀的程序员,十分优秀!