decrypt Posted March 22, 2004 Posted March 22, 2004 How could you get an image from a file, and paste text on it, and then save it? (the program would do all of this automatically) Quote
*Experts* mutant Posted March 22, 2004 *Experts* Posted March 22, 2004 First create a Bitmap object from the file, create graphics from the image and use the DrawString method of the graphics to draw the text. Then simply use the Save method of the Bitmap object. 'First load the image Dim b As New Bitmap("path") 'get the graphics object from the image so you can draw onto the image Dim gr As Graphics = Graphics.FromImage(b) 'draw text gr.DrawString("text", Me.Font, New SolidBrush(Color.Red), 10, 10) 'save the image b.Save("path") 'dispose gr.Dispose() b.Dispose() Quote
decrypt Posted March 22, 2004 Author Posted March 22, 2004 How would you change the font though? I've tried alot, but i always get errors... Quote
*Experts* mutant Posted March 22, 2004 *Experts* Posted March 22, 2004 Simply create a new Font object and pass in the information you want into the constructor. Is that were you are encountering errors? Quote
decrypt Posted March 22, 2004 Author Posted March 22, 2004 I tried this: gr.DrawString("text", "Times New Roman", New SolidBrush(Color.Red), 10, 10) How would i make it so that that will work? Quote
*Experts* mutant Posted March 22, 2004 *Experts* Posted March 22, 2004 That is a string not a Font object. Use this: New Font(<set the arguments here>) Quote
decrypt Posted March 22, 2004 Author Posted March 22, 2004 (edited) edit: ah i c, i was supposed to put it in there, sry... gr.DrawString("text", New Font(arguments), New SolidBrush(Color.Red), 10, 10) Edited March 22, 2004 by decrypt Quote
*Experts* mutant Posted March 22, 2004 *Experts* Posted March 22, 2004 If you look closer at the arguments the constructor accepts you will see that it takes much more of them if you want to build a new font without a base one.... [edit]You edited your post so Im not sure where you are with this problem now :)[/edit] Quote
decrypt Posted March 22, 2004 Author Posted March 22, 2004 I get an error: gr.DrawString(TextBox1.Text, New Font("Times New Roman", FontStyle.Regular), New SolidBrush(Color.FromArgb(0, 40, 40)), 10, 10) Quote
*Experts* mutant Posted March 22, 2004 *Experts* Posted March 22, 2004 The error is there becuase if you read the required argument type for the combination you showed you will see that it accepts a Font object that will be used as a base for the one you are creating. It doesn't accept a string. The try this and see if its what you want: New Font("Times New Roman", 12) '12 is the font's size Quote
Leaders dynamic_sysop Posted March 22, 2004 Leaders Posted March 22, 2004 darn beaten to the post , was just gonna put this ... you must specify the Font size gr.DrawString(TextBox1.Text, New Font("Times New Roman", 12, FontStyle.Regular), New SolidBrush(Color.FromArgb(0, 40, 40)), 10, 10) Quote
decrypt Posted March 22, 2004 Author Posted March 22, 2004 Thanks that worked perfectly, my next question was going to be how do you set the font size, but you just answered it. Thanks alot... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.