资源描述:
《c sharp 制作图案水印》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C#制作图案水印 usingSystem; usingSystem.Collections.Generic; usingSystem.Text; usingSystem.IO; usingSystem.Drawing; usingSystem.Drawing.Imaging; usingSystem.Drawing.Drawing2D; namespacecj.Tools { /**/ /// ///图像操作类(主要用于给图片加上透明文字水印) /// publiccla
2、ssImageWater_Word { #region添加水印 /// ///添加水印 /// /// /// /// /// /// ///
3、 /// publicbyte[]DrawImage(byte[]picBt,stringwaterWords,floatalpha,PointFposf,boolfRewrite,Colorcolor) { ImageimgPho=null; BitmapbmPho=null; GraphicsgrPho=null; MemoryStreammeoStr=newMemoryStream(picBt,0,picBt.Length); imgPho=Image.FromStream(me
4、oStr); intphWidth=imgPho.Width; intphHeight=imgPho.Height; bmPho=newBitmap(phWidth,phHeight,PixelFormat.Format24bppRgb); bmPho.SetResolution(imgPho.HorizontalResolution,imgPho.VerticalResolution); grPho=Graphics.FromImage(bmPho); grPho.SmoothingMode=SmoothingMode.A
5、ntiAlias; grPho.DrawImage(imgPho,newRectangle(0,0,phWidth,phHeight),0,0,phWidth,phHeight,GraphicsUnit.Pixel); FontcrFont=null; SizeFcrSize=newSizeF(); crFont=newFont("arial",9,FontStyle.Bold); crSize=grPho.MeasureString(waterWords,crFont); intyPixlesFromBottom=(int
6、)(phHeight*.05); //定义在图片上文字的位置 floatwmHeight=crSize.Height; floatwmWidth=crSize.Width; floatxPosOfWm=posf.X*3; floatyPosOfWm=posf.Y*2; StringFormatStrFormat=newStringFormat(); //定义需要印的文字居中对齐 StrFormat.Alignment=StringAlignment.Center; intm_alpha=
7、Convert.ToInt32(256*alpha); SolidBrushsemiTransBrush2=newSolidBrush(Color.FromArgb(m_alpha,0,0,0)); grPho.DrawString(waterWords, //stringoftext crFont, //font semiTransBrush2, //Brush newPointF(xPosOfWm+1,yPosOfWm+1), //Position StrFo
8、rmat); SolidBrushsemiTransBrush=newSolidBrush(color); grPho.DrawString(waterWords, //s