public void ProcessRequest (HttpContext context) {context. Response.ContentType = "Text/plain"; 1: Receive the data sent over the file. Httppostedfile file =context. request.files["Filedata"]; String fileName = Path.getfilename (file. filename);//file name string fileext = path.getextension (filename). ToLower ();//extension. String waterfile = context. Server.MapPath ("/images/error.jpg");//The image used to make the watermark if (Fileext = = ". jpg") {//Create a different folder to save on The file passed. String dir = "/imageupload/" +datetime.now.year+ "/" +datetime.now.month+ "/" +datetime.now.day+ "/"; Directory.CreateDirectory (Path.getdirectoryname) (context. Server.MapPath (dir)); You want to rename the uploaded file. (file. InputStream: Gets the file stream of the uploaded file) string fulldir = Dir +common.webcommon.getstreammd5 (file. InputStream) + Fileext; using (Image img = image.fromstream (file). InputStream)//Specify the uploaded picture {using (BitMap map = new Bitmap (img. Width, IMG. Height)//Create a canvas {using (Graphics g = graphics.fromimage (map))//Create a brush for the canvas. {using (Image Waterimage = Image.FromFile (waterfile)) {G.drawimage (IMG, new Point (0,0));//The uploaded picture is drawn on the canvas. Draw a watermark picture on a large map, the second parameter; Where to start the painting, how big. Back: Which part to draw. G.drawimage (Waterimage, New Rectangle (IMG). Width-waterimage.width, IMG. Height-waterimage.height, Waterimage.width, Waterimage.height), 0, 0, waterimage.width, Waterimage.height, GraphicsUnit.Pixel, Setimageattr (50));//Use the color or transparency information of the adjusted picture to begin drawing the picture. Map. Save (context. Server.MapPath (Fulldir));//Save picture context. Response.Write ("OK:" + fulldir); } } } } File. SaveAs (context. Server.MapPath (Fulldir)); Context. Response.Write ("OK:" +fulldir); can be thumbnails. File. SaveAs (context. Server.MapPath ("/imageupload/" +filename)); Context. Response.Write ("ok:/imageupload/" + fileName); }} public ImageAttributes setimageattr (float ff) {//Definition matrix: Rgbaw float[][] f = {New float[]{ff/100f,0,0,0,0}, new float[]{0,1,0,0,0}, New float[]{0,0,1,0,0}, New float[]{0,0,0,1,0}, new float[]{0,0,0,0,1}}; ColorMatrix ColorMatrix = new ColorMatrix (f);//Use a matrix of your own definition. ImageAttributes imageattr = new ImageAttributes ()///Specifies the color information of the image Imageattr.setcolormatrix (ColorMatrix, Colormatr Ixflag.default, Coloradjusttype.bitmap);//Use our own defined matrix to jump the color information of the picture. Return imageatTr }
04asp.net========== change the transparency of the watermark