Bonsoir, j'essaie de copier un bitmap sur un autre (les deux sont en 24 bits) en mode xor .

Voilà mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class XorFilter : IFilter
	{
		public void Process(Point pos, Graphics dest, Bitmap src)
		{
			IntPtr dst = dest.GetHdc();
			IntPtr source=CreateCompatibleDC(dst);
			IntPtr org=SelectObject(source,src.GetHbitmap());
			UInt32 dwrop = 0x00660046;//srcinvert
			BitBlt(dst, pos.X, pos.Y, src.Width, src.Height, source, 0, 0, dwrop);
			IntPtr n = SelectObject(source, org);
			DeleteObject(n);
			DeleteDC(source);
			dest.ReleaseHdc(dst);
		}
 
		[DllImport("gdi32.dll")]
		private static extern bool BitBlt(IntPtr hdcDest,	
						Int32 nXDest,
						Int32 nYDest,
						Int32 nWidth,
						Int32 nHeight,
						IntPtr hdcSrc,
						Int32 nXSrc,
						Int32 nYSrc,
						UInt32 dwRop);
 
		[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
		static extern IntPtr CreateCompatibleDC(IntPtr hdc);
 
		[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
		static extern bool DeleteDC(IntPtr hdc);
 
		[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
		static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
 
		[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
		static extern bool DeleteObject(IntPtr hObject);
	}
Je me suis aidé de ce site :
http://pinvoke.net/default.aspx/gdi32/BitBlt.html
(en passant l'utilité du dernier SelectObject suivi d'un DeleteObject m'échappe un peu)

Le problème c'est que j'obtiens comme une copie normale, sauf que le noir pur n'est pas transféré et les couleurs sont légèrement modifiées par rapport à la source . En outre les pixels transparents du bitmap sources deviennent bleus ...