For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Thursday, March 12, 2015

HOW TO MAKE TRANSPARENT PNG FILE IN C# VB.NET .NET

Problem:

I was working a project where watermark in pdf file as text. but after some time requirement has been changed. the requirement is put watermark as png file in pdf instead of text. The first task was generate transparent png file in C# with given text. the text should be show diagonal. listed below the few lines of code.
HOW TO MAKE TRANSPARENT PNG FILE IN C#





















Solution:

See the below code:

Example:

string text = " this is diognal text for watermark in transparent png file";
Bitmap bmp = new Bitmap(400, 800);
int x = 200, y = 400, angle=55;
Graphics g = Graphics.FromImage(bmp);
System.Drawing.Font f = new System.Drawing.Font("Arial", 25, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
g.Clear(Color.Transparent);
g.TranslateTransform(x, y);
g.RotateTransform(-angle);
g.TranslateTransform(-x, -y);
SizeF size = g.MeasureString(text, f);
g.DrawString(text, f, Brushes.Black, new PointF(x - size.Width / 2.0f, y - size.Height / 2.0f));
bmp.Save("test.png", System.Drawing.Imaging.ImageFormat.Png);
g.Dispose();
 
Share:

0 comments:

Post a Comment

Add Dependent Scripts

   here is the code that allow to add dependent script :         <script>         const addDependentScripts = async function( scriptsT...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive