PublicActionResult Pic () {varStram =NewSystem.Net.WebClient (). OpenRead ("http://www.mj100.com/img/index/z_ban02.jpg"); byte[] bytes= makesmallimg (Stram, -, -); returnFile (Bytes,"Image/jpeg","1.jpg"); } /// <summary> ///compress picture 15-5-4 by Qian/// </summary> /// <param name= "Fromfilestream" ></param> /// <param name= "Templatewidth" ></param> /// <param name= "Templateheight" ></param> /// <returns></returns> Public byte[] makesmallimg (System.IO.Stream fromfilestream, System.Double templatewidth, System.Double templateheight) { //get a Picture object from a file and use the embedded color management information in the streamSystem.Drawing.Image myimage = System.Drawing.Image.FromStream (Fromfilestream,true); //thumbnail width, heightSystem.Double newwidth = myimage.width, Newheight =Myimage.height; //wide cross-sectional view of the stencil if(Myimage.width > Myimage.height | | myimage.width = =myimage.height) {if(Myimage.width >templatewidth) { //wide-Press-fit, high-scaleNewwidth =Templatewidth; Newheight= Myimage.height * (Newwidth/myimage.width); } } //tall in the template of the vertical diagram Else { if(Myimage.height >templateheight) { //high-Press-fit, wide-scale scaleNewheight =Templateheight; Newwidth= Myimage.width * (Newheight/myimage.height); } } //Get picture sizeSystem.Drawing.Size mysize =NewSize (int) Newwidth, (int) newheight); //Create a new BMP imageSystem.Drawing.Image bitmap =NewSystem.Drawing.Bitmap (Mysize.width, mysize.height); //Create a new artboardSystem.Drawing.Graphics g =System.Drawing.Graphics.FromImage (bitmap); //setting high-quality interpolation methodsG.interpolationmode =System.Drawing.Drawing2D.InterpolationMode.High; //set high quality, low speed rendering smoothnessG.smoothingmode =System.Drawing.Drawing2D.SmoothingMode.HighQuality; //clear the canvas .g.clear (Color.White); //draw at the specified locationG.drawimage (MyImage,NewSystem.Drawing.Rectangle (0,0, Bitmap. Width, Bitmap. Height),NewSystem.Drawing.Rectangle (0,0, Myimage.width, myimage.height), System.Drawing.GraphicsUnit.Pixel); using(MemoryStream stream =NewMemoryStream ()) {Bitmap. Save (stream, imageformat.jpeg); G.dispose (); Myimage.dispose (); Bitmap. Dispose (); //Output byte stream returnStream. ToArray (); } }
Compress the remote picture and return