|
|
|
[C#]
using (Bitmap bm = new Bitmap(200, 200)) {
using (Graphics g = Graphics.FromImage(bm)) {
g.FillRectangle(Brushes.DarkRed, new RectangleF(0, 0, 100, 100));
g.FillRectangle(Brushes.DarkOliveGreen, new RectangleF(100, 0, 100, 100));
g.FillRectangle(Brushes.CornflowerBlue, new RectangleF(0, 100, 100, 100));
g.FillRectangle(Brushes.Goldenrod, new RectangleF(100, 100, 100, 100));
bm.Save(Server.MapPath("IG8_Bitmap_GetPixel.png"));
}
Response.Write("Top Left Color is " + bm.GetPixel(50, 50).ToString() + "<br>\r\n");
Response.Write("Top Right Color is " + bm.GetPixel(150, 50).ToString() + "<br>\r\n");
Response.Write("Bottom Left Color is " + bm.GetPixel(50, 150).ToString() + "<br>\r\n");
Response.Write("Bottom Right Color is " + bm.GetPixel(150, 150).ToString() + "<br>\r\n");
}
The graphics file and text output that this produces are shown
below.
Top Left Color is R=139, G=0, B=0
Top Right Color is R=85, G=107, B=47
Bottom Left Color is R=100, G=149, B=237
Bottom Left Color is R=218, G=165, B=32

IG8_Bitmap_GetPixel.png
|