Add Image function
Private Image Joinimage (list<image> imageList, Joinmode JM) {//Picture List if (imagelist.count <= 0) return null; if (JM = = joinmode.horizontal) {//cross stitch int width = 0; Calculates the total length of the foreach (Image i in imageList) {width + = i.width; }//height constant int height = Imagelist.max (x = x.height); Construct the final picture whiteboard Bitmap tablechartimage = new Bitmap (width, height); Graphics graph = graphics.fromimage (tablechartimage); Initialize this large graph of graph. DrawImage (tablechartimage, width, height); Initializes the current wide int currentwidth = 0; foreach (Image i in imageList) {//Puzzle graph. DrawImage (i, currentwidth, 0); After stitching the image, the current width Currentwidth + = I.width; } return tablechartimage; } else if (JM = = joinmode.vertical) {//Vertical stitching int height = 0; Calculates the total length of the foreach (Image i in imageList) {height + = i.height; }//Width invariant int width = Imagelist.max (x = x.width); Construct the final picture whiteboard Bitmap tablechartimage = new Bitmap (width, height); Graphics graph = graphics.fromimage (tablechartimage); Initialize this large graph of graph. DrawImage (tablechartimage, width, height); Initializes the current wide int currentheight = 0; foreach (Image i in imageList) {//Puzzle graph. DrawImage (i, 0, currentheight); After stitching the image, the current width currentheight + = i.height; } return tablechartimage; } else {return null; } }
Stitching test (under button event)
Bitmap Image1 = new Bitmap (application.startuppath + "\ \ Untitled -2_01.bmp"); Bitmap Image2 = new Bitmap (application.startuppath + "\ \ Untitled -2_02.bmp"); Picturebox2.image = Image1; Picturebox3.image = Image2; System.Windows.Forms.PictureBox AA = new PictureBox (); Aa. Image = Image1; Image Img1=aa. Image; Aa. Image = Image2; Image img2 = aa. Image; int unitewidth = IMG1. width;//picture uniform height int uniteheight = img1. height;//Picture Uniform width Bitmap tableChartImageCol1 = new Bitmap (Unitewidth * 2, uniteheight);//First line picture list< ;image> imageList = new list<image> (); list<image> imglistcopy = new list<image> (); Imagelist.add (IMG1); Imagelist.add (IMG2); foreach (Image i in imageList)//Stupid method, re-new picture, change picture height width {Bitmap b = new Bitmap (i, Unitewidth, unit Eheight); Imglistcopy.add (b); } for (int i = 0; i < 2; i++) {if (imagelist.count-1 >= i) { Imagelist[i] = imglistcopy[i];//changed picture, assigned to original picture} if (true)//go into puzzle/ /Horizontal Stitching {//Picture whiteboard 1 Graphics graph = graphics.fromimage (tableChartImageCol1); Initialize this large graph of graph. DrawImage (TableChartImageCol1, Unitewidth * 2, uniteheight); Initializes the current wide int currentwidth = 0; Graph. Clear (System.Drawing.Color.White); Clears the canvas with the background set to white foreach (Image i in imageList) {graph. DrawImage (i, currentwidth, 0);//puzzle--the picture is spelled up currentwidth + = I.width; After stitching the image, the current width} picturebox1.image = tableChartImageCol1;
One, to be stitching pictures
Stitching Complete effect
Image Stitching Test