Hello.every one my last post is for how to add text on the image (water mark text). Now i am describing how to create image from the given text. in that you have to only give your text and image will be created and display on the page or you can save it.
Function --------
private void createImage() { string myString = "This is a string.My highlight word : search highlighted word."; // give your string
Bitmap b = new Bitmap(myString.Length * 10, 40); Graphics g = Graphics.FromImage((System.Drawing.Image)b);
CharacterRange[] CharRanges = new CharacterRange[] { new CharacterRange(0, myString.Length) }; StringFormat stringFormat = new StringFormat(); stringFormat.SetMeasurableCharacterRanges(CharRanges); Font MyFont = new Font(FontFamily.GenericSansSerif, 20.0F, GraphicsUnit.Pixel);
Rectangle MyRectangle = new Rectangle(10, 10, myString.Length * 10, 30); RectangleF MyRectangleF = (RectangleF)MyRectangle;
Region[] charRegion = g.MeasureCharacterRanges(myString, MyFont, MyRectangleF, stringFormat); g.DrawString(myString, MyFont, Brushes.Red, MyRectangleF);
//g.FillRegion(new SolidBrush(Color.FromArgb(50, Color.Black)), charRegion[0]);
//b.Save(Server.MapPath("MyImage.png"), System.Drawing.Imaging.ImageFormat.Png); MemoryStream m = new MemoryStream(); b.Save(m, System.Drawing.Imaging.ImageFormat.Png); m.WriteTo(Response.OutputStream); b.Dispose(); MyFont.Dispose(); g.Dispose(); }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|