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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
using Gtk;
using Cairo;
using System;
using System.Drawing;
namespace GdiTest
{
public class BitBltDrawingArea : TestDrawingArea
{
Bitmap bmp_SRC;
Bitmap bmp_DST;
Bitmap bmp_PAT;
String dumpText;
public BitBltDrawingArea ()
{
String cwd = Environment.CurrentDirectory;
bmp_SRC = new Bitmap(cwd + "\\..\\..\\resources\\bmp_SRC.bmp");
bmp_DST = new Bitmap(cwd + "\\..\\..\\resources\\bmp_DST.bmp");
bmp_PAT = new Bitmap(cwd + "\\..\\..\\resources\\bmp_PAT.bmp");
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
using (Context cg = Gdk.CairoHelper.Create (args.Window))
{
Win32GDI GDI_Win32 = Win32GDI.getInstance();
if (GDI_Win32.isAvailable())
{
System.Drawing.Graphics wg = Gtk.DotNet.Graphics.FromDrawable(this.GdkWindow, true);
IntPtr hdc = wg.GetHdc();
drawBitmap(hdc, 0, 0, bmp_SRC);
drawBitmap(hdc, 16, 0, bmp_DST);
drawBitmap(hdc, 32, 0, bmp_PAT);
dumpText += "unsigned char bmp_SRC[" + bmp_SRC.Width * bmp_SRC.Height + "] = \n";
dumpText += this.dump(hdc, 0, 0, bmp_SRC.Width, bmp_SRC.Height) + "\n";
dumpText += "unsigned char bmp_DST[" + bmp_DST.Width * bmp_DST.Height + "] = \n";
dumpText += this.dump(hdc, 16, 0, bmp_DST.Width, bmp_DST.Height) + "\n";
dumpText += "unsigned char bmp_PAT[" + bmp_PAT.Width * bmp_PAT.Height + "] = \n";
dumpText += this.dump(hdc, 32, 0, bmp_PAT.Width, bmp_PAT.Height) + "\n";
//GDI_Win32.BitBlt(dc, 70, 0, 60, 60, dc, 0, 0, GDI.SRCCOPY);
}
}
return true;
}
public void drawBitmap(IntPtr hdc, int X, int Y, Bitmap bmp)
{
Win32GDI GDI_Win32 = Win32GDI.getInstance();
for (int y = Y; y < Y + bmp.Height; y++)
{
for (int x = X; x < X + bmp.Width; x++)
{
int p = 0;
System.Drawing.Color pixel = bmp.GetPixel(x - X, y - Y);
if (pixel.R == 0 && pixel.G == 0 && pixel.B == 0)
p = 0;
else
p = 0xFFFFFF;
GDI_Win32.SetPixel(hdc, x, y, p);
}
}
}
public String dump(IntPtr hdc, int X, int Y, int W, int H)
{
String text = "";
Win32GDI GDI_Win32 = Win32GDI.getInstance();
if (GDI_Win32.isAvailable())
{
text += "{\n";
for (int y = Y; y < Y + H; y++)
{
text += "\t\"";
for (int x = X; x < X + W; x++)
{
int p = GDI_Win32.GetPixel(hdc, x, y);
if (p == 0)
text += "\\x00";
else
text += "\\xFF";
}
text += "\"\n";
}
text += "};\n";
}
return text;
}
public override String getDumpText ()
{
return dumpText;
}
}
}
|