几个老外关于DX屏幕像素颜色判断的热烈讨论
# x) C: a3 Q' Z$ z- Phttp://www.xtremedotnettalk.com/showthread.php?p=466159
# C1 w) f9 E) m# H
9 v6 Q; t+ o" n8 i# XSurface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);
, f) p) u/ O4 @, uuint[,] data = (uint[,])s.LockRectangle(new Rectangle(0, 0, 32, 32), LockFlags.ReadOnly);
) `( g U" x$ ]. [' ~. \7 _1 D. E' f" C; J' y+ a5 B7 i3 X" N
for (int n = 0; n < 100; i++) P9 l6 r0 S! V- Q# [/ T
{( |" B0 a0 i9 R1 u1 [" ~% w! e
for (int j = 0; j < 100; j++)+ U& W/ F$ M7 E! `2 ?
{
& ]$ s) a8 `/ y+ u; @2 K data[n, j] = (uint)Color.White.ToArgb();& G- `2 p# s3 R6 j9 G
}
2 @9 ?0 }6 \ l. H( N9 A: Y}
+ [" b& S5 r* [, N. c B6 Q
: {4 f# ~, U" T6 ?9 X/ g0 l3 U----------------------------------------------------
* _+ `4 _, V& M3 a. h- d U: HSurface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);
; q& a9 M6 G! j6 iStream stream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, s, new Rectangle(int locationX, int locationY, 1, 1));+ D% ^' L/ N2 z+ @. O0 G
Bitmap bmp = new Bitmap(stream);
: k# R3 P6 P, j- |. Hstream.Dispose();; p2 q' y. p6 D9 g( F! Y
! ?- Y! W' z5 V" G" E* e1 n! s
Color c = bmp.GetPixel(0, 0);
1 [, Q" A* I1 ^" h) q t; Fif (c.R == 255 && c.G == 0 && c.B == 0)* Z( ~7 ^, [4 g) @9 x. c
{, W4 S4 J$ K9 ` F* [" V$ S8 ]
// do something' i% u! B9 G9 u
break;! @" k: T- j, c' J
} |