04asp.net========== change the transparency of the watermark

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.