M
Max Bolingbroke
Hi,
I'm trying to get the color of a palette-based BMP image at a certain
point, using Bitmap.GetPixel. However, the method call isnt returning
the correct color! Every editing program on my computer agrees that the
pixel in question is, for instance #00CC00, but GetPixel insists that
the pixel is actually #00C800.
Does anyone know why this might be the case?
Thanks in advance!
Max Bolingbroke
The image in question is here (104kb download):
http://www.omega-prime.co.uk/images/Map.bmp
And here is a demo app that demonstrates the problem:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
namespace PocketDebug
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private Bitmap bitmap;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
bitmap = new Bitmap("/Program Files/PocketDebug/Map.bmp");
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.Text = "Form1";
this.Paint += new
System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Brush brush = new SolidBrush(Color.Black);
Font font = new Font("Tahoma", 10.0f, FontStyle.Regular);
Color color = bitmap.GetPixel(89, 115);
e.Graphics.DrawString(color.R.ToString() + ", " + color.G.ToString()
+ ", " + color.B.ToString(), font, brush, 0.0f, 0.0f);
}
}
}
I'm trying to get the color of a palette-based BMP image at a certain
point, using Bitmap.GetPixel. However, the method call isnt returning
the correct color! Every editing program on my computer agrees that the
pixel in question is, for instance #00CC00, but GetPixel insists that
the pixel is actually #00C800.
Does anyone know why this might be the case?
Thanks in advance!
Max Bolingbroke
The image in question is here (104kb download):
http://www.omega-prime.co.uk/images/Map.bmp
And here is a demo app that demonstrates the problem:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
namespace PocketDebug
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private Bitmap bitmap;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
bitmap = new Bitmap("/Program Files/PocketDebug/Map.bmp");
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.Text = "Form1";
this.Paint += new
System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Brush brush = new SolidBrush(Color.Black);
Font font = new Font("Tahoma", 10.0f, FontStyle.Regular);
Color color = bitmap.GetPixel(89, 115);
e.Graphics.DrawString(color.R.ToString() + ", " + color.G.ToString()
+ ", " + color.B.ToString(), font, brush, 0.0f, 0.0f);
}
}
}