几个老外关于DX屏幕像素颜色判断的热烈讨论
9 L. C9 g- \! m% `+ _http://www.xtremedotnettalk.com/showthread.php?p=4661592 P4 `, A* d, C1 |8 P" e
5 M; i5 ?$ z5 ^$ ^
Surface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);4 t0 u! P( ]* k( B! @0 ~- \
uint[,] data = (uint[,])s.LockRectangle(new Rectangle(0, 0, 32, 32), LockFlags.ReadOnly);
, u5 u( {% _. n! n- d2 w5 V- w( v! u3 D% f. T1 p) K: u7 b
for (int n = 0; n < 100; i++)) V9 C Y9 J: o. F6 K9 j2 y
{. t. Z, |4 C1 t, _
for (int j = 0; j < 100; j++)9 W+ f4 d* E2 o: [- Z' a5 c
{+ R% k% S+ F- G7 S, S3 W
data[n, j] = (uint)Color.White.ToArgb();0 r: ] K' I8 ]- d# N) K
}
/ o9 B9 `* o/ x8 N0 U}1 j: t; s) l) W8 O) P( w
' Y8 l# M" [0 H( q----------------------------------------------------
6 `) @1 \$ L' `; \' q" O% f# A8 A# ISurface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);9 ]0 ]" u5 b }" K+ ], e
Stream stream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, s, new Rectangle(int locationX, int locationY, 1, 1));" Q! K/ d5 g. Y/ v, o0 U+ Y
Bitmap bmp = new Bitmap(stream);: `7 ]& K$ ]9 N/ i3 I
stream.Dispose();
. C# F! G7 ^3 \
) ] O; m5 ~4 b9 fColor c = bmp.GetPixel(0, 0);$ K9 w- e F( V' v% V9 |
if (c.R == 255 && c.G == 0 && c.B == 0)8 |4 T" e8 l7 C4 k4 c9 A
{
. A+ v3 M8 v& b9 H5 w a. i0 N // do something
9 Y. k J; i; O9 E4 Q+ d, N break;5 T2 E! B$ l. n# l' U1 Q
} |