几个老外关于DX屏幕像素颜色判断的热烈讨论& I" {" d5 a4 n" ~& w
http://www.xtremedotnettalk.com/showthread.php?p=4661593 Q4 {3 B8 _& g
$ E0 X$ H% k* I
Surface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);- N/ ^! i0 o. F- N% _5 T
uint[,] data = (uint[,])s.LockRectangle(new Rectangle(0, 0, 32, 32), LockFlags.ReadOnly);" F+ k8 T5 P3 f& I$ v0 K; J% m" q
6 `- |. u! E. Y s3 G& k4 Qfor (int n = 0; n < 100; i++)" n, L; E; w$ O* H( j% p. }' G1 o* i5 x! b
{
( t% x, G3 Y. I: X9 l; a' S for (int j = 0; j < 100; j++)
6 f4 V9 F- L. e9 g- W( } f. J {
. U6 y/ X% s* K) k data[n, j] = (uint)Color.White.ToArgb();6 K9 \5 r" B" e) X P7 A1 a: `( g
}) p) L; _0 k6 } f
}
8 K) S& T! u X. T3 @0 W0 { K, j8 T+ l j& D
----------------------------------------------------- ^4 @+ M5 d1 v6 b
Surface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);( W" J% V, G6 ~$ c
Stream stream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, s, new Rectangle(int locationX, int locationY, 1, 1));) r, }+ \! w+ D2 c5 N1 G' G
Bitmap bmp = new Bitmap(stream);0 \5 l) L$ G* N" d4 i3 _
stream.Dispose();1 P* d8 n9 Y# ~' `$ t: h; ^: E y
2 p( m# b+ Q3 D( M5 [( R
Color c = bmp.GetPixel(0, 0);
3 E6 U" c, P7 E0 |, bif (c.R == 255 && c.G == 0 && c.B == 0)" e. S- G' b% t3 v
{
: Y: P. Q7 K6 K8 y // do something
9 p, s0 S* u u, c' V6 f8 f" D' Q break;
' e4 S/ U/ i0 ?8 m% q} |