Bitmap b = new Bitmap(700, 100);
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
string myString = "This is a string.My highlight word : search highlighted word.";
// Declare the word to highlight.
string searchWord = "search highlighted word";
// Create a CharacterRange array with the searchWord
// location and length.
CharacterRange[] CharRanges =
new CharacterRange[]{new CharacterRange
(myString.IndexOf(searchWord), searchWord.Length)};
// Construct a StringFormat object.
StringFormat stringFormat = new StringFormat();
// Set the ranges on the StringFormat object.
stringFormat.SetMeasurableCharacterRanges(CharRanges);
// Declare the font to write the message in.
Font MyFont = new Font(FontFamily.GenericSansSerif, 20.0F,
GraphicsUnit.Pixel);
// Construct a new Rectangle.
Rectangle MyRectangle = new Rectangle(10, 10, 700, 100);
// Convert the Rectangle to a RectangleF.
RectangleF MyRectangleF = (RectangleF)MyRectangle;
// Get the Region to highlight by calling the
// MeasureCharacterRanges method.
Region[] charRegion = g.MeasureCharacterRanges(myString,
MyFont, MyRectangleF, stringFormat);
// Draw the message string on the form.
g.DrawString(myString, MyFont, Brushes.Red,
MyRectangleF);
// Fill in the region using a semi-transparent color.
g.FillRegion(new SolidBrush(Color.FromArgb(50, Color.Black)),
charRegion[0]);
// save image to the root
b.Save(Server.MapPath("MyImage.png"), System.Drawing.Imaging.ImageFormat.Png);
// write image on the page
//MemoryStream m = new MemoryStream();
//b.Save(m, System.Drawing.Imaging.ImageFormat.Png);
//m.WriteTo(Response.OutputStream);
b.Dispose();
MyFont.Dispose();
g.Dispose();
Thursday, December 4, 2008
HIGHLIGHT STRING IN IMAGE [ DRAW STRING WITH HIGHLIGHT WORD ]
at
3:25 AM
·
Category: Graphics GDI+
Subscribe to:
Post Comments (Atom)
Archivo
-
▼
2008
(20)
-
▼
December
(14)
- Building Custom Control : Tell A Friend Custom Con...
- Watermark on image : Draw string on the image
- Remember me on this computer - Store username and ...
- Building URL with www.
- HIGHLIGHT STRING IN IMAGE [ DRAW STRING WITH HIGHL...
- LOOPING IN STORED PROCEDURE [CURSOR IN SQL SERVER]
- CHANGE IMAGE COLOR USING C# ( GRAPHICS GDI+ )
- DRAW STRING WITH MULTI LINES IN FIX RECTANGLE
- DRAW STRING WITH TWO LINES IN FIX RECTANGLE
- DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR...
- DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR...
- DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR...
- DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR
- DRAW STRING IN FIX RECTANGLE
-
▼
December
(14)
Categories
- Custom Control (1)
- Data Control (1)
- Graphics GDI+ (11)
- Other (6)
- SQL SERVER (1)
0 comments:
Post a Comment