I'll show you how to convert any string to image and save it in your hard disk drive.
also you can use this sample code to prevent your website content from spiders.
there are many benfits.
1- Create Windows Forms Application.
2- Add Button Control on Form.
3- Add TextBox Control on Form and set Multiline to TRUE.
Sample Code:
public Color FontColor { get; set; }
public Color FontBackColor { get; set; }
public string FontName { get; set; }
public string ImagePath { get; set; }
public int FontSize { get; set; }
public int ImageHeight { get; set; }
public int ImageWidth { get; set; }
public Bitmap ImageText { get; set; }
public Graphics ImageGraphics { get; set; }
public Font ImageFont { get; set; }
public SolidBrush BrushForeColor { get; set; }
public SolidBrush BrushBackColor { get; set; }
public PointF ImagePointF { get; set; }
private void DrawText(string text)
{
FontColor = Color.Red;
FontBackColor = Color.Yellow;
FontName = "Arial";
FontSize = 10;
ImageHeight = textBox1.Height;
ImageWidth = textBox1.Width;
ImagePath = @"C:\WaleedImageTest.JPEG";
ImageText = new Bitmap(ImageWidth, ImageHeight);
ImageGraphics = Graphics.FromImage(ImageText);
ImageFont = new Font(FontName, FontSize);
ImagePointF = new PointF(5, 5);
BrushForeColor = new SolidBrush(FontColor);
BrushBackColor = new SolidBrush(FontBackColor);
ImageGraphics.FillRectangle(BrushBackColor, 0, 0, ImageWidth, ImageHeight);
ImageGraphics.DrawString(text, ImageFont, BrushForeColor, ImagePointF);
ImageText.Save(ImagePath, ImageFormat.Jpeg);
}
private void button1_Click(object sender, EventArgs e)
{
DrawText(textBox1.Text);
}
Then Run Your Application.
Showing posts with label Convert Image. Show all posts
Showing posts with label Convert Image. Show all posts
Wednesday, August 12, 2009
How To: Convert Text to Image Using C#
Tuesday, August 11, 2009
How To: Convert Image to String Using C#
the easy way to convert any image to string is :
1- Convert Image to Memory Stream.
2- Convert Memory Stream to Base64String.
so in this sample code I will convert the image to string and I'll save this string in text file.
private string ConvertImage(Bitmap sBit)
{
MemoryStream imageStream = new MemoryStream();
sBit.Save(imageStream, ImageFormat.Jpeg);
return Convert.ToBase64String(imageStream.ToArray());
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap sBit = new Bitmap(@"C:\bmw.jpg");
string imageString = ConvertImage(sBit);
StreamWriter sw = new StreamWriter(@"C:\waleedelkot.text", false);
sw.Write(imageString);
sw.Close();
}
1- Convert Image to Memory Stream.
2- Convert Memory Stream to Base64String.
so in this sample code I will convert the image to string and I'll save this string in text file.
private string ConvertImage(Bitmap sBit)
{
MemoryStream imageStream = new MemoryStream();
sBit.Save(imageStream, ImageFormat.Jpeg);
return Convert.ToBase64String(imageStream.ToArray());
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap sBit = new Bitmap(@"C:\bmw.jpg");
string imageString = ConvertImage(sBit);
StreamWriter sw = new StreamWriter(@"C:\waleedelkot.text", false);
sw.Write(imageString);
sw.Close();
}
Subscribe to:
Posts (Atom)