From 7b58235a5a5deda53eeeb48290043bccc6d6b988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Tue, 29 Mar 2011 13:02:06 -0400 Subject: improved pixel dump method --- GdiTest/BitBltDrawingArea.cs | 11 +++++++++-- GdiTest/LineToDrawingArea.cs | 19 ++++++++++++++++--- GdiTest/MainWindow.cs | 2 +- GdiTest/TestDrawingArea.cs | 1 + GdiTest/Win32GDI.cs | 6 ++---- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/GdiTest/BitBltDrawingArea.cs b/GdiTest/BitBltDrawingArea.cs index 269f2f1..68f90f6 100644 --- a/GdiTest/BitBltDrawingArea.cs +++ b/GdiTest/BitBltDrawingArea.cs @@ -6,7 +6,9 @@ using System.Drawing; namespace GdiTest { public class BitBltDrawingArea : TestDrawingArea - { + { + String dumpText; + public BitBltDrawingArea () { } @@ -60,7 +62,7 @@ namespace GdiTest { for (int x = 0; x < 16; x++) { - System.Drawing.Color color = GDI_Win32.GetPixelColor(x, y); + System.Drawing.Color color = GDI_Win32.GetPixelColor(hdc, x, y); text += String.Format("0x{0:X}, ", color.ToArgb()); } text += "\n"; @@ -69,6 +71,11 @@ namespace GdiTest return text; } + + public override String getDumpText () + { + return dumpText; + } } } diff --git a/GdiTest/LineToDrawingArea.cs b/GdiTest/LineToDrawingArea.cs index 0144258..1e78aff 100644 --- a/GdiTest/LineToDrawingArea.cs +++ b/GdiTest/LineToDrawingArea.cs @@ -15,6 +15,7 @@ namespace GdiTest } private bool rendered; + private String dumpText; public LineToDrawingArea() { @@ -174,6 +175,9 @@ namespace GdiTest } } } + + dumpText = this.dump(); + return true; } @@ -182,7 +186,7 @@ namespace GdiTest String text = ""; Win32GDI GDI_Win32 = Win32GDI.getInstance(); - + if (GDI_Win32.isAvailable()) { System.Drawing.Graphics wg = Gtk.DotNet.Graphics.FromDrawable(this.GdkWindow, true); @@ -192,8 +196,12 @@ namespace GdiTest { for (int x = 0; x < 16; x++) { - System.Drawing.Color color = GDI_Win32.GetPixelColor(x, y); - text += String.Format("0x{0:X}, ", color.ToArgb()); + System.Drawing.Color color = GDI_Win32.GetPixelColor(hdc, x, y); + + if (color.R == 255) + text += "0xFF, "; + else + text += "0x00, "; } text += "\n"; } @@ -201,6 +209,11 @@ namespace GdiTest return text; } + + public override String getDumpText() + { + return dumpText; + } } } diff --git a/GdiTest/MainWindow.cs b/GdiTest/MainWindow.cs index 214c593..e422090 100644 --- a/GdiTest/MainWindow.cs +++ b/GdiTest/MainWindow.cs @@ -52,7 +52,7 @@ public partial class MainWindow : Gtk.Window } protected virtual void OnDumpButtonClicked (object sender, System.EventArgs e) { - String dumpText = testDrawingArea.dump(); + String dumpText = testDrawingArea.getDumpText(); dumpTextView.Buffer.Text = dumpText; } diff --git a/GdiTest/TestDrawingArea.cs b/GdiTest/TestDrawingArea.cs index 27e9d24..ecc5d61 100644 --- a/GdiTest/TestDrawingArea.cs +++ b/GdiTest/TestDrawingArea.cs @@ -11,6 +11,7 @@ namespace GdiTest } abstract public String dump(); + abstract public String getDumpText(); } } diff --git a/GdiTest/Win32GDI.cs b/GdiTest/Win32GDI.cs index 389e48e..1d1c722 100644 --- a/GdiTest/Win32GDI.cs +++ b/GdiTest/Win32GDI.cs @@ -132,11 +132,9 @@ namespace GdiTest return 0; } - public System.Drawing.Color GetPixelColor(int x, int y) + public System.Drawing.Color GetPixelColor(IntPtr hdc, int X, int Y) { - IntPtr hdc = GetDC(IntPtr.Zero); - uint pixel = Callbacks.GetPixel(hdc, x, y); - ReleaseDC(IntPtr.Zero, hdc); + uint pixel = Callbacks.GetPixel(hdc, X, Y); System.Drawing.Color color = System.Drawing.Color.FromArgb((int)(pixel & 0x000000FF), (int)(pixel & 0x0000FF00) >> 8, (int)(pixel & 0x00FF0000) >> 16); -- cgit v1.2.3