PDA

View Full Version : سوال: تبدیل متن درون تکست باکس به عکس



saeed0935
یک شنبه 11 دی 1390, 17:13 عصر
سلام.
من میخوام تو #C متنی که درون یه تکست باکس مینویسم رو درون یک pictureBox نشان بدم.لطفا کمک کنید.

اسماعیل ابراهیمی
یک شنبه 11 دی 1390, 17:30 عصر
از این کد استفاده کنید

public static Bitmap Convert_Text_to_Image(string txt, string fontname, int fontsize)
{
//creating bitmap image
Bitmap bmp = new Bitmap(1, 1);

//FromImage method creates a new Graphics from the specified Image.
Graphics graphics = Graphics.FromImage(bmp);
// Create the Font object for the image text drawing.
Font font = new Font(fontname, fontsize);
// Instantiating object of Bitmap image again with the correct size for the text and font.
SizeF stringSize = graphics.MeasureString(txt, font);
bmp = new Bitmap(bmp,(int)stringSize.Width,(int)stringSize.H eight);
graphics = Graphics.FromImage(bmp);


//Draw Specified text with specified format
graphics.DrawString(txt, font, Brushes.Red, 0, 0);
font.Dispose();
graphics.Flush();
graphics.Dispose();
return bmp; //return Bitmap Image
}

برای استفاده از متد بالا هم به روش زیر عمل کنبد :

picbox.Image = Convert_Text_to_Image(txtvalue.Text, "Bookman Old Style", 20);
picbox.SizeMode = PictureBoxSizeMode.StretchImage;

saeed0935
یک شنبه 11 دی 1390, 17:59 عصر
خیلی ممنون از جوابتون کارم راه افتاد.
فقط حالا چه جوری اینو تو دیتابیس ذخیره کنم؟

Hybrid
یک شنبه 11 دی 1390, 19:55 عصر
سلام دوست عزیز ف

اگه دیتابیستون اس کیو ال هست ، مطالب زیادی برای ذخیره عکس تو دیتا بیس اس کیو ال تو همین سایت هست میتونین جستجو کنین..

موفق باشید