eramgarden Posted March 24, 2004 Posted March 24, 2004 I want to create a canvas/rectangualr background, 500x700 and then put my image on top of the canvas This is what I have but i only get a white rectangle with the font and NO IMAGE on top of it.. what am I missing? Dim strFileToConvert As String strFileToConvert = "C:\source1.Tif" 'Initialize the bitmap object by supplying the image file path Dim b As New Bitmap(strFileToConvert) Dim g As Graphics = Graphics.FromImage(b) [b] Dim rect = New Rectangle(0, 0, 500, 700)[/b] Dim bgBrush = New SolidBrush(System.Drawing.Color.White) [b] g.FillRectangle(bgBrush, rect)[/b] Dim bold As Font = New Font("Times New Roman", 14, FontStyle.Regular) [b] g.DrawString("Copyright © 1994-2004 ", bold, Brushes.Black, 10.0F, 350.0F) [/b] b.Save(strFileToConvert + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg) Quote
*Experts* mutant Posted March 24, 2004 *Experts* Posted March 24, 2004 That happen because you are drawing the white rectangle over your image. You are creating a bitmpa object from the image file and then drawing on it. Instead, create a new Bitmap object but not from a file but rather 700x500 size like you want, then create Graphics object from that. Now use the DrawImage method of the Graphics object to draw another Bitmap object you declared which contains your image. Dim back As New Bitmap(700,500) 'create bitmap with the size you want Dim gr As Graphics = Graphics.FromImage(back) 'get graphics for it Dim img As New Bitmap("file path") 'load your image gr.FillRectangle(New SolidBrush(Color.White), New Rectangle(0,0,700,500)) 'fill the background gr.DrawImage(img, xpos, ypos) 'draw the image at specified position 'draw whatever else you need .... back.Save("file path") 'save it img.Dispose() 'dont forget to dispose! back.Dispose() Quote
eramgarden Posted March 25, 2004 Author Posted March 25, 2004 You are wonderful! thanks..it works! 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.