In the paint event i draw a rectangle and then adding the pixels coordinates inside the rectangle area to a List:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (cloudPoints != null)
{
if (DrawIt)
{
e.Graphics.DrawRectangle(pen, rect);
pointsAffected = cloudPoints.Where(pt => rect.Contains(pt));
CloudEnteringAlert.pointtocolorinrectangle = pointsAffected.ToList();
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height, PixelFormat.Format32bppArgb);
CloudEnteringAlert.Paint(e.Graphics, 1, 200, bmp);
}
}
}
I'm drawing a rectangle thats the rect(Rectangle) variable and assigning to pointsAffected List only the pixels coordinates that are inside the rect area ! cloudPoints contain all the pixels coordinates all over the image !!! but pointsAffected contain only the coordinates of pixels inside the rectangle area.
Then the mouse up event:
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
StreamWriter w = new StreamWriter(@"c:\diff\diff.txt");
pixelscoordinatesinrectangle = new List<Point>();
pixelscoordinatesinrectangle = pointsAffected.ToList();
DrawIt = false;
for (int i = 0; i < trackBar1FileInfo.Length; i++)
{
DrawIt = true;
trackBar1.Value = i;
LoadPictureAt(trackBar1.Value, sender);
pictureBox1.Load(trackBar1FileInfo[i].FullName);
ConvertedBmp = ConvertTo24(trackBar1FileInfo[trackBar1.Value].FullName);
ConvertedBmp.Save(ConvertedBmpDir + "\\ConvertedBmp.bmp");
mymem = ToStream(ConvertedBmp, ImageFormat.Bmp);
backTexture = TextureLoader.FromStream(D3Ddev, mymem);
scannedCloudsTexture = new Texture(D3Ddev, 512, 512, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);
Button1Code();
pictureBox1.Refresh();
newpixelscoordinates = new List<Point>();
newpixelscoordinates = pointsAffected.ToList();
if (pixelscoordinatesinrectangle != null && newpixelscoordinates != null)
{
IEnumerable<Point> differenceQuery =
pixelscoordinatesinrectangle.Except(newpixelscoordinates);
// Execute the query.
foreach (Point s in differenceQuery)
w.WriteLine("The following points are not the same" + s);
}
else
{
am1 = pixelscoordinatesinrectangle.Count;
am2 = newpixelscoordinates.Count;
}
//MessageBox.Show(pixelscoordinatesinrectangle.Count.ToString());
}
w.Close();
}
Once i draw the rectangle when finish drawing it i'm creating a new List instance and store the pixels in the rectangle area in the pixelscoordinatesinrectangle List.
Then i loop over trackBar1FileInfo that contains for example 5000 images files names from the hard disk.
This is the problem part:
pictureBox1.Refresh();
newpixelscoordinates = new List<Point>();
newpixelscoordinates = pointsAffected.ToList();
if (pixelscoordinatesinrectangle != null && newpixelscoordinates != null)
{
IEnumerable<Point> differenceQuery =
pixelscoordinatesinrectangle.Except(newpixelscoordinates);
// Execute the query.
foreach (Point s in differenceQuery)
w.WriteLine("The following points are not the same" + s);
}
else
{
am1 = pixelscoordinatesinrectangle.Count;
am2 = newpixelscoordinates.Count;
}
I'm doing refresh for the pictureBox1 so it will go one each image to the paint event and will create a new List pointsAffected will have each time a different pixels coordinates.
So newpixelscoordinates should be with new pixels coordinates each loop itertion.
Then i'm comparing both Lists newpixelscoordinates and pixelscoordinatesinrectangle for a different items.
And write those who are not the same to a text file.
So i'm getting a very large text file with many pixels coordinates that are not the same in both Lists.
The problems are:
Does the comparison i'm doing is right ? I want to compare one list index against other listi ndex.
For example in the List newpixelscoordinates in index 0 if i have x = 233 y = 23 and in the List pixelscoordinatesinrectangle in index 0 there is x = 1 y = 100 then write this as not the same to the text file.
What i want to do is to check the whole List items against the other List items and if some of the items are not the same write this items to the text file.
Next itertion new image new Lists with new pixels coordinates do the same comparison.
The List pixelscoordinatesinrectangle is not changing it's storing the first pixels coordinates when i drawed the rectangle first time. Only the List newpixelscoordinates change each time, Should change each itertion.
The exception i'm getting is on the line:
newpixelscoordinates = new List();
I added this line since i thought maybe i didn't clear it each time but it didn't help.
Before adding this line the exception was on the line:
newpixelscoordinates = pointsAffected.ToList();
The exception is: OutOfMemoryException: Out of memory
System.OutOfMemoryException was unhandled
HResult=-2147024882
Message=Out of memory.
Source=System.Drawing
StackTrace:
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
InnerException:
MouseUp
event for example, I'd look into disposing a bunch of stuff at the same point you callw.Close();