private void button1_Click(object sender, EventArgs e) { string srcfile = Path.Combine(Directory.GetCurrentDirectory(), "1.jpg"); string srcfile2 = Path.Combine(Directory.GetCurrentDirectory(), "2.jpg"); string desfile = Path.Combine(Directory.GetCurrentDirectory(), "op"); Image[] imgarr = CropJoin.splitimg(srcfile, 10, 10); Image[] imgarr2 = CropJoin.splitimg(srcfile2, 10, 10); //Image[] imgarr_original = (Image[])imgarr.Clone(); if (checkBox_ri.Checked) { CropJoin.shuffle(imgarr2); } CropJoin.shuffle(imgarr); Image img = CropJoin.combineimg(imgarr, 10, 10); CropJoin.overlayimg(img, imgarr2, 10, 10); CropJoin.saveimg(img, desfile); pictureBox1.Image = img; //CropJoin.saveimg(imgarr,desfile); string rndn = ""; Random rnd = new Random(); int n = 10; while (n > 0) { int k = (rnd.Next(1, 100) % 100); n--; rndn += k.ToString() + " "; } textBox1.Text = rndn; }
private void methodotherthread() { int w = curimg.Height; int h = curimg.Width; Image imgrnd = new Bitmap(w, h); var graphics2 = Graphics.FromImage(imgrnd); int w1 = w / splitcount; int h1 = h / splitcount; int[] rndidx = CropJoin.getrandomnumber(splitcount * splitcount - 1, splitcount * splitcount); int loopcnt = 0; foreach (int ind in rndidx) { int i = ind / splitcount; int j = ind % splitcount; graphics2.DrawImage(imgarr[ind], new Rectangle(i * h1, j * w1, h1, w1), new Rectangle(0, 0, h1, w1), GraphicsUnit.Pixel); setpic(imgrnd); if (loopcnt > splitcount * splitcount / 10) { Thread.Sleep(sp); } loopcnt++; } graphics2.Dispose(); }
private void methodotherthread() { //all processing here and call imagereload from here. .... string nmbrfile = Path.Combine(Directory.GetCurrentDirectory(), "numbers.jpg"); Image[] numarr = CropJoin.splitimg(nmbrfile, 10, 10); gridn = int.Parse(textBox1.Text); int[] index = CropJoin.getrandomnumber(maximgcount / 2 - 1, gridn * gridn / 2); int delay = 1; try { delay = int.Parse(textBox3.Text); } catch (Exception ex) { } //Debug.Print("index: " + string.Join(",", index)); selectedimg = new Image[gridn * gridn]; imginput = CropJoin.creategrid(pxsz, pxsz, gridn, gridn); for (int ii = 0; ii < selectedimg.Count(); ii++) //foreach (Image oneimg in selectedimg) { //imgadd = Image.FromFile(one); CropJoin.addimg(imginput, numarr[ii], ii, pxsz, pxsz, gridn, gridn); } pictureBox1.Image = imginput; Thread.Sleep(2000); //int[] x = new int[10]; for (int ii = 0; ii < index.Count(); ii++) { selectedimg[2 * ii] = allimgs[2 * index[ii]]; selectedimg[2 * ii + 1] = allimgs[2 * index[ii] + 1]; //Debug.Print(String.Format("selected img : {0},{1} from: {2},{3}", 2 * ii, (2 * ii + 1), index[ii], index[ii] + 1)); } CropJoin.shuffle(selectedimg); int[] rndidx; if (checkBox1.Checked == true) { rndidx = CropJoin.getrandomnumber(selectedimg.Count() - 1, selectedimg.Count()); } else { rndidx = Enumerable.Range(0, selectedimg.Count()).ToArray(); } //Debug.Print(string.Join(",", x)); //for (int ii = 0; ii < selectedimg.Count(); ii++) foreach (int ii in rndidx) //foreach (Image oneimg in selectedimg) { Image imageinclone = (Image)imginput.Clone(); //imgadd = Image.FromFile(one); CropJoin.addimg(imageinclone, selectedimg[ii], ii, pxsz, pxsz, gridn, gridn); pictureBox1.Image = imageinclone; Thread.Sleep(1000 * delay); } pictureBox1.Image = imginput; }
private void button1_Click(object sender, EventArgs e) { string srcfile = Path.Combine(Directory.GetCurrentDirectory(), "allcards.jpg"); //string srcfile2 = Path.Combine(Directory.GetCurrentDirectory(), "2.jpg"); string desfile = Path.Combine(Directory.GetCurrentDirectory(), "op"); Image[] imgarr = CropJoin.splitimg(srcfile, 4, 13); //Image[] imgarr2 = CropJoin.splitimg(srcfile2,10,10); //Image[] imgarr_original = (Image[])imgarr.Clone(); //if (checkBox_ri.Checked) //{ // CropJoin.shuffle(imgarr2); //} CropJoin.shuffle(imgarr); Image img = CropJoin.combineimg(imgarr, 4, 13); //CropJoin.overlayimg(img,imgarr2,10,10); CropJoin.saveimg(img, desfile); pictureBox1.Image = img; //CropJoin.saveimg(imgarr,desfile); /* * imgarray = new Image[52]; * for (int i = 0; i < 13; i++) * { * for (int j = 0; j < 4; j++) * { * var index = i * 4 + j; * Debug.Print(w1.ToString()+": "+h1.ToString()); * imgarray[index] = new Bitmap(w1, h1); * var graphics = Graphics.FromImage(imgarray[index]); * graphics.DrawImage(img, new Rectangle(0, 0, w1, h1), new Rectangle(i * w1, j * h1, w1, h1), GraphicsUnit.Pixel); * graphics.Dispose(); * } * } * //pictureBox1.Image = imgrnd; * * Shuffle(listofindex); * var imgrnd = new Bitmap(w, h); * int rndidx = 0; * var graphics2 = Graphics.FromImage(imgrnd); * for (int i = 0; i < 13; i++) * { * for (int j = 0; j < 4; j++) * { * var index = listofindex[rndidx]; * rndidx++; * Debug.Print("Index: " + index); * graphics2.DrawImage(imgarray[index], new Rectangle(i * w1, j * h1, w1, h1), new Rectangle(0, 0, w1, h1), GraphicsUnit.Pixel); * } * } * graphics2.Dispose(); * //pictureBox1.Image = imgarray[5]; * pictureBox1.Image = imgrnd; * //pictureBox1.Image = imgarray[5]; */ }
private void button2_Click(object sender, EventArgs e) { Image imageinclone = (Image)imginput.Clone(); for (int ii = 0; ii < selectedimg.Count(); ii++) //foreach (Image oneimg in selectedimg) { //imgadd = Image.FromFile(one); CropJoin.addimg(imageinclone, selectedimg[ii], ii, pxsz, pxsz, gridn, gridn); pictureBox1.Image = imageinclone; } }
private void reload() { if (workerThread != null) { workerThread.Abort(); } Thread.Sleep(100); try { sp = int.Parse(textBox2.Text); } catch (Exception ex) { } int sz = 100; try { sz = int.Parse(textBox1.Text); } catch (Exception ex) { } if (splitcount < 1) { splitcount = 1; } textBox1.Text = splitcount.ToString(); button1.Enabled = true; button3.Enabled = true; if (curimgidx == 0) { button1.Enabled = false; } if (curimgidx == maximgcount - 1) { button3.Enabled = false; } curimg = Image.FromFile(allpictures[curimgidx]); imgarr = CropJoin.splitimg(allpictures[curimgidx], splitcount, splitcount); this.workerThread = new Thread(new ThreadStart(this.methodotherthread)); this.workerThread.Start(); //Image imgpuzzle = CropJoin.removeimgpartially(imgarr, splitcount, splitcount, 4); //pictureBox1.Image = imgpuzzle; }
private void reload() { if (splitcount < 1) { splitcount = 1; } textBox1.Text = splitcount.ToString(); button1.Enabled = true; button3.Enabled = true; if (curimgidx == 0) { button1.Enabled = false; } if (curimgidx == maximgcount - 1) { button3.Enabled = false; } Image[] imgarr = CropJoin.splitimg(allpictures[curimgidx], splitcount, splitcount); imgoriginal = (Image[])imgarr.Clone(); Image imgpuzzle; if (radioButton1.Checked == true) { CropJoin.shuffle(imgarr); imgpuzzle = CropJoin.combineimg(imgarr, splitcount, splitcount); pictureBox1.Image = imgpuzzle; } else if (radioButton2.Checked == true) { imgpuzzle = CropJoin.removeimgpartially(imgarr, splitcount, splitcount, 5); pictureBox1.Image = imgpuzzle; } else if (radioButton3.Checked == true) { CropJoin.shuffle(imgarr); imgpuzzle = CropJoin.removeimgpartially(imgarr, splitcount, splitcount, 2); pictureBox1.Image = imgpuzzle; } else if (radioButton4.Checked == true) { CropJoin.showimgpartially(imgarr, splitcount, splitcount, 5, pictureBox1); } }
private void solvepuzzle() { splitcount = int.Parse(textBox1.Text); pictureBox1.Image = CropJoin.combineimg(imgoriginal, splitcount, splitcount); }