几个老外关于DX屏幕像素颜色判断的热烈讨论
% F4 D" l7 F8 E0 `, [http://www.xtremedotnettalk.com/showthread.php?p=4661596 \$ W" u3 @# p" @( J% P
- f8 U8 P: e) t- t& ZSurface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);7 a Z, R W% w$ a- K& \9 W* s
uint[,] data = (uint[,])s.LockRectangle(new Rectangle(0, 0, 32, 32), LockFlags.ReadOnly);3 A$ F5 c- o2 w2 ?1 p
$ @2 R9 N0 d3 qfor (int n = 0; n < 100; i++)
0 I. e. y# N' @1 m9 m2 c, q5 m{
. j% b; @' Y' V" ^: y; p- c, e for (int j = 0; j < 100; j++)5 b$ u6 T; l$ ?& Q2 q% {
{' r5 L1 K! j. s1 _9 D6 h4 `2 g
data[n, j] = (uint)Color.White.ToArgb();
w+ C% q+ }1 f6 _ }
/ h, ?# `( }3 V2 u% d}# f4 B$ `4 q- o6 v
+ L. k6 L+ d1 b4 R' I
----------------------------------------------------
2 I6 k! c3 ^) L# k. H) f4 eSurface s = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);* d7 b( |& m( m7 f8 k
Stream stream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, s, new Rectangle(int locationX, int locationY, 1, 1));% C& f0 ?6 e1 s6 N6 E
Bitmap bmp = new Bitmap(stream);
r2 W3 t% o- {- F! P" s6 x7 X% nstream.Dispose();9 a5 j5 B1 s( x5 ]
7 h v# t3 N; @; K) X+ E. Z
Color c = bmp.GetPixel(0, 0);
+ L9 u% m, [8 v& L# Lif (c.R == 255 && c.G == 0 && c.B == 0)/ D3 Q: K& Q3 ~- u& Y1 z
{% T! m! h% G/ H4 Q) |
// do something. ^8 p6 K5 n* t) ?2 B, M
break;- Q: Y0 l& z! i% o0 J7 C$ @; F9 A
} |