几个老外关于DX屏幕像素颜色判断的热烈讨论
! o0 z L( I# U0 Qhttp://www.xtremedotnettalk.com/showthread.php?p=466159
7 l6 V: v+ ~! m) Y4 `7 U& Z5 S
. d" l' ? ^; P2 m% x/ BSurface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);' i( h9 J$ f6 c9 U! l% ~
uint[,] data = (uint[,])s.LockRectangle(new Rectangle(0, 0, 32, 32), LockFlags.ReadOnly);
% m+ l: o7 Y: v
# q& M m! _+ E7 i$ i: ^9 {for (int n = 0; n < 100; i++)
; K* B h9 |+ L3 b9 w! ~. Q{
- I0 b2 W9 i( U% [8 N# ^# ^ for (int j = 0; j < 100; j++)
, [" t2 u* U' \: }) z* X* C: X {
+ }/ P0 m, r* d+ d' Y data[n, j] = (uint)Color.White.ToArgb();
3 f% k# u. ~3 {. }4 \ }
; j9 X1 n8 b) ]: L+ |# s}
& c" x$ p9 u$ ]$ y
; O9 ^3 W) x3 _2 e---------------------------------------------------- ^! C- c) @, V5 N
Surface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);
5 D. ^ k/ H+ w* d5 H4 n/ ?Stream stream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, s, new Rectangle(int locationX, int locationY, 1, 1));
9 ~ [6 l6 j' m4 BBitmap bmp = new Bitmap(stream);
& i D$ G0 j( f+ R( @& Wstream.Dispose();! b! u4 `# r+ V* C
1 Z% W2 g/ | R! O& `' y
Color c = bmp.GetPixel(0, 0);2 S0 j9 w( Z0 Y7 v
if (c.R == 255 && c.G == 0 && c.B == 0)
# ~7 Z. a" \0 w9 ]{
. ~# E5 P9 o, a4 i4 p5 H1 _* L // do something
0 g7 t( k# s" w0 s$ r9 w8 J break;
* O, E1 \7 ^0 k% g3 |1 v! [+ E9 { v} |