Httppostedfile file = context. request.files[0]; using(Stream stream =file. InputStream) {Image img=NewBitmap (stream); //3. Equal to zoom the image according to the proportion of zoom intTHUMBW = $, Thumbh = -; intW =0, h =0; if(IMG. Height *1.0/Thumbh >= img. Width *1.0/THUMBW) {h=Thumbh; W= (int) (THUMBH *1.0/img. Height *img. Width); } Else{W=THUMBW; H= (int) (THUMBW *1.0/img. Width *img. Height); } using(Bitmap newimg =NewBitmap (W, h)) { using(Graphics graphics =graphics.fromimage (newimg)) {Graphics. DrawImage (IMG,NewRectangle (0,0, W, h),NewRectangle (0,0, IMG. Width, IMG. Height), GraphicsUnit.Pixel); //1. Crop the image directly//Graphics. DrawImage (IMG, 0, 0, IMG. Width, IMG. Height); //2. Specify small 100*100 for scaling//Graphics. DrawImage (IMG, new Rectangle (0, 0, +,), new Rectangle (0, 0, IMG). Width, IMG. Height), graphicsunit.pixel);Newimg.save (context. Server.MapPath ("/b.png")); Context. Response.Write ("Width:"+ img. Width +"Height:"+img. Height); } } }
Equal zoom of picture