几个老外关于DX屏幕像素颜色判断的热烈讨论, [0 Y: I, u5 H- H9 I
http://www.xtremedotnettalk.com/showthread.php?p=466159
5 D. b/ R) h( I- F2 i7 t
, I- ]5 @7 @; {: \# P! j8 DSurface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);8 Z9 A; Y. k3 z/ I e
uint[,] data = (uint[,])s.LockRectangle(new Rectangle(0, 0, 32, 32), LockFlags.ReadOnly);
# x& j$ Y+ i4 l- a1 Z% m! d) ], ]1 m( J, I$ e& x
for (int n = 0; n < 100; i++)3 ?3 P* x" f9 B
{/ y3 E/ Y( S, w! M/ y& E" j1 s
for (int j = 0; j < 100; j++)+ k6 z0 u6 a0 [4 p8 E8 v( W0 d2 {
{7 J( m$ F' u( w6 u
data[n, j] = (uint)Color.White.ToArgb();/ y/ K3 L2 Y H
}
2 Q+ H& C$ g( ^- j5 V d}, @$ S. m$ R# W. F2 U
; j6 H7 w) S3 Y) g* C o----------------------------------------------------; }7 V% d. [* T
Surface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);; @. ~, T7 Q4 y$ }
Stream stream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, s, new Rectangle(int locationX, int locationY, 1, 1));
9 \. O; u) Y8 y, p5 A& cBitmap bmp = new Bitmap(stream);* b# |7 ~' Q1 T
stream.Dispose();+ c& u; p3 _* H( @/ g
4 _, [ X; \1 d+ X! O
Color c = bmp.GetPixel(0, 0);
) ~# b* L# b: d3 sif (c.R == 255 && c.G == 0 && c.B == 0); X6 u5 \ |' R. L/ P
{
7 y5 F' k& q: v; f5 k" \! N( f8 B // do something
% H/ W4 h/ d/ f* k* z break;
2 U8 E/ a, X2 a# x' `} |