Upload an image and draw a shadow watermark. (C #)

Source: Internet
Author: User
Tags transparent image

ASP. after uploading an image, add a watermark. for example, the URL. the text is white. however, when the background is white, the watermark cannot be seen at all. search for materials and find a method to draw text shadow. I found several, finally found a foreigner's article, and. net comes with the same statement in the documentation. instead, draw 2-5 gray texts with different alpha values as shadows .. then, draw the text of the normal color .... khan !!!!!!!!!!!!!!!!!! 111 there is no way, so I have to use it. the effect is normal. font font = new Font ("Arial Black", 15, FontStyle. bold); SizeF sf = g. measureString ("ImgGood. com ", font); PointF pf = new PointF (); pf. X = (250-sf.Width)/2; pf. Y = (bHeight-sf.Height)/2; // new watermark bmp Bitmap floatBmp = new Bitmap (int) sf. width + 3, (int) sf. height + 3, System. drawing. imaging. pixelFormat. format32bppArgb); // Bitmap floatBmp = new Bitmap (250,100); // Bitmap floatBmp = new Bitmap (int) sf. width, (int) sf. height); Graphics fg = Graphics. fromImage (floatBmp); // draw the Shadow character PointF pt = new PointF (0, 0); System. drawing. brush TransparentBrush0 = new System. drawing. solidBrush (System. drawing. color. fromArgb (50, System. drawing. color. black); System. drawing. brush TransparentBrush1 = new System. drawing. solidBrush (System. drawing. color. fromArgb (20, System. drawing. color. black); fg. drawString ("ImgGood. com ", font, TransparentBrush0, pt. x, pt. Y + 1); fg. drawString ("ImgGood. com ", font, TransparentBrush0, pt. X + 1, pt. y); fg. drawString ("ImgGood. com ", font, TransparentBrush1, pt. X + 1, pt. Y + 1); fg. drawString ("ImgGood. com ", font, TransparentBrush1, pt. x, pt. Y + 2); fg. drawString ("ImgGood. com ", font, TransparentBrush1, pt. X + 2, pt. y); TransparentBrush0.Dispose (); TransparentBrush1.Dispose (); // draw the LOGO character fg. smoothingMode = System. drawing. drawing2D. smoothingMode. highQuality; // fg. clear (Color. black); fg. drawString ("ImgGood. com ", font, new SolidBrush (Color. white), pt. x, pt. y, StringFormat. genericDefault); // watermark to the big image fg. save (); fg. dispose (); // set the color attribute float [] [] ptsArray = {new float [] {1, 0, 0, 0} of the transparent image }, new float [] {0, 1, 0, 0, 0}, new float [] {0, 0, 1, 0, 0}, new float [] {0, 0, 0, 0.5f, 0}, new float [] {0, 0, 0, 0, 1 }}; ColorMatrix clrMatrix = new ColorMatrix (ptsArray ); imageAttributes imgAttributes = new ImageAttributes (); imgAttributes. setColorMatrix (clrMatrix, ColorMatrixFlag. default, ColorAdjustType. bitmap); g. drawImage (floatBmp, new Rectangle (10, 10, (int) sf. width, (int) sf. height), 0, 0, (int) sf. width, (int) sf. height, GraphicsUnit. pixel, imgAttributes ); // ================================================ ======================================== g. save (); g. dispose (); bigBmp. save (filePath + "B/" + fileName); bigBmp. dispose (); the Code is not hard to solve.

Related Article

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.