几个老外关于DX屏幕像素颜色判断的热烈讨论) y1 L1 }( z4 ]1 B0 x" D" G
http://www.xtremedotnettalk.com/showthread.php?p=466159
7 n i& q( [" i2 ?+ j' Q# g! y; X
C% c. z7 n( X% O0 [' QSurface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);" ]4 b, \4 @/ w* r! h
uint[,] data = (uint[,])s.LockRectangle(new Rectangle(0, 0, 32, 32), LockFlags.ReadOnly);
0 V4 W9 Q4 y3 [/ ]. `
0 j* E' Q. B* s/ Z ]0 L3 xfor (int n = 0; n < 100; i++)
- u4 ? I& |/ J{ Z9 `+ e, l% Z$ R
for (int j = 0; j < 100; j++)8 [- e4 N, e- g7 @
{
" } q n" J( l data[n, j] = (uint)Color.White.ToArgb();6 M6 S$ B$ f6 g8 C& ^
}# ]7 K, X* Z9 Q6 r8 E& @6 F
}
3 L W, y1 r0 |4 B
. g2 m. o6 y5 {! w----------------------------------------------------. Z4 c! c. m' `% n5 w; O- A1 m8 c) e
Surface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);
$ m5 D7 G: H" i( SStream stream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, s, new Rectangle(int locationX, int locationY, 1, 1));; A% [- I# o5 a
Bitmap bmp = new Bitmap(stream);
" _8 C8 V2 k7 e( Mstream.Dispose();
% T! _2 r$ T7 f+ m+ \" N7 J
3 V# P* J" z! S( J$ kColor c = bmp.GetPixel(0, 0);. U% `* a4 V- y0 o* D* r9 u4 d8 X; N
if (c.R == 255 && c.G == 0 && c.B == 0)
( X. E( _; m* F n, h{) e% X- T+ m3 W; y. l" H
// do something
1 Z! F6 j% ~" p0 Y e7 g break;" e9 i \# t0 K( h7 u
} |