1. The project requires uploading white-bottomed images to be trimmed with white edges, so colleagues thanks a function that feels very useful.
2.
#regionCut white edges/// <summary> ///cut White edges/// </summary> /// <param name= "p" ></param> /// <returns></returns> Public Staticimage Crop (image p) {intx, y;//For use of x, y coordinates of pixelsBitmap B =NewBitmap (P);//image needed to cropColor C =NewColor ();//pixel color for use of identifying if background intintleft=0;//furthest left X coordinate intintright=0;//furthest right X coordinate intIntbottom =0;//furthest to the bottom Y coordinate intInttop =0; Y=0; while(Y <b.height) {x=0; while(x < B.width)//loop through pixels on X axis until end of image width{C= B.getpixel (x, y);//Get The color of the pixel if(C.R! =255&&c.r!=0&& C.G! =255&&c.g!=0&& C.B! =255&&c.b!=0) { if(C.R < -|| C.G < -|| C.b < -) { //determine if Pixel is further left than the value we already has if(Intleft = =0|| Intleft >x) {intleft=x; } //determine if pixel is further to the top than the value we already has if(Inttop = =0|| Inttop >y) {inttop=y; } //determine if pixel is further right than the value we already has if(Intright <= b.width && Intright <x) {intright=x; } //determine if pixel is further to the bottom than the value we already has if(Intbottom <= b.height && Intbottom <y) {intbottom=y; } }} X+=1; } y+=1; } intIntnewwidth = Intright;//establish width of new cropped image intIntnewheight = Intbottom;//establish height of new cropped imageBitmap imgcropped =NewBitmap (Intnewwidth-intleft +2, Intnewheight-inttop +2); Graphics Objgraphics=graphics.fromimage (imgcropped); //set the background color to white (you can chooseobjgraphics.clear (System.Drawing.Color.Transparent); intIntstarttop =1-Inttop;///+ 5 intIntstartleft =1-Intleft;///+ 5 //Draw The original image to your new cropped sized imageObjgraphics.drawimage (b, Intstartleft, intstarttop); B.dispose (); Objgraphics.dispose (); //return the cropped image to the caller returnimgcropped; }
. NET picture auto crop white edge function case