Sascha B

Sascha B

  • NA
  • 237
  • 0

[Solved with Solution]BackgroundWorker/Bitmap drawing slower on Dual Core? Or Widnows 7? pls help me...

Apr 5 2011 7:46 AM
Hello,

I finished my programm and wanted start the big test part.
Today I started it on a Windows 7 DualCore machine and my BackgroundWorker is damm slow now!
I coded it with a crappy old xp pc and everything works fine.
My computer just takes 3 to 4 seconds to render the image
The Widnows 7 PC took about 4-5 Minutes!!!
WTF?
Heres my Code:
My BackgroundWorker creates a virtual Bitmap and if it is finished the Bitmap becomes the PictureBox's Background.

       private void paintInBackground_DoWork(object sender, DoWorkEventArgs e)
       {
           int w = 390 - 1, h = 390 - 1;


           bitmap = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format64bppPArgb);


           bmpgrafik = Graphics.FromImage(bitmap);


           bmpgrafik.CompositingMode = CompositingMode.SourceCopy;
           bmpgrafik.CompositingQuality = CompositingQuality.GammaCorrected;
           painterflag = false; // Enthält ein Messwert eine Note unter 1 ist etwas schief gelaufen
           Color notenfarbe = new Color();
           try
           {
               if (measuredatas != null)
               {
                   for (int k = 0; k < measuredatas[aktTab].Length && invisible_or_blasser == "blasser"; k++)// Bei der Angabe "blasser" werden die punkte mit einen niedrigeren A Wert
                   // angegeben. Dadurch ist dieser Punkt eben blasser
                   // Ist "unsichtbar" angegeben dann geht er erst gar nicht in diese schleife und lässt den Punkt aus
                   {
                       notenfarbe = choosemarkcolor(measuredatas[aktTab][k].Mark);


                       notenfarbe = Color.FromArgb(65, notenfarbe);


                       if (dottype == 0)
                           bmpgrafik.FillRectangle(new SolidBrush(notenfarbe), (int)measuredatas[aktTab][k].CoordX + w / 2 - dotstrength, (int)measuredatas[aktTab][k].CoordY * -1 + h / 2 - dotstrength, dotstrength * 2 + 1, dotstrength * 3 + 1);
                       else if (dottype == 1)
                           bmpgrafik.FillEllipse(new SolidBrush(notenfarbe), (int)measuredatas[aktTab][k].CoordX + w / 2 - dotstrength, (int)measuredatas[aktTab][k].CoordY * -1 + h / 2 - dotstrength, (dotstrength * 2 + 1), (dotstrength * 2 + 1));
                   }
                   for (int i = 0; i < measuredatas[aktTab].Length; i++)
                   {
                       bool imageflag = false;
                       if ((measuredatas[aktTab][i].Theta <= 10 && isThetaSelected[paintertabnumber, 0] == true) ||
                           (measuredatas[aktTab][i].Theta > 10 && measuredatas[aktTab][i].Theta <= 20 && isThetaSelected[paintertabnumber, 1] == true) ||
                           (measuredatas[aktTab][i].Theta > 20 && measuredatas[aktTab][i].Theta <= 30 && isThetaSelected[paintertabnumber, 2] == true) ||
                           (measuredatas[aktTab][i].Theta > 30 && measuredatas[aktTab][i].Theta <= 40 && isThetaSelected[paintertabnumber, 3] == true) ||
                           (measuredatas[aktTab][i].Theta > 40 && measuredatas[aktTab][i].Theta <= 50 && isThetaSelected[paintertabnumber, 4] == true) ||
                           (measuredatas[aktTab][i].Theta > 50 && measuredatas[aktTab][i].Theta <= 60 && isThetaSelected[paintertabnumber, 5] == true) ||
                           (measuredatas[aktTab][i].Theta > 60 && measuredatas[aktTab][i].Theta <= 70 && isThetaSelected[paintertabnumber, 6] == true) ||
                           (measuredatas[aktTab][i].Theta > 70 && measuredatas[aktTab][i].Theta <= 80 && isThetaSelected[paintertabnumber, 7] == true)
                           )
                       {
                           if (// Oben
                               (isPhiSelected[aktTab, 0] == true && measuredatas[aktTab][i].Phi >= 90 - categories[aktcat].TopPhi / 2 && measuredatas[aktTab][i].Phi <= 90 + categories[aktcat].TopPhi / 2) ||
                               (isPhiSelected[aktTab, 1] == true && ((measuredatas[aktTab][i].Phi <= 180 - categories[aktcat].MiddlePhi / 2 && measuredatas[aktTab][i].Phi > 90 + categories[aktcat].TopPhi / 2) ||
                               (measuredatas[aktTab][i].Phi > categories[aktcat].MiddlePhi / 2 && measuredatas[aktTab][i].Phi < 90 - categories[aktcat].TopPhi / 2))) ||
                               // Mitte
                               (isPhiSelected[aktTab, 2] == true && ((measuredatas[aktTab][i].Phi >= 360 - categories[aktcat].MiddlePhi / 2 || measuredatas[aktTab][i].Phi <= categories[aktcat].MiddlePhi / 2) ||
                               (measuredatas[aktTab][i].Phi <= categories[aktcat].MiddlePhi / 2) || (measuredatas[aktTab][i].Phi >= 180 - categories[aktcat].MiddlePhi / 2 && measuredatas[aktTab][i].Phi <= 180 + categories[aktcat].MiddlePhi / 2))) ||
                               (isPhiSelected[aktTab, 2] == true && measuredatas[aktTab][i].Phi == 360) ||
                               (isPhiSelected[aktTab, 2] == true && measuredatas[aktTab][i].Phi == 0) ||
                               // Unten
                               (isPhiSelected[aktTab, 3] == true && ((measuredatas[aktTab][i].Phi <= 360 - categories[aktcat].MiddlePhi / 2 && measuredatas[aktTab][i].Phi >= 270 + categories[aktcat].BottomPhi / 2) ||
                               (measuredatas[aktTab][i].Phi < 270 - categories[aktcat].BottomPhi / 2 && measuredatas[aktTab][i].Phi > 180 + categories[aktcat].MiddlePhi / 2))) ||
                               (isPhiSelected[aktTab, 4] == true && measuredatas[aktTab][i].Phi >= 270 - categories[aktcat].BottomPhi / 2 && measuredatas[aktTab][i].Phi < 270 + categories[aktcat].BottomPhi / 2))
                           {
                               notenfarbe = choosemarkcolor(measuredatas[aktTab][i].Mark);


                               if (dottype == 0 && imageflag == false)
                                   bmpgrafik.FillRectangle(new SolidBrush(notenfarbe), (int)measuredatas[aktTab][i].CoordX + w / 2 - dotstrength, (int)measuredatas[aktTab][i].CoordY * -1 + h / 2 - dotstrength, dotstrength * 2 + 1, dotstrength * 2 + 1);
                               else if (dottype == 1)
                                   bmpgrafik.FillEllipse(new SolidBrush(notenfarbe), (int)measuredatas[aktTab][i].CoordX + w / 2 - dotstrength, (int)measuredatas[aktTab][i].CoordY * -1 + h / 2 - dotstrength, (dotstrength * 2 + 1), (dotstrength * 2 + 1));
                           }
                       }
                   }
               }


               if (showgrid == true)
               {
                   for (int z = 0; z < 8; z++)
                   {
                       bmpgrafik.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(100, Color.Black)), 1), (imagepreview[aktTab].Width / 16) * z, (imagepreview[aktTab].Height / 16) * z, imagepreview[aktTab].Width - ((imagepreview[aktTab].Width / 8) * z) - 1, imagepreview[aktTab].Height - ((imagepreview[aktTab].Height / 8) * z) - 1);
                   }


                   //Vertikal Oben
                   bmpgrafik.DrawLine(new Pen(Color.FromArgb(100, Color.Black), 1), w / 2, h / 2, MeasureData.polarToX(80, 90 - categories[aktcat].TopPhi / 2) + w / 2, MeasureData.polarToY(80, 90 - categories[aktcat].TopPhi / 2) * -1 + h / 2);
                   bmpgrafik.DrawLine(new Pen(Color.FromArgb(100, Color.Black), 1), w / 2, h / 2, MeasureData.polarToX(80, 90 + categories[aktcat].TopPhi / 2) + w / 2, MeasureData.polarToY(80, 90 + categories[aktcat].TopPhi / 2) * -1 + h / 2);


                   //Horizontal
                   bmpgrafik.DrawLine(new Pen(Color.FromArgb(100, Color.Black), 1), w / 2, h / 2, MeasureData.polarToX(80, 360 - categories[aktcat].MiddlePhi / 2) + w / 2, MeasureData.polarToY(80, 360 - categories[aktcat].MiddlePhi / 2) * -1 + h / 2);
                   bmpgrafik.DrawLine(new Pen(Color.FromArgb(100, Color.Black), 1), w / 2, h / 2, MeasureData.polarToX(80, 0 + categories[aktcat].MiddlePhi / 2) + w / 2, MeasureData.polarToY(80, 0 + categories[aktcat].MiddlePhi / 2) * -1 + h / 2);
                   bmpgrafik.DrawLine(new Pen(Color.FromArgb(100, Color.Black), 1), w / 2, h / 2, MeasureData.polarToX(80, 180 - categories[aktcat].MiddlePhi / 2) + w / 2, MeasureData.polarToY(80, 180 - categories[aktcat].MiddlePhi / 2) * -1 + h / 2);
                   bmpgrafik.DrawLine(new Pen(Color.FromArgb(100, Color.Black), 1), w / 2, h / 2, MeasureData.polarToX(80, 180 + categories[aktcat].MiddlePhi / 2) + w / 2, MeasureData.polarToY(80, 180 + categories[aktcat].MiddlePhi / 2) * -1 + h / 2);




                   //Vertikal Unten
                   bmpgrafik.DrawLine(new Pen(Color.FromArgb(100, Color.Black), 1), w / 2, h / 2, MeasureData.polarToX(80, 270 - categories[aktcat].BottomPhi / 2) + w / 2, MeasureData.polarToY(80, 270 - categories[aktcat].BottomPhi / 2) * -1 + h / 2);
                   bmpgrafik.DrawLine(new Pen(Color.FromArgb(100, Color.Black), 1), w / 2, h / 2, MeasureData.polarToX(80, 270 + categories[aktcat].BottomPhi / 2) + w / 2, MeasureData.polarToY(80, 270 + categories[aktcat].BottomPhi / 2) * -1 + h / 2);


               }
           }
           catch { }
       }


       private void paintInBackground_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
       {
           // Alles erstmal wieder benutzbar machen
           tabmeasure.Enabled = true;


           try
           {
               imagepreview[paintertabnumber].Image = bitmap;
           }
           catch { }
           bmpgrafik.Dispose();


           try
           {
               fillsummary(newMeasure[paintertabnumber].Text);
               if (markFlag)
               {
                   string fehlermeldung = "";
                   fehlermeldung += "Die Notenmatrix wurde nicht korrekt ausgefüllt." + Environment.NewLine;
                   if (painterflag)
                       fehlermeldung += Environment.NewLine + "Dadurch entstanden Berechnungsfehler der Noten." + Environment.NewLine +
                           "Bitte korrigieren Sie die Notenmatrix um Berechnungsfehler zu vermeiden.";
                   else fehlermeldung += "Dadurch könnten Berechnungsfehler entstanden zu sein.";
                   MessageBox.Show(fehlermeldung, "Warnung", MessageBoxButtons.OK, MessageBoxIcon.Warning);
               }
           }
           catch
           { }
           if (firststart == true && measurePath.Count > 1)
           {
               paintpicture(0);
               firststart = false;
           }
       }


If having trouble understanding something pls feel free to ask me.
Hope you can help me...

Answers (25)