I need to draw an Google marker image via C# Graphics
for that i;ll need the exact coordinates of Google marker
how can i do that Please help .
My Current Code is .
private void Shape8(PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
int startMarker = 0;
int MarkerDiameter = 30;
int EllipseDiameter = 15;
const int StartX = 150;
const int StartY = 350;
int X = StartX;
int Y = StartY;
GraphicsPath path = new GraphicsPath();
Rectangle ellipse = new Rectangle(X, Y, EllipseDiameter, EllipseDiameter);
path.AddEllipse(ellipse);
path.CloseFigure();
X = X + (EllipseDiameter / 2) - (MarkerDiameter / 2);
Y = Y - (EllipseDiameter * 2) - (MarkerDiameter / 2);
startMarker = StartY - 10 - (Convert.ToInt32(MarkerDiameter * 1.5));//Space Between marker and circle.
AddMarker8(ref path, X, startMarker, StartX, StartY, EllipseDiameter, MarkerDiameter, "Concept1");
e.Graphics.FillPath(Brushes.Pink, path);
e.Graphics.DrawPath(Pens.Black, path);
e.Graphics.FillEllipse(Brushes.White, ellipse);
path.CloseAllFigures();
}
private void AddMarker8(ref GraphicsPath path, int X, int Y, int StartX, int StartY, int EllipseDiameter, int MarkerDiameter, string conceptName)
{
float startAngle = 180.0F;
float sweepAngle = 180.0F;
int fontStyle = (int)FontStyle.Regular;
path.AddString(conceptName, new FontFamily("Arial"), fontStyle, 15, new Point(X + (MarkerDiameter / 2), Y - 15), lblFormat);
Rectangle rect = new Rectangle(X, Y, MarkerDiameter, MarkerDiameter);
path.AddArc(rect, startAngle, sweepAngle);
Point lastpoint = new Point(X + (MarkerDiameter / 2), (Y + (MarkerDiameter * 2)) - (MarkerDiameter / 2));
path.AddCurve(new Point[] {
new Point(X+(MarkerDiameter), Y + (MarkerDiameter / 2)), //a
new Point((X +MarkerDiameter)-(MarkerDiameter/4) ,(Y +(MarkerDiameter ))) ,//A.5
lastpoint ,//c
new Point(X +(MarkerDiameter / 4) ,(Y +(MarkerDiameter ))) ,//B.5
new Point(X, Y + (MarkerDiameter / 2))//b
}, 0.5f);
path.CloseFigure();
}
Try the following code
private void DrawMarker(int X, int Y, double Scale, Color BorderColor, Color FillColor, PaintEventArgs e, char Letter = '\0')
{
Graphics G1 = e.Graphics;
Pen Pen1 = new Pen(BorderColor, 8);
SolidBrush Brush1 = new SolidBrush(BorderColor);
SolidBrush Brush2 = new SolidBrush(FillColor);
G1.SmoothingMode = SmoothingMode.AntiAlias;
G1.ResetTransform();
G1.ScaleTransform(Convert.ToSingle(0.4 * Scale), Convert.ToSingle(0.4 * Scale));
GraphicsPath GraphicsPath1 = new GraphicsPath();
GraphicsPath1.AddBeziers(new Point(X + 51, Y + 169), new Point(X + 47, Y + 137), new Point(X + 42, Y + 107), new Point(X + 14, Y + 77));
GraphicsPath1.AddBeziers(new Point(X + 87, Y + 77), new Point(X + 62, Y + 107), new Point(X + 55, Y + 137), new Point(X + 51, Y + 169));
GraphicsPath GraphicsPath2 = new GraphicsPath();
GraphicsPath2.AddEllipse(X + 5, Y + 5, 92, 92);
G1.FillPath(Brush2, GraphicsPath2);
G1.DrawPath(Pen1, GraphicsPath2);
G1.SetClip(new Rectangle(X, Y + 85, 103, 84));
G1.FillPath(Brush2, GraphicsPath1);
G1.DrawPath(Pen1, GraphicsPath1);
G1.ResetClip();
if (Letter != '\0')
{
Font Font1 = new Font("Arial", 52, FontStyle.Bold);
StringFormat StringFormat1 = new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
};
G1.DrawString(Convert.ToString(Letter), Font1, Brush1, new Rectangle(X, Y, 103, 103), StringFormat1);
Font1.Dispose();
StringFormat1.Dispose();
}
else
{
G1.FillEllipse(Brush1, new Rectangle(X + 32, Y + 32, 37, 37));
}
Pen1.Dispose();
Brush1.Dispose();
Brush2.Dispose();
GraphicsPath1.Dispose();
GraphicsPath2.Dispose();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
DrawMarker(0, 0, 0.5, Color.Black, Color.Tomato, e, Convert.ToChar("A"));
DrawMarker(80, 0, 0.8, Color.Black, Color.Red, e, Convert.ToChar("B"));
DrawMarker(160, 0, 1, Color.Black, Color.Linen, e, Convert.ToChar("C"));
DrawMarker(210, 0, 1.3, Color.Black, Color.Orange, e, Convert.ToChar("D"));
DrawMarker(260, 0, 1.6, Color.Black, Color.Green, e);
}
after running it, the result should be like this
Related
I can not find any information on how to draw a few dots (for Split separator slider) as shown in the first picture.
I am trying to draw this:
Right now, my custom control code is drawing a straight line with a shadow
public class CustomPaintSplitter : SplitContainer {
...
protected override void OnPaint(PaintEventArgs pe)
{
Graphics g = pe.Graphics;
Rectangle r = ClientRectangle;
g.FillRectangle(new SolidBrush(BackColor), r);
if (Orientation == Orientation.Horizontal)
{
SplitterWidth = 9;
int recWidth = SplitterRectangle.Width / 3;
Rectangle split_rect = new(SplitterRectangle.X + recWidth, SplitterRectangle.Y, SplitterRectangle.Width - recWidth, SplitterRectangle.Height);
int x = split_rect.X;
int y = split_rect.Y + 3;
g.DrawLine(new Pen(SystemColors.ControlLightLight), x, y, x, y + 2);
g.DrawLine(new Pen(SystemColors.ControlLightLight), x, y, x + recWidth, y);
g.DrawLine(new Pen(SystemColors.ControlDark), x, y + 2, x + recWidth, y + 2);
g.DrawLine(new Pen(SystemColors.ControlDark), x + recWidth, y, x + recWidth, y + 2);
}
// Calling the base class OnPaint
base.OnPaint(pe);
}
}
How can this be achieved? I tried different Point[] methods on the internet, but none of them draw anything near what I am trying to achieve.
Even a parameter to specify the number of "dots" drawn would be a plus.
Any help is appreciated!
I just draw it on a panel but you can use it the same way.
private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
Brush b = new SolidBrush(Color.Gray);
e.Graphics.FillEllipse(b, new Rectangle(10, 5, 5, 5));
e.Graphics.FillEllipse(b, new Rectangle(20, 5, 5, 5));
e.Graphics.FillEllipse(b, new Rectangle(30, 5, 5, 5));
}
I have this little code to use AddArc() method in a label, but when I execute the code the label disappears. I believe it is the numbers I have used, I followed instructions from the Windows documentation and it had these parameters there too.
GraphicsPath gp = new GraphicsPath();
Rectangle rec = new Rectangle(20, 20, 50, 100);
gp.AddArc(rec, 0 , 180);
label2.Region = new Region(gp);
label2.Invalidate();
I used another code to make the correct way or curve in a text
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var center = new Point(Width / 2, Height / 2);
var radius = Math.Min(Width, Height) / 3;
var text = "Hello";//txtUp.Text;
var font = new Font(FontFamily.GenericSansSerif, 24, FontStyle.Bold);
for (var i = 0; i < text.Length; ++i)
{
var c = new String(text[i], 1);
var size = e.Graphics.MeasureString(c, font);
var charRadius = radius + size.Height;
var angle = (((float)i / text.Length) - 2);
var x = (int)(center.X + Math.Cos(angle) * charRadius);
var y = (int)(center.Y + Math.Sin(angle) * charRadius);
e.Graphics.TranslateTransform(x, y);
e.Graphics.RotateTransform((float)(90 + 360 * angle / (2 * Math.PI)));
e.Graphics.DrawString(c, font, Brushes.Red, 0, 0);
e.Graphics.ResetTransform();
e.Graphics.DrawArc(new Pen(Brushes.Transparent, 2.0f), center.X - radius, center.Y - radius, radius * 2, radius * 2, 0, 360);
}
}
but it wont show in front of a panel is it possible.
This is what it looks like:
Is it possible to move that text in front of the green circle?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Below I've created a program using C# that creates a smiley face. It also moves across the screen. I cannot figure out how to get the smiley face to bounce off the edges and around the screen. Please Help. Thank you.
*/using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HappyFace
{
public partial class HappyFace : Form
{
int xpos = 0;
int ypos = 0;
int width = 0;
int length = 0;
int startAngle = 45;
int sweepAngle = 90;
public HappyFace()
{
InitializeComponent();
}
private void HappyFace_Load(object sender, EventArgs e)
{
}
private void HappyFace_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen myPen = new Pen(Brushes.Red, 7);
Pen myPen2 = new Pen(Brushes.Green, 7);
//g.DrawLine(myPen, 0, 0, 500, 500);
//g.DrawLine(myPen, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height);
//g.DrawLine(myPen2, 0, this.ClientRectangle.Height, this.ClientRectangle.Width, 0);
//g.DrawLine(myPen2, this.ClientRectangle.Left, this.ClientRectangle.Bottom, this.ClientRectangle.Right, ClientRectangle.Top);
int endX = this.ClientRectangle.Width;
int endY = this.ClientRectangle.Height;
//string msg = String.Format("endX = {0} endY = {1}", endX, endY);
//MessageBox.Show(msg);
int xCenter = this.ClientRectangle.Left + (this.ClientRectangle.Width / 2);
int yCenter = this.ClientRectangle.Top + (this.ClientRectangle.Height / 2);
Pen circlePen = new Pen(Brushes.Black, 9);
//g.DrawEllipse(circlePen, xCenter - 50, yCenter - 50, 100, 100);
// g.FillEllipse(Brushes.Orange, xCenter -50, yCenter - 50, 100, 100);
Font myFont = new Font("Monotype Corsiva", 43, FontStyle.Bold);
g.DrawString("Happy Face", myFont, Brushes.Aqua, 300, 25);
//g.DrawArc(circlePen, xpos, width, length, startAngle, sweepAngle);
g.DrawEllipse(circlePen, xpos, ypos + 130, 250, 250);
g.FillEllipse(Brushes.PeachPuff, xpos, ypos + 130, 250, 250);
g.DrawEllipse(circlePen, xpos + 65, ypos + 200, 20, 35);
g.FillEllipse(Brushes.Black, xpos + 65, ypos + 200, 20, 35);
g.DrawEllipse(circlePen, xpos + 160, ypos + 200, 20, 35);
g.FillEllipse(Brushes.Black, xpos + 160, ypos + 200, 20, 35);
g.DrawArc(circlePen, xpos + 60, ypos + 215, 130, 120, 35, 115);
}
private void timer1_Tick(object sender, EventArgs e)
{
xpos = xpos + 3;
if(xpos >= this.ClientRectangle.Right - 250)
{
xpos = 0;
}
this.Invalidate();
}
}
}*/
Well, I was a bit bored. I'll assume that the object is going to move in a 45 degrees trajectory,and that when it collides with the bounds it would change by 90ยบ.
What I would do (this is a very simple solution) is, first of all, define the direction in both axes in which i want the "smiley" to move,the step in each timer tick, the position of the center and the size of the object, something like:
int xpos = 0;
int ypos = 130;
int step = 10;
int width = 250;
int height = 250;
int directionX = +1;
int directionY = -1;
The timer would just increase the x and y positions:
private void timer1_Tick(object sender, EventArgs e)
{
xpos += 10*directionX;
ypos += 10*directionY;
checkBounds(); //This would check if the object collides with the bounds
this.Invalidate();
}
The checkBounds method check if the object collides with the bounds:
private void checkBounds()
{
if (ypos < 0 + step || ypos + height+ step > ClientRectangle.Height)
{
directionY *= -1;
}
if (xpos < 0 + step || xpos + width + step > ClientRectangle.Width)
{
directionX *= -1;
}
}
Finally, the Paint method is similar to yours, just adjusting some values:
private void Form2_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen myPen = new Pen(Brushes.Red, 7);
Pen myPen2 = new Pen(Brushes.Green, 7);
int endX = this.ClientRectangle.Width;
int endY = this.ClientRectangle.Height;
int xCenter = this.ClientRectangle.Left + (this.ClientRectangle.Width / 2);
int yCenter = this.ClientRectangle.Top + (this.ClientRectangle.Height / 2);
Pen circlePen = new Pen(Brushes.Black, 9);
Font myFont = new Font("Monotype Corsiva", 43, FontStyle.Bold);
g.DrawString("Happy Face", myFont, Brushes.Aqua, 300, 25);
g.DrawEllipse(circlePen, xpos, ypos, 250, 250);
g.FillEllipse(Brushes.PeachPuff, xpos, ypos, 250, 250);
g.DrawEllipse(circlePen, xpos + 65, ypos -130 + 200, 20, 35);
g.FillEllipse(Brushes.Black, xpos + 65, ypos-130 + 200, 20, 35);
g.DrawEllipse(circlePen, xpos + 160, ypos-130 + 200, 20, 35);
g.FillEllipse(Brushes.Black, xpos + 160, ypos-130 + 200, 20, 35);
g.DrawArc(circlePen, xpos + 60, ypos-130 + 215, 130, 120, 35, 115);
}
This code could be highly improved, but this may help you think how it should be done. Hope it helps.
Program works fine for the first time print. but when i'm going to print the second receipt error occurs.
Screen shot of first error 1
I tried (as i foundd on internet)- unchecked enable visual studio hosting process and checked enable unmanaged code dubugging after that now it gives an error like this..
screen shot of second error 2
Code :
private void btnprint_Click(object sender, EventArgs e)
{
try
{
if (txtcash.Text == "" || txttpri.Text == "" || txtftot.Text == "")
{
MessageBox.Show("Please Input Cash Price ! ", "Sales", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
txtbal.Text = (Convert.ToInt32(txtcash.Text) - Convert.ToInt32(txtftot.Text)).ToString();
printDialog1.ShowDialog();
printDocument1.Print();
radreta.Enabled = true;
radwhol.Enabled = true;
radreta.Checked = false;
radwhol.Checked = false;
}
}
catch (Exception)
{
MessageBox.Show("Printing Issue !", "Message");
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
try
{
salesconnection.Open();
OleDbCommand cmdprint = new OleDbCommand();
cmdprint.Connection = salesconnection;
cmdprint.CommandText = "Select * from saletrans";
OleDbDataReader printreder = cmdprint.ExecuteReader();
int x = 50;
int y = 65;
int width = 800;
int height = 0;
StringFormat left = new StringFormat();
left.Alignment = StringAlignment.Near;
StringFormat center = new StringFormat();
center.Alignment = StringAlignment.Near;
e.Graphics.DrawString(" Toyota Motor Corporation Area Store Branch ", new Font("Georgia", 15, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = 85;
e.Graphics.DrawString(" No:56,Kurunegala Road,Katugasthota", new Font("Georgia", 12, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = 100;
e.Graphics.DrawString(" toyotamotorcorporation#gmail.com / TpNo: 081-2225468/081-2224445", new Font("Georgia", 11, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = 138;
e.Graphics.DrawString(" " + "Product ID" + " " + "Product Name" + " " + "Unit/P" + " " + "Quantity" + " " + "Sub Total(Rs:)", new Font("Georgia", 13, FontStyle.Bold), Brushes.CadetBlue, new Rectangle(x, y, width, height), left);
y = 146;
e.Graphics.DrawString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", new Font("Georgia", 12, FontStyle.Bold), Brushes.CadetBlue, new Rectangle(x, y, width, height), left);
x = 110;
y = 155;
while (printreder.Read())
{
y = y + 20;
e.Graphics.DrawString("" + printreder["ProductID"] + " " + printreder["ProductName"].ToString(), new Font("Georgia", 13, FontStyle.Bold), Brushes.Black, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString(" " + printreder["Unitprice"] + " x " + printreder["Quantity"].ToString() + " = " + printreder["Total"].ToString(), new Font("Georgia", 13, FontStyle.Bold), Brushes.Black, new Rectangle(x, y, width, height), left);
}
y = y + 25;
x = 60;
e.Graphics.DrawString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", new Font("Georgia", 12, FontStyle.Bold), Brushes.CadetBlue, new Rectangle(x, y, width, height), left);
y = y + 15;
x = 490;
e.Graphics.DrawString("Grand Total " + txtftot.Text, new Font("Georgia", 14, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString("Cash " + txtcash.Text, new Font("Georgia", 14, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString("-------------------------------------", new Font("Georgia", 14, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString("Balance " + txtbal.Text, new Font("Georgia", 14, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
x = 60;
y = y + 30;
e.Graphics.DrawString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", new Font("Georgia", 12, FontStyle.Bold), Brushes.CadetBlue, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString("Customer Name & ID : " + txtcname.Text +" / "+ cmbcid.Text, new Font("Georgia", 12, FontStyle.Bold), Brushes.DarkBlue, new Rectangle(x, y, width, height), center);
y = y + 30;
e.Graphics.DrawString(frmlog.user.ToString() + " " + DateTime.Now, new Font("Georgia", 12, FontStyle.Bold), Brushes.DarkBlue, new Rectangle(x, y, width, height), center);
y = y + 20;
e.Graphics.DrawString("** Exchange Possible Within 7 Days **", new Font("Georgia", 12, FontStyle.Bold), Brushes.DarkBlue, new Rectangle(x, y, width, height), center);
y = y + 20;
e.Graphics.DrawString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", new Font("Georgia", 12, FontStyle.Bold), Brushes.CadetBlue, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString("Software by NKP Developer", new Font("Georgia", 12, FontStyle.Bold), Brushes.DarkBlue, new Rectangle(x, y, width, height), center);
pictureBox1.Image = Image.FromFile("E:\\NIBM\\C#\\GROUP PROJECT\\graphics\\Billlogo.png");
Point loc = new Point(300, 15);
e.Graphics.DrawImage(pictureBox1.Image, loc);
printreder.Close();
salesconnection.Close();
salesconnection.Open();
OleDbCommand deleteall = new OleDbCommand();
deleteall.Connection = salesconnection;
string del = "delete from saletrans";
deleteall.CommandText = del;
deleteall.ExecuteNonQuery();
salesconnection.Close();
dataGridView2.DataSource = null;
dataGridView2.Refresh();
cmbcid.Enabled = true;
cmbcid.Text = "";
txtcname.Text = "";
txtbal.Text = "";
txtcash.Text = "";
txttpri.Text = "0";
txtftot.Text = "0";
btnnewbill.Enabled = false;
btnpurdelete.Enabled = false;
btncalculate.Enabled = false;
btnprint.Enabled = false;
sum = 0;
}
catch (Exception)
{
MessageBox.Show("Printing Issue !", "Message");
}
}
Ive got a panel and im drawing a heart on that panel..
But i dont want to draw the heart i want to draw everything except the heart so the heart is transparent.
Can i invert the Region selected out of the Path?
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddArc(0, 0, (this.Width / 2), (this.Height / 2), 135, 195);
path.AddArc((this.Width / 2), 0, (this.Width / 2), (this.Height / 2), 210, 195);
path.AddLine((this.Width / 2), this.Height, (this.Width / 2), this.Height);
this.Region = new Region(path);
this.BackColor = Color.Black;
What it looks like(white = transparent):
What i want it to look like(white = transparent):
I think you can just add 2 graphics paths together.
You could try this code out:
private void panel1_Paint(object sender, PaintEventArgs e)
{
GraphicsPath path = new GraphicsPath();
path.AddArc(0, 0, (this.Width / 2), (this.Height / 2), 135, 195);
path.AddArc((this.Width / 2), 0, (this.Width / 2), (this.Height / 2), 210, 195);
path.AddLine((this.Width / 2), this.Height, (this.Width / 2), this.Height);
GraphicsPath path2 = new GraphicsPath();
path2.AddRectangle(new Rectangle(new Point(0, 0), panel1.Size));
path2.AddPath(path, false);
e.Graphics.FillPath(Brushes.Black, path2);
}
Result is:
You can try excluding a region from from the Graphic object of your panel's Paint event:
GraphicsPath path = new GraphicsPath();
path.AddArc(0, 0, (this.Width / 2), (this.Height / 2), 135, 195);
path.AddArc((this.Width / 2), 0, (this.Width / 2), (this.Height / 2), 210, 195);
path.AddLine((this.Width / 2), this.Height, (this.Width / 2), this.Height);
using (Region r = new Region(path)) {
e.Graphics.ExcludeClip(r);
}
// continue drawing...
e.Graphics.Clear(Color.Yellow);
or if trying to modify the control's region, then just use the Region's Exclude property:
GraphicsPath path = new GraphicsPath();
path.AddArc(0, 0, (this.Width / 2), (this.Height / 2), 135, 195);
path.AddArc((this.Width / 2), 0, (this.Width / 2), (this.Height / 2), 210, 195);
path.AddLine((this.Width / 2), this.Height, (this.Width / 2), this.Height);
Region r = new Region(new Rectangle(Point.Empty, this.ClientSize));
r.Exclude(path);
this.Region = r;
I don't know of a way to invert the selection, but you can always draw a heart in the background color, then change the background color to black.
this.BackColor = Form.BackColor;
Form.BackColor = Color.Black;
Original solution here. I've modified that for your needs
this.Region = InvertRegion(new Region(path), this.Width, this.Height);
and
private Region InvertRegion(Region region, int width, int height)
{
Bitmap mask = new Bitmap(width, height);
Graphics.FromImage(mask).FillRegion(Brushes.Black, region);
int matchColor = Color.Black.ToArgb();
Region inverted = new System.Drawing.Region();
inverted.MakeEmpty();
Rectangle rc = new Rectangle(0, 0, 0, 0);
bool inimage = false;
for (int y = 0; y < mask.Height; y++)
{
for (int x = 0; x < mask.Width; x++)
{
if (!inimage)
{
if (mask.GetPixel(x, y).ToArgb() != matchColor)
{
inimage = true;
rc.X = x;
rc.Y = y;
rc.Height = 1;
}
}
else
{
if (mask.GetPixel(x, y).ToArgb() == matchColor)
{
inimage = false;
rc.Width = x - rc.X;
inverted.Union(rc);
}
}
}
if (inimage)
{
inimage = false;
rc.Width = mask.Width - rc.X;
inverted.Union(rc);
}
}
return inverted;
}