Click to See Complete Forum and Search --> : GDI plus how to ?
four20pisces
September 24th, 2002, 12:14 PM
Ok I know how to use GDI + to put text into any control when the form loads by using this.
Private Sub test(ByVal sender As System.Object, ByVal pe As _ System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim g As Graphics = pe.Graphics
Dim mybrush As New Drawing2D.LinearGradientBrush(ClientRectangle, _
Color.Blue, Color.Black, Drawing2D.LinearGradientMode.Vertical)
Dim myFont As New Font("arial", 24)
g.DrawString("text here", myFont, mybrush, 300, 260)
End Sub
What I don't know how to do is get this to happen on command(i.e. when I press a button)
Any help on this matter would be greatly appritiated.
thank you :) :confused: :confused:
DSJ
September 24th, 2002, 04:11 PM
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim g As Graphics = Graphics.FromHwnd(PictureBox1.Handle)
Dim mybrush As New Drawing2D.LinearGradientBrush(ClientRectangle, _
Color.Blue, Color.Black, Drawing2D.LinearGradientMode.Vertical)
Dim myFont As New Font("arial", 24)
g.DrawString("text here", myFont, mybrush, 10, 10)
End Sub
four20pisces
September 25th, 2002, 02:02 PM
Ok That Worked but how do I save it ?
From my documentation It works like this...
PictureBox1.Image.Save("c:\path\testing.png", System.Drawing.Imaging.ImageFormat.Png)
But this returns a generic GDI + error.
I sent it to the clip board like this ...
Clipboard.SetDataObject(PictureBox1.Image)
it works but none of the text that I added is showing up.
Am I going about this wrong ...
:confused: Can I save this as an image? :confused:
DSJ
September 25th, 2002, 04:27 PM
I'm not suprised the changes didn't "stick" because if the picturebox is refreshed or the paint event gets called, it's going to clear and overwrite your changes with whatever is in the paint event. You might see if you can find something equivelent to the AutoRedraw property on VB 6 and see if that helps. Don't know about saving to a file, seems like I did that before with no problems (BMP format not PNG.)
DSJ
September 25th, 2002, 04:32 PM
Just did a little reading and the docs say there is no AutoRedraw equivelent. That to persist a graphic is has to be in the Paint Event. (Note though that you should be able to use RemoveHandler and AddHandler to have different paint event methods at different places in your program...)
four20pisces
September 25th, 2002, 05:43 PM
What I am doing here is trying to save text to an exsisting bitmap ( I don't care what format it uses )
I am Using GDI plus to render this text to the picturbox.
Now... on the screen it all apears the way I want it to.
When I use picturebox.image.save("c:\path\imagename.bmp")
It saves the Image but the text does not apear. I think this is because there is no text on the image but floating above it on the control.
The only way I can think to pull this off is to make a screen capture of the picturebox control.
I just don't know how to go about doing that.
Any ideas ?¿?
Thanks...
DSJ
September 26th, 2002, 08:54 AM
Take a look at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconintroductiontogdi.asp
DSJ
September 26th, 2002, 09:05 AM
You don't really need a picturebox at all... this works...
Dim img As Image = Image.FromFile("C:\RedneckDog.jpg")
Dim g As Graphics = Graphics.FromImage(img)
Dim mybrush As New Drawing2D.LinearGradientBrush(ClientRectangle, _
Color.Blue, Color.Black, Drawing2D.LinearGradientMode.Vertical)
Dim myFont As New Font("arial", 24)
g.DrawString("text here", myFont, mybrush, 10, 10)
img.Save("C:\test1.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.