求高效截屏和分块代码
目前用的DC,BitBlt 方法 截一屏将近160MS 分块也差不多160MS(4*4)
分块代码:
graphic.DrawImage(im, 0, 0, new Rectangle(x, y, width, height), GraphicsUnit.Pixel);
//从作图区生成新图
IntPtr pr = bitmap.GetHbitmap();
Image MyImage = Image.FromHbitmap(pr);
DeleteObject(pr);
//
byte[] tmpbyte = CompressByte(imageToByteArray(MyImage));//转换为字节压缩。
在另外一台17寸电脑上操作更是消耗 860MS。
求高效方法,DirecxX ,差异截图 等方法
[最优解释]
Image deskImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format24bppRgb);
Graphics deskG = Graphics.FromImage(deskImage);
deskG.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.PrimaryScreen.Bounds.Size);
Rectangle targRect = new Rectangle(0, 0,640, 480);
Image baseImage = new Bitmap(640, 480, PixelFormat.Format24bppRgb);
Graphics baseG = Graphics.FromImage(baseImage);
baseG.DrawImage(deskImage, targRect, new Rectangle(0, 0, deskImage.Width, deskImage.Height), GraphicsUnit.Pixel);
[其他解释]
graphic.DrawImage(im, 0, 0, new Rectangle(x, y, width, height), GraphicsUnit.Pixel);
//从作图区生成新图
IntPtr pr = bitmap.GetHbitmap();
Image MyImage = Image.FromHbitmap(pr);
DeleteObject(pr);
-------------------
graphic.DrawImage(im, 0, 0, new Rectangle(x, y, width, height), GraphicsUnit.Pixel);
Image MyImage =bitmap;
bitmap.dispose; '释放
截屏可用:
graphic.CopyFromScreen(..)
[其他解释]
http://topic.csdn.net/u/20090911/14/5614a16e-ab08-4106-901e-e8dcc5cd1fa3.html?44754
[其他解释]
http://topic.csdn.net/u/20090911/14/5614a16e-ab08-4106-901e-e8dcc5cd1fa3.html?8513
[其他解释]
友情关注,解决了望楼主分享
[其他解释]
该回复于2010-12-24 16:02:05被版主删除
[其他解释]
不是这种截图,是做屏幕传输的,它这里面用的应该也是DC
[其他解释]
类库自带的 g.CopyFromScreen( 跟上面的效率差不多。
[其他解释]
该回复于2010-12-25 08:34:32被版主删除
[其他解释]
使用 DirectX 截图 GetFrontBufferData(0, mySurface) 应用程序错误。。
[其他解释]
刚错误是设置的分辨率问题,不过耗时还是需要140毫秒左右 = =!不知道哪出问题了
[其他解释]
该回复于2010-12-27 13:00:57被版主删除
[其他解释]
Microsoft.DirectX.Direct3D.Device myDevice;
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.PresentFlag = PresentFlag.LockableBackBuffer;
presentParams.BackBufferWidth = 1280;
presentParams.BackBufferHeight = 800;
presentParams.MultiSample = MultiSampleType.None;
presentParams.BackBufferCount = 1;
// presentParams.DeviceWindowHandle = this.Handle;
for (int i = 0; i < 100; i++)
{
string datetime = DateTime.Now.ToString("HH:mm:ss:ff");
myDevice = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
Surface mySurface = myDevice.CreateOffscreenPlainSurface(1280, 800, Format.A8R8G8B8, Pool.SystemMemory);
try
{
myDevice.GetFrontBufferData(0, mySurface); //copy frontsurface to mySurface
Microsoft.DirectX.GraphicsStream gStr = Microsoft.DirectX.Direct3D.SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, mySurface);
// pictureBox1.Image = Bitmap.FromStream(gStr);
Bitmap screen = new Bitmap(Bitmap.FromStream(gStr));
gStr.Dispose();
mySurface.Dispose();
}
catch (Exception ee)
{
Tools.Trace(ee.ToString());
mySurface.Dispose();
}
string datetime2 = DateTime.Now.ToString("HH:mm:ss:ff");
}
使用的DX,速度也差不多 = =。请问是哪的使用问题吗
[其他解释]
该回复于2010-12-27 09:24:14被版主删除
[其他解释]
这种方法试过了,速度差不多
[其他解释]
顶顶 谁有效率代码给发发。。。
[其他解释]
该回复于2011-03-11 13:54:45被版主删除
[其他解释]
上面的释放方式运行段时间就会出错。
CopyFromScreen()效果和API差不多。。
[其他解释]
不知道楼主问题解决没有?
[其他解释]
这只是截图。。