EDN Admin
Well-known member
Hi mates,
Theres a code:
<div style="color:black; background-color:white
<pre><span style="color:blue using System.Windows.Forms;
<span style="color:blue using System.Drawing;
<span style="color:blue using System.Drawing.Imaging;
<span style="color:blue using System.Runtime.InteropServices;
<span style="color:blue public <span style="color:blue class Test : Form
{
<span style="color:blue public <span style="color:blue static <span style="color:blue long SRCINVERT = 0x00660046;
[DllImport(<span style="color:#a31515 "gdi32.dll")]
<span style="color:blue public <span style="color:blue static <span style="color:blue extern <span style="color:blue bool BitBlt(
IntPtr hdcDest, <span style="color:blue int nXDest, <span style="color:blue int nYDest, <span style="color:blue int nWidth, <span style="color:blue int nHeight, IntPtr hdcSrc,
<span style="color:blue int nXSrc, <span style="color:blue int nYSrc, <span style="color:blue long dwRop);
[DllImport(<span style="color:#a31515 "gdi32.dll", EntryPoint = <span style="color:#a31515 "SelectObject")]
<span style="color:blue public <span style="color:blue static <span style="color:blue extern IntPtr SelectObject(IntPtr hdc, IntPtr h);
<span style="color:blue public <span style="color:blue void TestXOR()
{
Bitmap test = <span style="color:blue new Bitmap(100, 100);
Graphics g = Graphics.FromImage(test);
g.DrawLine(Pens.White, <span style="color:blue new Point(0, 0), <span style="color:blue new Point(100, 100));
test.Save(<span style="color:#a31515 @"c:testBefore.bmp", ImageFormat.Bmp);
IntPtr testHDC = g.GetHdc();
SelectObject(testHDC, test.GetHbitmap());
BitBlt(testHDC, 0, 0, 100, 100, testHDC, 0, 0, SRCINVERT);
g.ReleaseHdc(testHDC);
test.Save(<span style="color:#a31515 @"c:testAfter.bmp", ImageFormat.Bmp);
g.Dispose();
}
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args)
{
Test tst = <span style="color:blue new Test();
tst.TestXOR();
tst.Dispose();
}
}
[/code]
<br/>
<br/>
This code should create 2 bitmaps like the next: http://itbrigada.ru/img/testBefore.bmp Before
http://itbrigada.ru/img/testAfter.bmp After
But it doesnt. The idea is to Blit same DCs in XOR mode, so - result is black.
In fact, it does two equal images like Before.
If you know the reason why. please, give me a hint... what am I doing wrong?
<br/>
View the full article
Theres a code:
<div style="color:black; background-color:white
<pre><span style="color:blue using System.Windows.Forms;
<span style="color:blue using System.Drawing;
<span style="color:blue using System.Drawing.Imaging;
<span style="color:blue using System.Runtime.InteropServices;
<span style="color:blue public <span style="color:blue class Test : Form
{
<span style="color:blue public <span style="color:blue static <span style="color:blue long SRCINVERT = 0x00660046;
[DllImport(<span style="color:#a31515 "gdi32.dll")]
<span style="color:blue public <span style="color:blue static <span style="color:blue extern <span style="color:blue bool BitBlt(
IntPtr hdcDest, <span style="color:blue int nXDest, <span style="color:blue int nYDest, <span style="color:blue int nWidth, <span style="color:blue int nHeight, IntPtr hdcSrc,
<span style="color:blue int nXSrc, <span style="color:blue int nYSrc, <span style="color:blue long dwRop);
[DllImport(<span style="color:#a31515 "gdi32.dll", EntryPoint = <span style="color:#a31515 "SelectObject")]
<span style="color:blue public <span style="color:blue static <span style="color:blue extern IntPtr SelectObject(IntPtr hdc, IntPtr h);
<span style="color:blue public <span style="color:blue void TestXOR()
{
Bitmap test = <span style="color:blue new Bitmap(100, 100);
Graphics g = Graphics.FromImage(test);
g.DrawLine(Pens.White, <span style="color:blue new Point(0, 0), <span style="color:blue new Point(100, 100));
test.Save(<span style="color:#a31515 @"c:testBefore.bmp", ImageFormat.Bmp);
IntPtr testHDC = g.GetHdc();
SelectObject(testHDC, test.GetHbitmap());
BitBlt(testHDC, 0, 0, 100, 100, testHDC, 0, 0, SRCINVERT);
g.ReleaseHdc(testHDC);
test.Save(<span style="color:#a31515 @"c:testAfter.bmp", ImageFormat.Bmp);
g.Dispose();
}
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args)
{
Test tst = <span style="color:blue new Test();
tst.TestXOR();
tst.Dispose();
}
}
[/code]
<br/>
<br/>
This code should create 2 bitmaps like the next: http://itbrigada.ru/img/testBefore.bmp Before
http://itbrigada.ru/img/testAfter.bmp After
But it doesnt. The idea is to Blit same DCs in XOR mode, so - result is black.
In fact, it does two equal images like Before.
If you know the reason why. please, give me a hint... what am I doing wrong?
<br/>
View the full article