几个老外关于DX屏幕像素颜色判断的热烈讨论
3 s$ B9 b$ w( ghttp://www.xtremedotnettalk.com/showthread.php?p=466159
: x. m0 b5 o8 c2 o3 }/ r- K
2 Y4 W& o- T: t1 _7 tSurface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);
" O" a7 B9 c {! n6 x5 iuint[,] data = (uint[,])s.LockRectangle(new Rectangle(0, 0, 32, 32), LockFlags.ReadOnly);/ a$ a# ?- t7 l4 S. j( G
+ O5 O: n* o7 ?# j
for (int n = 0; n < 100; i++)
. X( a5 ~ D E: w% H% l{! ~- Z8 F5 f2 R
for (int j = 0; j < 100; j++)- S% S) ]5 A8 ]
{
4 ^9 p& C. I4 O% v$ M& {4 U6 S4 D; H data[n, j] = (uint)Color.White.ToArgb();2 ~$ h6 G! L" J
}/ w* W A+ ^6 u& ~7 w
}
" _5 M5 P/ t# u' Z; d2 n
$ }( ^4 p# }8 G7 |) X5 j----------------------------------------------------( N# V/ Z7 m$ E
Surface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);: R$ D% i2 ^1 x# V% ^. H, @8 x
Stream stream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, s, new Rectangle(int locationX, int locationY, 1, 1));' r/ m- b, ~/ D7 h9 Q/ G. O
Bitmap bmp = new Bitmap(stream);
+ M7 B& D# O9 e9 K% n9 h7 Y! n8 i, wstream.Dispose();6 a* C. \9 P7 l
6 X0 ]& z0 p% n5 o3 O
Color c = bmp.GetPixel(0, 0);
2 \% w5 [8 k8 t8 s t7 tif (c.R == 255 && c.G == 0 && c.B == 0)
3 b: x0 c5 b- \) R( D& N( E3 J{& J7 ^# u% J5 s( Z2 H8 w3 ]
// do something8 f5 w R0 `, e4 t3 N' H: G2 W( Z9 s
break; a# C) ` T1 B' X4 g! m
} |