Simple text image watermark effect-c#winform

Source: Internet
Author: User


Corresponding code download: http://download.csdn.net/source/1210790

 //original picture public void Originalimage () {String SourcePath = @ "... /.. /resources/test.jpg "; System.Drawing.Image Image = System.Drawing.Image.FromFile (SourcePath); Resultimage.image = Image; ///Add text watermark public void Makewordwatermark () {String SourcePath = @ "... /.. /resources/test.jpg "; System.Drawing.Image Image = System.Drawing.Image.FromFile (SourcePath); System.Drawing.Graphics Graphics = System.Drawing.Graphics.FromImage (image); Graphics. DrawImage (image, 0, 0, image. Width, image. Height); System.Drawing.Font Font = new System.Drawing.Font ("Verdana", 30); System.Drawing.Brush Brush = new System.Drawing.SolidBrush (System.Drawing.Color.White); String addtext = "Picture Add text watermark effect"; Graphics. DrawString (addtext, font, brush, 10, 10); Graphics. Dispose (); Resultimage.image = Image; //Picture Overall set transparency public void Makeimagewatermark () {String SourcePath = @ "... /.. /resources/test.jpg "; String Copypath = @ ". /.. /resources/image.jpg "; System.Drawing.Image Image = System.Drawing.Image.FromFile (SourcePath); SystEm. Drawing.image copyimage = System.Drawing.Image.FromFile (Copypath); Graphics g = graphics.fromimage (image); Transparency Setting Float alpha = 0.15f; The ImageAttributes object contains information about how bitmap and metafile colors are manipulated when rendering. ImageAttributes imageattributes = new ImageAttributes (); ColorMap: Defines the mapping of the conversion color colormap ColorMap = new ColorMap (); Here the watermark is defined as a picture with a green background color replaced with a transparent Colormap.oldcolor = Color.FromArgb (255, 0, 255, 0); Colormap.newcolor = Color.FromArgb (0, 0, 0, 0); Colormap[] remaptable = {ColorMap}; Imageattributes.setremaptable (remaptable, Coloradjusttype.bitmap); Float[][] colormatrixelements = {new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},//Red new float[] {0.0f, 1.0f, 0.0f, 0.0f , 0.0f},//green Green new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},//blue blue new float[] {0.0f, 0.0f, 0.0f, Alpha, 0.0f},//Transparency New float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}}; ColorMatrix: Defines a 5 x 5 matrix containing RGBA space coordinates. Several methods of the ImageAttributes class adjust the image color by using a color matrix. ColorMatrix Wmcolormatrix = new ColorMatrix (colormatrixelements); Imageattributes.setcolormatriX (Wmcolormatrix, Colormatrixflag.default, Coloradjusttype.bitmap); G.drawimage (Copyimage, new Rectangle) (image. Width-copyimage.width, image. Height-copyimage.height, Copyimage.width, Copyimage.height), 0, 0, copyimage.width, Copyimage.height, GraphicsUnit.Pixel, ImageAttributes); G.dispose (); Resultimage.image = Image; }

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.