几个老外关于DX屏幕像素颜色判断的热烈讨论
+ c& n- c: P: V/ y$ ghttp://www.xtremedotnettalk.com/showthread.php?p=4661595 K% g$ {0 x% _' g# G+ }+ q5 @
" |- }- e0 }$ [0 g* O, _Surface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);
* B/ l0 z8 Q7 u ?# ?+ Q, T# Ruint[,] data = (uint[,])s.LockRectangle(new Rectangle(0, 0, 32, 32), LockFlags.ReadOnly);& B7 W9 R& \& M; O' c
# A) G! g1 i/ o) I& x! n
for (int n = 0; n < 100; i++)% l' d; p0 A5 _8 v- Q1 D
{9 s% ]5 d* d& A
for (int j = 0; j < 100; j++)
7 A7 u+ U w! ?7 Y {4 J$ e- @/ f8 q8 g3 z7 ]
data[n, j] = (uint)Color.White.ToArgb();6 S% U( Q1 ^6 k% u* s9 J
}
) ^5 Y! D# a' O0 w- }' [: t}
2 \4 N2 B3 x$ l( q& k% Q; ?1 I4 l: z7 i1 H3 n
----------------------------------------------------0 d- @/ y& K5 o( k- `( x
Surface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);: I: p6 `( a" ]% A
Stream stream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, s, new Rectangle(int locationX, int locationY, 1, 1));
! D' |- w2 a% ?8 tBitmap bmp = new Bitmap(stream);: f$ {/ m5 i9 w* W$ R' }; ^
stream.Dispose();# O( a: J9 B# I6 f+ t2 q0 i
3 ~; w0 K( a' q; ^$ ?2 t
Color c = bmp.GetPixel(0, 0);4 u$ j, w7 l2 {6 Q- h% w/ ?
if (c.R == 255 && c.G == 0 && c.B == 0)
9 U! U1 S1 y- K9 X B+ _: c{
; [2 }- C) C+ q5 ] // do something
2 h) F8 [* R+ S1 q" p0 o8 o; V break;0 O; V" ]4 _5 P/ x; S' E
} |