Пример #1
0
 /// <summary>
 /// determines if ratio of bitmap is close enough to dimensions given
 /// </summary>
 /// <param name="b">bitmap to test</param>
 /// <param name="x">width dimension</param>
 /// <param name="y">height dimension</param>
 /// <returns></returns>
 private bool sameratio(picture b, double x, double y, double value)
 {
     double screenRatio = x / y;
     double imgRatio = (double)b.getwidth() / (double)b.getheight();
     if (screenRatio < imgRatio)
         return ((screenRatio / imgRatio) + (value / 100) >= 1);
     else
         return ((imgRatio / screenRatio) + (value / 100) >= 1);
     //return (getratio(ref b) >= x/y - (value / 100 * x/y) && getratio(ref b) <= x/y + (value / 100 * x/y));
 }
Пример #2
0
        /// <summary>
        /// gets random picture from directory based on given max width, if picture is close enough to max width that the scaling will be correct, picture is returned, even if the width is greater than maxwidth
        /// </summary>
        /// <param name="maxwidth">maximum picture width that is returned; any size = 0</param>
        private string getrandompic(int maxwidth, int screen)
        {
            bool ok = true;
            //ArrayList pics = dir.getlist();
            //picture temp;
            picture b;
            int fail = 0;
            int failpoint;
            if(useParse)
                failpoint = pictures.Count-1;
            else
                failpoint = dirpics.Count-1;
            //DateTime start = DateTime.Now;
            int c = 0;
            do
            {
                /* all of this is for color matching, to implement it, just uncomment and comment out the code below it
                c = new Random().Next(pics.Count);
                //temp = (FileInfo)pics[c];
                temp = (picture)pics[c];
                pics.RemoveAt(c);
               // MessageBox.Show(temp.FullName);
                label5.Text = pics.Count.ToString() + "  " + temp.getfilename();
                if (colormatching.Checked && temp.getcolorindex() == "0|0|0")
                    if (directory.getcolorindex(temp.getfilename()) != "0|0|0")
                    {
                        dir.removepic(temp);
                        dir.update(new picture(temp.getfilename()));
                    }
                Application.DoEvents();
                if (temp.getwidth() > maxwidth && !sameratio(temp.getwidth(), temp.getheight(), maxwidth, allheight))
                    ok = false;
                else if (pictures.Contains(temp.getfilename()))
                        ok = false;
                else if(colormatching.Checked && !directory.colorsmatch(lastpic.getcolorindex(), temp.getcolorindex(), (int)colorratio.Value))
                    ok = false;
                else
                    ok = true;
                //TimeSpan duration = start - DateTime.Now;
                if (maxwidth == 0 || fail == failpoint)// || duration.Seconds > 5)
                    ok = true;
                fail++;*/

                if (useParse)
                {
                    c = new Random().Next(pictures.Count);
                    b = (picture)pictures[c];
                }
                else
                {
                    c = new Random().Next(dirpics.Count);
                    b = new picture((string)dirpics[c]);
                }
                System.Threading.Thread.Sleep(10);
                int j = screen;
                int workingwidth = desktops[0][screen].Bounds.Width;
                int workingheight = desktops[0][screen].Bounds.Height;
                if (b.getwidth() > desktops[0][screen].Bounds.Width && !sameratio(b, screen, (double)usebox.Value) && desktops[0].Length > 1)
                {
                    int i = screen;
                    while (i < desktops[0].Length - 1 && b.getwidth() > workingwidth && !sameratio(b, workingwidth, workingheight, (double)usebox.Value))
                    {
                        i++;
                        j++;
                        workingwidth = widthofscreens(screen, i);
                    }
                    if (!sameratio(b, workingwidth, workingheight, (double)usebox.Value))
                        if (b.getwidth() > workingwidth)
                        { }
                        else
                        {
                            workingwidth -= desktops[0][i].Bounds.Width;
                            j--;
                        }
                    else
                    { }
                    j = j - screen + 1;
                }
                else
                    j = 1;
                if(j == 1)
                    if (b.getwidth() > maxwidth && !sameratio(b, maxwidth, workingheight, (double)usebox.Value) || !sameratio(b, desktops[0][screen].Bounds.Width, desktops[0][screen].Bounds.Height, (double)usebox.Value))
                        ok = false;
                    else
                        ok = true;
                else
                    if (b.getwidth() > maxwidth && !sameratio(b, maxwidth, allheight, (double)usebox.Value))
                        ok = false;
                    else
                        ok = true;
                if (maxwidth == 0 && sameratio(b, maxwidth, allheight, (double)usebox.Value) || fail == failpoint)
                    ok = true;
                fail++;
                Application.DoEvents();
            } while (!ok);
            //addToLog(b..Name);
            addToLog("Screen " + screen + " Chose after " + fail.ToString() + " tries");

            //lastpic = temp;
            //return temp.getfilename();
            return b.getfilename();
        }
Пример #3
0
 /// <summary>
 /// appends a new picture to "pics.txt" as well as memory
 /// </summary>
 /// <param name="pic">picture to add</param>
 public void update(picture pic)
 {
     add(pic);
 }
Пример #4
0
 /// <summary>
 /// determines whether or not the ratio of the picture is close enough to the ratio of the screen
 /// </summary>
 /// <param name="b">bitmap to test</param>
 /// <param name="screen">index of the screen in the desktop array</param>
 /// <returns></returns>
 private bool sameratio(picture b, int screen, double value)
 {
     double screenRatio = getratio(screen);
     double imgRatio = (double)b.getwidth()/(double)b.getheight();
     if (screenRatio < imgRatio)
         return ((screenRatio / imgRatio) + (value / 100) >= 1);
     else
         return ((imgRatio / screenRatio) + (value / 100) >= 1);
     //return (getratio(ref b) >= getratio(screen) - (value / 100 * getratio(screen)) && getratio(ref b) <= getratio(screen) + (value / 100 * getratio(screen)));
 }
Пример #5
0
 public void removepic(picture toremove)
 {
     pics.RemoveAt(pics.IndexOf(toremove));
 }
Пример #6
0
 public void add(picture pic)
 {
     pics.Add(pic);
 }
Пример #7
0
 public void add(picture pic)
 {
     pics.Add(pic);
 }
Пример #8
0
 public void removepic(picture toremove)
 {
     pics.RemoveAt(pics.IndexOf(toremove));
 }
Пример #9
0
 /// <summary>
 /// appends a new picture to "pics.txt" as well as memory
 /// </summary>
 /// <param name="pic">picture to add</param>
 public void update(picture pic)
 {
     add(pic);
 }